2015-08-29 14:33:25 +02:00
|
|
|
/*
|
|
|
|
* This file ("TileEntityFishingNet.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-01-03 16:05:51 +01:00
|
|
|
* http://ellpeck.de/actaddlicense/
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-01-03 16:05:51 +01:00
|
|
|
* © 2016 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-03-30 15:08:19 +02:00
|
|
|
|
2016-01-08 13:31:58 +01:00
|
|
|
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
2015-03-30 15:08:19 +02:00
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
2015-05-07 16:36:29 +02:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.item.ItemFishingRod;
|
2015-05-07 16:36:29 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-03-30 15:08:19 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-05-07 16:36:29 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-01-07 21:41:28 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.world.WorldServer;
|
|
|
|
import net.minecraft.world.storage.loot.LootContext;
|
|
|
|
import net.minecraft.world.storage.loot.LootTableList;
|
2015-03-30 15:08:19 +02:00
|
|
|
|
2015-12-09 13:35:18 +01:00
|
|
|
import java.util.ArrayList;
|
2016-03-18 23:47:22 +01:00
|
|
|
import java.util.List;
|
2015-12-09 13:35:18 +01:00
|
|
|
|
2015-03-30 15:08:19 +02:00
|
|
|
public class TileEntityFishingNet extends TileEntityBase{
|
|
|
|
|
|
|
|
public int timeUntilNextDrop;
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, boolean sync){
|
|
|
|
super.writeSyncableNBT(compound, sync);
|
|
|
|
compound.setInteger("TimeUntilNextDrop", this.timeUntilNextDrop);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readSyncableNBT(NBTTagCompound compound, boolean sync){
|
|
|
|
super.readSyncableNBT(compound, sync);
|
|
|
|
this.timeUntilNextDrop = compound.getInteger("TimeUntilNextDrop");
|
|
|
|
}
|
|
|
|
|
2015-03-30 15:08:19 +02:00
|
|
|
@Override
|
|
|
|
public void updateEntity(){
|
2015-11-18 23:11:24 +01:00
|
|
|
super.updateEntity();
|
2015-03-30 15:08:19 +02:00
|
|
|
if(!worldObj.isRemote){
|
2015-12-03 18:40:43 +01:00
|
|
|
if(!this.isRedstonePowered){
|
2016-01-08 13:31:58 +01:00
|
|
|
if(PosUtil.getMaterial(PosUtil.offset(this.pos, 0, -1, 0), this.worldObj) == Material.water){
|
2015-05-07 16:36:29 +02:00
|
|
|
if(this.timeUntilNextDrop > 0){
|
|
|
|
this.timeUntilNextDrop--;
|
|
|
|
if(timeUntilNextDrop <= 0){
|
2016-03-18 23:47:22 +01:00
|
|
|
LootContext.Builder builder = new LootContext.Builder((WorldServer)this.worldObj);
|
|
|
|
List<ItemStack> fishables = this.worldObj.getLootTableManager().getLootTableFromLocation(LootTableList.GAMEPLAY_FISHING).generateLootForPools(Util.RANDOM, builder.build());
|
|
|
|
for(ItemStack fishable : fishables){
|
|
|
|
TileEntity tile = worldObj.getTileEntity(PosUtil.offset(pos, 0, 1, 0));
|
|
|
|
if(tile != null && tile instanceof IInventory){
|
|
|
|
ArrayList<ItemStack> list = new ArrayList<ItemStack>();
|
|
|
|
list.add(fishable);
|
|
|
|
WorldUtil.addToInventory((IInventory)tile, list, EnumFacing.DOWN, true, false);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
EntityItem item = new EntityItem(worldObj, pos.getX()+0.5, pos.getY()+0.5, pos.getZ()+0.5, fishable);
|
|
|
|
item.lifespan = 2000;
|
|
|
|
worldObj.spawnEntityInWorld(item);
|
|
|
|
}
|
2015-05-07 16:36:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-02 16:48:01 +02:00
|
|
|
else{
|
2015-11-28 19:02:01 +01:00
|
|
|
int time = 15000;
|
2015-12-09 13:35:33 +01:00
|
|
|
this.timeUntilNextDrop = time+Util.RANDOM.nextInt(time/2);
|
2015-10-02 16:48:01 +02:00
|
|
|
}
|
2015-05-07 16:36:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-30 15:08:19 +02:00
|
|
|
}
|