Skip to content

Commit

Permalink
im confused ngl
Browse files Browse the repository at this point in the history
  • Loading branch information
Leclowndu93150 committed Dec 27, 2024
1 parent 02a8c26 commit 033c7ba
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/portingdeadmods/plonk/data/DataComponents.java
Original file line number Diff line number Diff line change
@@ -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<DataComponentType<Boolean>> HELD = COMPONENTS.registerComponentType("Held",
builder -> builder.persistent(Codec.BOOL).networkSynchronized(ByteBufCodecs.BOOL));

public static final Supplier<DataComponentType<Integer>> RENDER_TYPE = COMPONENTS.registerComponentType("RenderType",
builder -> builder.persistent(Codec.INT).networkSynchronized(ByteBufCodecs.INT));

public static final Supplier<DataComponentType<Integer>> TAG_VERSION = COMPONENTS.registerComponentType("TagVersion",
builder -> builder.persistent(Codec.INT).networkSynchronized(ByteBufCodecs.INT));

public static final Supplier<DataComponentType<Integer>> TILE_ROTATION = COMPONENTS.registerComponentType("TileRotation",
builder -> builder.persistent(Codec.INT).networkSynchronized(ByteBufCodecs.INT));

public static final Supplier<DataComponentType<Integer>> TAG_ITEM_ROTATION = COMPONENTS.registerComponentType("TagItemRotation",
builder -> builder.persistent(Codec.INT).networkSynchronized(ByteBufCodecs.INT));



}

0 comments on commit 033c7ba

Please sign in to comment.