Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. public class TileEntityFishnet extends TileEntity implements ITickable, ICapabilityProvider {
  2.  
  3. private ItemStackHandler handler;
  4. private int cooldown;
  5.  
  6. public TileEntityFishnet() {
  7. this.cooldown = 0;
  8. this.handler = new ItemStackHandler(15);
  9. }
  10.  
  11. @Override
  12. public void readFromNBT(NBTTagCompound nbt) {
  13. this.cooldown = nbt.getInteger("Cooldown");
  14. this.handler.deserializeNBT(nbt.getCompoundTag("ItemStackHandler"));
  15. super.readFromNBT(nbt);
  16. }
  17.  
  18. @Override
  19. public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
  20. nbt.setInteger("Cooldown", this.cooldown);
  21. nbt.setTag("ItemStackHandler", this.handler.serializeNBT());
  22. return super.writeToNBT(nbt);
  23. }
  24.  
  25. @Override
  26. public void update() {
  27. if(this.getWorld().getBlockState(this.pos.up()).getBlock() == Blocks.WATER) {
  28. if(this.getWorld().getBlockState(this.pos.north()).getBlock() == Blocks.WATER) {
  29. if(this.getWorld().getBlockState(this.pos.south()).getBlock() == Blocks.WATER) {
  30. if(this.getWorld().getBlockState(this.pos.east()).getBlock() == Blocks.WATER) {
  31. if(this.getWorld().getBlockState(this.pos.west()).getBlock() == Blocks.WATER) {
  32. this.cooldown++;
  33. if(this.cooldown == 1000) {
  34. LootTable table = this.getWorld().getLootTableManager().getLootTableFromLocation(new ResourceLocation("minecraft:gameplay/fishing/fish"));
  35. LootContext ctx = new LootContext.Builder(this.getWorld());
  36. List<ItemStack> stacks = table.generateLootForPools(this.getWorld().rand, ctx);
  37. table.fillInventory(IInventory, this.getWorld().rand, ctx);
  38.  
  39. this.cooldown = 0;
  40. }
  41. }
  42. }
  43. }
  44. }
  45. }
  46. Utils.getLogger().info("Fishnet Cooldown: " + this.cooldown);
  47. }
  48.  
  49. @Override
  50. public SPacketUpdateTileEntity getUpdatePacket() {
  51. NBTTagCompound nbt = new NBTTagCompound();
  52. this.writeToNBT(nbt);
  53. int metadata = getBlockMetadata();
  54. return new SPacketUpdateTileEntity(this.pos, metadata, nbt);
  55. }
  56.  
  57. @Override
  58. public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
  59. this.readFromNBT(pkt.getNbtCompound());
  60. }
  61.  
  62. @Override
  63. public NBTTagCompound getUpdateTag() {
  64. NBTTagCompound nbt = new NBTTagCompound();
  65. this.writeToNBT(nbt);
  66. return nbt;
  67. }
  68.  
  69. @Override
  70. public void handleUpdateTag(NBTTagCompound tag) {
  71. this.readFromNBT(tag);
  72. }
  73.  
  74. @Override
  75. public NBTTagCompound getTileData() {
  76. NBTTagCompound nbt = new NBTTagCompound();
  77. this.writeToNBT(nbt);
  78. return nbt;
  79. }
  80.  
  81. @Override
  82. public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
  83. if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
  84. return (T) this.handler;
  85. return super.getCapability(capability, facing);
  86. }
  87.  
  88. @Override
  89. public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
  90. if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
  91. return true;
  92. return super.hasCapability(capability, facing);
  93. }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement