Created
April 21, 2025 15:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package quest.laxla.cevsc | |
import fr.iglee42.createcasing.blockEntities.WoodenShaftBlockEntity | |
import net.minecraft.core.BlockPos | |
import net.minecraft.core.HolderLookup | |
import net.minecraft.core.component.DataComponentMap | |
import net.minecraft.nbt.CompoundTag | |
import net.minecraft.nbt.NbtOps | |
import net.minecraft.world.level.block.entity.BlockEntityType | |
import net.minecraft.world.level.block.state.BlockState | |
class WoodenShaftCogwheelBlockEntity( | |
type: BlockEntityType<*>, | |
pos: BlockPos, | |
state: BlockState, | |
) : WoodenShaftBlockEntity(type, pos, state) { | |
companion object { | |
private val TagKey by lazy { Cevsc.CogwheelTypeDataComponentType.registeredName } | |
} | |
var cogwheelType: CogwheelType = CogwheelType.Oak | |
override fun applyImplicitComponents(componentInput: DataComponentInput) { | |
super.applyImplicitComponents(componentInput) | |
cogwheelType = componentInput.get(Cevsc.CogwheelTypeDataComponentType) ?: cogwheelType | |
} | |
override fun collectImplicitComponents(components: DataComponentMap.Builder) { | |
super.collectImplicitComponents(components) | |
components[Cevsc.CogwheelTypeDataComponentType] = cogwheelType | |
} | |
@Deprecated("Mojang-deprecated") | |
override fun removeComponentsFromTag(tag: CompoundTag) { | |
tag.remove(TagKey) | |
} | |
override fun write(compound: CompoundTag, registries: HolderLookup.Provider, clientPacket: Boolean) { | |
super.write(compound, registries, clientPacket) | |
CogwheelType.Codec.encodeStart(NbtOps.INSTANCE, cogwheelType).ifSuccess { compound.put(TagKey, it) } | |
} | |
override fun read(compound: CompoundTag, registries: HolderLookup.Provider, clientPacket: Boolean) { | |
super.read(compound, registries, clientPacket) | |
CogwheelType.Codec.parse(NbtOps.INSTANCE, compound.get(TagKey)).ifSuccess { cogwheelType = it } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment