Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TileEntityFishnet extends TileEntity implements ITickable, ICapabilityProvider {
- private ItemStackHandler handler;
- private int cooldown;
- public TileEntityFishnet() {
- this.cooldown = 0;
- this.handler = new ItemStackHandler(15);
- }
- @Override
- public void readFromNBT(NBTTagCompound nbt) {
- this.cooldown = nbt.getInteger("Cooldown");
- this.handler.deserializeNBT(nbt.getCompoundTag("ItemStackHandler"));
- super.readFromNBT(nbt);
- }
- @Override
- public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
- nbt.setInteger("Cooldown", this.cooldown);
- nbt.setTag("ItemStackHandler", this.handler.serializeNBT());
- return super.writeToNBT(nbt);
- }
- @Override
- public void update() {
- if(this.getWorld().getBlockState(this.pos.up()).getBlock() == Blocks.WATER) {
- if(this.getWorld().getBlockState(this.pos.north()).getBlock() == Blocks.WATER) {
- if(this.getWorld().getBlockState(this.pos.south()).getBlock() == Blocks.WATER) {
- if(this.getWorld().getBlockState(this.pos.east()).getBlock() == Blocks.WATER) {
- if(this.getWorld().getBlockState(this.pos.west()).getBlock() == Blocks.WATER) {
- this.cooldown++;
- if(this.cooldown == 1000) {
- LootTable table = this.getWorld().getLootTableManager().getLootTableFromLocation(new ResourceLocation("minecraft:gameplay/fishing/fish"));
- LootContext ctx = new LootContext.Builder(this.getWorld());
- List<ItemStack> stacks = table.generateLootForPools(this.getWorld().rand, ctx);
- table.fillInventory(IInventory, this.getWorld().rand, ctx);
- this.cooldown = 0;
- }
- }
- }
- }
- }
- }
- Utils.getLogger().info("Fishnet Cooldown: " + this.cooldown);
- }
- @Override
- public SPacketUpdateTileEntity getUpdatePacket() {
- NBTTagCompound nbt = new NBTTagCompound();
- this.writeToNBT(nbt);
- int metadata = getBlockMetadata();
- return new SPacketUpdateTileEntity(this.pos, metadata, nbt);
- }
- @Override
- public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
- this.readFromNBT(pkt.getNbtCompound());
- }
- @Override
- public NBTTagCompound getUpdateTag() {
- NBTTagCompound nbt = new NBTTagCompound();
- this.writeToNBT(nbt);
- return nbt;
- }
- @Override
- public void handleUpdateTag(NBTTagCompound tag) {
- this.readFromNBT(tag);
- }
- @Override
- public NBTTagCompound getTileData() {
- NBTTagCompound nbt = new NBTTagCompound();
- this.writeToNBT(nbt);
- return nbt;
- }
- @Override
- public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
- if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
- return (T) this.handler;
- return super.getCapability(capability, facing);
- }
- @Override
- public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
- if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
- return true;
- return super.hasCapability(capability, facing);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement