Bibouche

Untitled

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