Skip to content

Instantly share code, notes, and snippets.

@Laxystem
Created April 21, 2025 15:19
Show Gist options
  • Save Laxystem/a0b855d4c0c8c9c59b0d74677f505e61 to your computer and use it in GitHub Desktop.
Save Laxystem/a0b855d4c0c8c9c59b0d74677f505e61 to your computer and use it in GitHub Desktop.
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