Fix tables not placing items contained in the item
@@ -3,8 +3,10 @@ package slimeknights.tconstruct.tables.block;
import lombok.Getter;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
+import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
@@ -15,6 +17,7 @@ import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
+import net.minecraftforge.common.util.Constants.NBT;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemHandlerHelper;
import slimeknights.mantle.tileentity.InventoryTileEntity;
@@ -22,6 +25,7 @@ import slimeknights.tconstruct.common.config.Config;
import slimeknights.tconstruct.tables.tileentity.chest.TinkerChestTileEntity;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.function.Supplier;
public class TinkerChestBlock extends TinkerTableBlock {
@@ -49,6 +53,21 @@ public class TinkerChestBlock extends TinkerTableBlock {
return te.get();
}
+ @Override
+ public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
+ super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
+ // check if we also have an inventory
+
+ CompoundNBT tag = stack.getTag();
+ if (tag != null && tag.contains("TinkerData", NBT.TAG_COMPOUND)) {
+ CompoundNBT tinkerData = tag.getCompound("TinkerData");
+ TileEntity te = worldIn.getTileEntity(pos);
+ if (te instanceof TinkerChestTileEntity) {
+ ((TinkerChestTileEntity)te).readInventoryFromNBT(tinkerData);
+ }
+ }
+ }
+
@SuppressWarnings("deprecation")
@Override
@Deprecated
