mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-27 01:08:34 +01:00
Made the farmer put seeds back into the seed slot
This commit is contained in:
parent
6db18f05fe
commit
a96f386686
2 changed files with 42 additions and 18 deletions
|
@ -65,7 +65,7 @@ public class ContainerFarmer extends Container{
|
||||||
//Other Slots in Inventory excluded
|
//Other Slots in Inventory excluded
|
||||||
if(slot >= inventoryStart){
|
if(slot >= inventoryStart){
|
||||||
//Shift from Inventory
|
//Shift from Inventory
|
||||||
if(newStack.getItem() instanceof IPlantable){
|
if(TileEntityFarmer.getPlantableFromStack(newStack) != null){
|
||||||
if(!this.mergeItemStack(newStack, 0, 6, false)){
|
if(!this.mergeItemStack(newStack, 0, 6, false)){
|
||||||
return StackUtil.getNull();
|
return StackUtil.getNull();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import net.minecraft.util.SoundCategory;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraftforge.common.IPlantable;
|
import net.minecraftforge.common.IPlantable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TileEntityFarmer extends TileEntityInventoryBase implements ICustomEnergyReceiver{
|
public class TileEntityFarmer extends TileEntityInventoryBase implements ICustomEnergyReceiver{
|
||||||
|
@ -93,10 +94,31 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements ICustom
|
||||||
|
|
||||||
if(plantBlock instanceof BlockCrops){
|
if(plantBlock instanceof BlockCrops){
|
||||||
if(((BlockCrops)plantBlock).isMaxAge(plantState)){
|
if(((BlockCrops)plantBlock).isMaxAge(plantState)){
|
||||||
List<ItemStack> drops = plantBlock.getDrops(this.worldObj, plant, plantState, 0);
|
List<ItemStack> seeds = new ArrayList<ItemStack>();
|
||||||
|
List<ItemStack> other = new ArrayList<ItemStack>();
|
||||||
|
|
||||||
if(WorldUtil.addToInventory(this, 6, 12, drops, EnumFacing.UP, false, true)){
|
List<ItemStack> drops = plantBlock.getDrops(this.worldObj, plant, plantState, 0);
|
||||||
WorldUtil.addToInventory(this, 6, 12, drops, EnumFacing.UP, true, true);
|
for(ItemStack stack : drops){
|
||||||
|
if(getPlantableFromStack(stack) != null){
|
||||||
|
seeds.add(stack);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
other.add(stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean putSeeds = true;
|
||||||
|
if(!WorldUtil.addToInventory(this, 0, 6, seeds, EnumFacing.UP, false, true)){
|
||||||
|
other.addAll(seeds);
|
||||||
|
putSeeds = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(WorldUtil.addToInventory(this, 6, 12, other, EnumFacing.UP, false, true)){
|
||||||
|
WorldUtil.addToInventory(this, 6, 12, other, EnumFacing.UP, true, true);
|
||||||
|
|
||||||
|
if(putSeeds){
|
||||||
|
WorldUtil.addToInventory(this, 0, 6, seeds, EnumFacing.UP, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
this.worldObj.playEvent(2001, plant, Block.getStateId(plantState));
|
this.worldObj.playEvent(2001, plant, Block.getStateId(plantState));
|
||||||
this.worldObj.setBlockToAir(plant);
|
this.worldObj.setBlockToAir(plant);
|
||||||
|
@ -152,19 +174,7 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements ICustom
|
||||||
for(int i = 0; i < 6; i++){
|
for(int i = 0; i < 6; i++){
|
||||||
ItemStack stack = this.slots[i];
|
ItemStack stack = this.slots[i];
|
||||||
if(StackUtil.isValid(stack)){
|
if(StackUtil.isValid(stack)){
|
||||||
IPlantable plantable = null;
|
IPlantable plantable = getPlantableFromStack(stack);
|
||||||
|
|
||||||
Item item = stack.getItem();
|
|
||||||
if(item instanceof IPlantable){
|
|
||||||
plantable = (IPlantable)item;
|
|
||||||
}
|
|
||||||
else if(item instanceof ItemBlock){
|
|
||||||
Block block = Block.getBlockFromItem(item);
|
|
||||||
if(block instanceof IPlantable){
|
|
||||||
plantable = (IPlantable)block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(plantable != null){
|
if(plantable != null){
|
||||||
IBlockState state = plantable.getPlant(this.worldObj, pos);
|
IBlockState state = plantable.getPlant(this.worldObj, pos);
|
||||||
if(state != null && state.getBlock() instanceof BlockCrops && state.getBlock().canPlaceBlockAt(this.worldObj, pos)){
|
if(state != null && state.getBlock() instanceof BlockCrops && state.getBlock().canPlaceBlockAt(this.worldObj, pos)){
|
||||||
|
@ -177,9 +187,23 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements ICustom
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IPlantable getPlantableFromStack(ItemStack stack){
|
||||||
|
Item item = stack.getItem();
|
||||||
|
if(item instanceof IPlantable){
|
||||||
|
return (IPlantable)item;
|
||||||
|
}
|
||||||
|
else if(item instanceof ItemBlock){
|
||||||
|
Block block = Block.getBlockFromItem(item);
|
||||||
|
if(block instanceof IPlantable){
|
||||||
|
return (IPlantable)block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValidForSlot(int i, ItemStack stack){
|
public boolean isItemValidForSlot(int i, ItemStack stack){
|
||||||
return i < 6 && StackUtil.isValid(stack) && stack.getItem() instanceof IPlantable;
|
return i < 6 && StackUtil.isValid(stack) && getPlantableFromStack(stack) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue