I don't have a seperate container class, maybe thats the Problem?
public class PedestalBlockEntity extends BlockEntity {
private final ItemStackHandler inventory = new ItemStackHandler(1);
private final LazyOptional<IItemHandler> optional = LazyOptional.of(() -> this.inventory);
public PedestalBlockEntity(BlockPos pos, BlockState state) {
super(BlockEntityRegister.PEDESTAL.get(), pos, state);
}
@Override
public void load(CompoundTag nbt) {
super.load(nbt);
this.inventory.deserializeNBT(nbt.getCompound("Inventory"));
System.out.println("load: " + nbt.getCompound("Inventory"));
}
@Override
public void saveAdditional(@NotNull CompoundTag nbt) {
super.saveAdditional(nbt);
nbt.put("Inventory", this.inventory.serializeNBT());
System.out.println("saveAdditional: " + this.inventory.serializeNBT());
}
@Override
public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap) {
return cap == ForgeCapabilities.ITEM_HANDLER ? this.optional.cast() : super.getCapability(cap, null);
}
@Override
public void invalidateCaps() {
this.optional.invalidate();
}
public ItemStackHandler getInventory() {
return inventory;
}
public ItemStack addItem(ItemStack itemStack, Boolean simulate){
IItemHandler h = optional.orElse(null);
ItemStack returner = h.insertItem(0,itemStack.copy(), simulate);
if(!simulate) update();
return returner;
}
public ItemStack getDisplayItem(Boolean simulate) {
IItemHandler h = optional.orElse(null);
ItemStack returner = h.extractItem(0,1,simulate);
if(!simulate) update();
//System.out.println(""+returner);
return returner;
}
public void update() {
BlockState state = level.getBlockState(this.worldPosition);
this.level.sendBlockUpdated(this.worldPosition, state, state, 3);
this.setChanged();
}
}
Do You want the render class too?