diff --git a/src/main/java/com/portingdeadmods/plonk/common/block/BlockPlacedItems.java b/src/main/java/com/portingdeadmods/plonk/common/block/BlockPlacedItems.java index 85ba9c0..06f409a 100644 --- a/src/main/java/com/portingdeadmods/plonk/common/block/BlockPlacedItems.java +++ b/src/main/java/com/portingdeadmods/plonk/common/block/BlockPlacedItems.java @@ -273,8 +273,8 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { } @Override - public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter world, BlockPos pos, Player player) { - return WorldUtils.withTile(world, pos, TilePlacedItems.class, tile -> { + public ItemStack getCloneItemStack(BlockState state, HitResult target, LevelReader level, BlockPos pos, Player player) { + return WorldUtils.withTile(level, pos, TilePlacedItems.class, tile -> { int slot = getPickedSlot(tile, pos, player); return slot >= 0 ? tile.getItem(slot) : ItemStack.EMPTY; }, () -> ItemStack.EMPTY); diff --git a/src/main/java/com/portingdeadmods/plonk/common/item/ItemBlockPlacedItems.java b/src/main/java/com/portingdeadmods/plonk/common/item/ItemBlockPlacedItems.java index e9b2729..9cb1a80 100644 --- a/src/main/java/com/portingdeadmods/plonk/common/item/ItemBlockPlacedItems.java +++ b/src/main/java/com/portingdeadmods/plonk/common/item/ItemBlockPlacedItems.java @@ -3,9 +3,9 @@ import com.portingdeadmods.plonk.common.config.PlonkConfig; import com.portingdeadmods.plonk.common.registry.RegistryBlocks; import com.portingdeadmods.plonk.common.tile.TilePlacedItems; +import com.portingdeadmods.plonk.data.DataComponents; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; @@ -19,37 +19,29 @@ import net.minecraft.world.level.block.state.BlockState; public class ItemBlockPlacedItems extends BlockItem { - private static final String TAG_HELD = "Held"; - private static final String TAG_RENDER_TYPE = TilePlacedItems.TAG_RENDER_TYPE; public ItemBlockPlacedItems(Item.Properties builder) { super(RegistryBlocks.placed_items, builder); } public void setHeldStack(ItemStack stack, ItemStack held, int renderType) { - CompoundTag tagCompound = stack.getOrCreateTag(); - - CompoundTag tagCompoundHeld = tagCompound.getCompound(TAG_HELD); - held.save(tagCompoundHeld); - tagCompound.put(TAG_HELD, tagCompoundHeld); - - tagCompound.putInt(TAG_RENDER_TYPE, renderType); - - stack.setTag(tagCompound); + stack.set(DataComponents.HELD, true); + stack.set(DataComponents.RENDER_TYPE, renderType); } public ItemStack getHeldStack(ItemStack stack) { - CompoundTag tagCompound = stack.getTag(); - if (tagCompound == null || !tagCompound.contains(TAG_HELD)) + if (!stack.has(DataComponents.HELD)) return ItemStack.EMPTY; - return ItemStack.of(tagCompound.getCompound(TAG_HELD)); + + ItemStack held = new ItemStack(stack.getItem()); + held.set(DataComponents.HELD,stack.get(DataComponents.HELD)); + return held; } public int getHeldRenderType(ItemStack stack) { - CompoundTag tagCompound = stack.getTag(); - if (tagCompound == null || !tagCompound.contains(TAG_RENDER_TYPE)) + if (!stack.has(DataComponents.RENDER_TYPE)) return 0; - return tagCompound.getInt(TAG_RENDER_TYPE); + return stack.get(DataComponents.RENDER_TYPE); } /** diff --git a/src/main/java/com/portingdeadmods/plonk/common/tile/TilePlacedItems.java b/src/main/java/com/portingdeadmods/plonk/common/tile/TilePlacedItems.java index 4befad4..88a197c 100644 --- a/src/main/java/com/portingdeadmods/plonk/common/tile/TilePlacedItems.java +++ b/src/main/java/com/portingdeadmods/plonk/common/tile/TilePlacedItems.java @@ -73,10 +73,7 @@ public class TilePlacedItems extends BlockEntity implements WorldlyContainer { HEIGHT_ITEM, 0.75 ); - public static final String TAG_VERSION = "Version"; - public static final String TAG_TILE_ROTATION = "TileRotation"; public static final int TILE_ROTATION_COUNT = 4; - public static final String TAG_ITEM_ROTATION = "ItemRotation"; public static final String TAG_ITEMS = "Items"; public static final String TAG_SLOT = "Slot"; public static final String TAG_RENDER_TYPE = "RenderType"; diff --git a/src/main/java/com/portingdeadmods/plonk/data/DataComponents.java b/src/main/java/com/portingdeadmods/plonk/data/DataComponents.java new file mode 100644 index 0000000..6b93dec --- /dev/null +++ b/src/main/java/com/portingdeadmods/plonk/data/DataComponents.java @@ -0,0 +1,32 @@ +package com.portingdeadmods.plonk.data; + +import com.mojang.serialization.Codec; +import com.portingdeadmods.plonk.Plonk; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.network.codec.ByteBufCodecs; +import net.neoforged.neoforge.registries.DeferredRegister; + +import java.util.function.Supplier; + +public class DataComponents { + + public static final DeferredRegister.DataComponents COMPONENTS = DeferredRegister.createDataComponents(Plonk.MOD_ID); + + public static final Supplier> HELD = COMPONENTS.registerComponentType("Held", + builder -> builder.persistent(Codec.BOOL).networkSynchronized(ByteBufCodecs.BOOL)); + + public static final Supplier> RENDER_TYPE = COMPONENTS.registerComponentType("RenderType", + builder -> builder.persistent(Codec.INT).networkSynchronized(ByteBufCodecs.INT)); + + public static final Supplier> TAG_VERSION = COMPONENTS.registerComponentType("TagVersion", + builder -> builder.persistent(Codec.INT).networkSynchronized(ByteBufCodecs.INT)); + + public static final Supplier> TILE_ROTATION = COMPONENTS.registerComponentType("TileRotation", + builder -> builder.persistent(Codec.INT).networkSynchronized(ByteBufCodecs.INT)); + + public static final Supplier> TAG_ITEM_ROTATION = COMPONENTS.registerComponentType("TagItemRotation", + builder -> builder.persistent(Codec.INT).networkSynchronized(ByteBufCodecs.INT)); + + + +}