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
|
|
|
|
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2015-11-02 20:55:19 +01:00
|
|
|
* © 2015 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2015-03-30 15:08:19 +02:00
|
|
|
package ellpeck.actuallyadditions.tile;
|
|
|
|
|
2015-04-24 19:22:03 +02:00
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
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;
|
|
|
|
import net.minecraft.inventory.ISidedInventory;
|
|
|
|
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;
|
2015-03-30 15:08:19 +02:00
|
|
|
import net.minecraftforge.common.FishingHooks;
|
2015-05-07 16:36:29 +02:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2015-03-30 15:08:19 +02:00
|
|
|
|
|
|
|
public class TileEntityFishingNet extends TileEntityBase{
|
|
|
|
|
|
|
|
public int timeUntilNextDrop;
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
2015-10-18 15:31:01 +02:00
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, boolean sync){
|
|
|
|
compound.setInteger("TimeUntilNextDrop", this.timeUntilNextDrop);
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-18 15:31:01 +02:00
|
|
|
public void readSyncableNBT(NBTTagCompound compound, boolean sync){
|
|
|
|
this.timeUntilNextDrop = compound.getInteger("TimeUntilNextDrop");
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
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-05-07 16:36:29 +02:00
|
|
|
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){
|
2015-10-02 16:48:01 +02:00
|
|
|
if(worldObj.getBlock(xCoord, yCoord-1, zCoord).getMaterial() == Material.water){
|
2015-05-07 16:36:29 +02:00
|
|
|
if(this.timeUntilNextDrop > 0){
|
|
|
|
this.timeUntilNextDrop--;
|
|
|
|
if(timeUntilNextDrop <= 0){
|
2015-11-12 21:36:20 +01:00
|
|
|
ItemStack fishable = FishingHooks.getRandomFishable(worldObj.rand, this.worldObj.rand.nextFloat());
|
2015-10-02 16:48:01 +02:00
|
|
|
TileEntity tile = worldObj.getTileEntity(xCoord, yCoord+1, zCoord);
|
2015-05-07 16:36:29 +02:00
|
|
|
if(tile != null && tile instanceof IInventory){
|
|
|
|
this.insertIntoInventory((IInventory)tile, fishable);
|
|
|
|
}
|
|
|
|
else{
|
2015-10-02 16:48:01 +02:00
|
|
|
EntityItem item = new EntityItem(worldObj, xCoord+0.5, yCoord+0.5, zCoord+0.5, fishable);
|
2015-05-07 16:36:29 +02:00
|
|
|
item.lifespan = 2000;
|
|
|
|
worldObj.spawnEntityInWorld(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-02 16:48:01 +02:00
|
|
|
else{
|
2015-11-12 21:36:20 +01:00
|
|
|
this.timeUntilNextDrop = ConfigIntValues.FISHER_TIME.getValue()+worldObj.rand.nextInt(ConfigIntValues.FISHER_TIME.getValue()/2);
|
2015-10-02 16:48:01 +02:00
|
|
|
}
|
2015-05-07 16:36:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void insertIntoInventory(IInventory inventory, ItemStack stack){
|
|
|
|
for(int i = 0; i < inventory.getSizeInventory(); i++){
|
|
|
|
if(inventory.isItemValidForSlot(i, stack)){
|
|
|
|
if(!(inventory instanceof ISidedInventory) || ((ISidedInventory)inventory).canInsertItem(i, stack, ForgeDirection.DOWN.flag)){
|
|
|
|
ItemStack slot = inventory.getStackInSlot(i);
|
|
|
|
if(slot == null){
|
|
|
|
inventory.setInventorySlotContents(i, stack);
|
|
|
|
return;
|
|
|
|
}
|
2015-10-02 16:48:01 +02:00
|
|
|
if(slot.isItemEqual(stack) && slot.stackSize <= slot.getMaxStackSize()-stack.stackSize && slot.stackSize <= inventory.getInventoryStackLimit()-stack.stackSize){
|
2015-05-07 16:36:29 +02:00
|
|
|
slot.stackSize += stack.stackSize;
|
|
|
|
return;
|
2015-03-30 15:08:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|