Bibouche

Untitled

Jul 21st, 2021
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. public class CelestialPowerPedestalTileEntity extends TileEntity {
  2.  
  3.     public static final  int                        slots                  = 1;
  4.     public               ItemStackHandler           inv                    = new ItemStackHandler();
  5.     private final        LazyOptional<IItemHandler> capabilityLazyOptional = LazyOptional.of(() -> inv);
  6.  
  7.     public CelestialPowerPedestalTileEntity() {
  8.         super(ModTileEntities.CELESTIAL_POWER_PEDESTAL_TILE_ENTITY.get());
  9.     }
  10.  
  11.     public boolean isFillable() {
  12.         return inv.getStackInSlot(0).getItem() != ModItems.CELESTIAL_POWER_EYE.get();
  13.     }
  14.  
  15.     @Override
  16.     public void read(BlockState state, CompoundNBT nbt) {
  17.         super.read(state, nbt);
  18.         inv.deserializeNBT(nbt.getCompound("Inv"));
  19.     }
  20.  
  21.     @Nonnull
  22.     @Override
  23.     public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
  24.         if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
  25.             return capabilityLazyOptional.cast();
  26.         }
  27.         return super.getCapability(cap, side);
  28.     }
  29.  
  30.     @Override
  31.     protected void invalidateCaps() {
  32.         super.invalidateCaps();
  33.         capabilityLazyOptional.invalidate();
  34.     }
  35.  
  36.     @Nullable
  37.     @Override
  38.     public SUpdateTileEntityPacket getUpdatePacket() {
  39.         return new SUpdateTileEntityPacket(this.pos, -1, getUpdateTag());
  40.     }
  41.  
  42.     @Override
  43.     public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) {
  44.         handleUpdateTag(this.getBlockState(), pkt.getNbtCompound());
  45.     }
  46.  
  47.     @Override
  48.     public CompoundNBT getUpdateTag() {
  49.         CompoundNBT nbt = super.getUpdateTag();
  50.         nbt.put("Inv", inv.serializeNBT());
  51.         return nbt;
  52.     }
  53.  
  54.     @Override
  55.     public void handleUpdateTag(BlockState state, CompoundNBT tag) {
  56.         this.read(state, tag);
  57.     }
  58. }
  59.  
Add Comment
Please, Sign In to add comment