mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-19 11:59:17 +00:00
Basics of the farming block starting to work (wheat, potatoes, carrots + nether wart)
This commit is contained in:
1 parent
0513f492e8
commit
7dcd024c18
20 files changed
+670
-233
No files matched your search
@@ -11,7 +11,7 @@ public final class Config {
|
||||
static int BID = 700;
|
||||
static int IID = 8524;
|
||||
|
||||
public static final double DEFAULT_CONDUIT_SCALE = 0.2;
|
||||
public static final double DEFAULT_CONDUIT_SCALE = 0.75;
|
||||
|
||||
public static boolean useAlternateBinderRecipe;
|
||||
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
package crazypants.enderio.farm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class DefaultSeedFarmer implements IFarmerJoe {
|
||||
|
||||
protected Block plantedBlock;
|
||||
protected int plantedBlockMeta;
|
||||
protected int grownBlockMeta;
|
||||
protected ItemStack seeds;
|
||||
|
||||
public DefaultSeedFarmer(Block plantedBlock, ItemStack seeds) {
|
||||
this(plantedBlock, 0,7,seeds);
|
||||
}
|
||||
|
||||
public DefaultSeedFarmer(Block plantedBlock, int grownBlockMeta, ItemStack seeds) {
|
||||
this(plantedBlock,0,grownBlockMeta,seeds);
|
||||
}
|
||||
|
||||
public DefaultSeedFarmer(Block plantedBlock, int plantedBlockMeta, int grownBlockMeta, ItemStack seeds) {
|
||||
this.plantedBlock = plantedBlock;
|
||||
this.plantedBlockMeta = plantedBlockMeta;
|
||||
this.grownBlockMeta = grownBlockMeta;
|
||||
this.seeds = seeds;
|
||||
}
|
||||
|
||||
public int getPlantedBlockMeta() {
|
||||
return plantedBlockMeta;
|
||||
}
|
||||
|
||||
public Block getPlantedBlock() {
|
||||
return plantedBlock;
|
||||
}
|
||||
|
||||
public ItemStack getSeeds() {
|
||||
return seeds;
|
||||
}
|
||||
|
||||
public int getFullyGrownBlockMeta() {
|
||||
return grownBlockMeta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHarvest(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
return block == getPlantedBlock() && getFullyGrownBlockMeta() == meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlant(ItemStack stack) {
|
||||
if(stack == null) {
|
||||
return false;
|
||||
}
|
||||
return stack.isItemEqual(getSeeds());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepareBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
if(block != Blocks.air) {
|
||||
return false;
|
||||
}
|
||||
World worldObj = farm.getWorldObj();
|
||||
if(isGroundTilled(farm, bc)) {
|
||||
return plantFromInvenetory(farm, bc);
|
||||
}
|
||||
|
||||
if(farm.hasSeed(getSeeds(), bc)) {
|
||||
boolean tilled= tillBlock(farm, bc);
|
||||
if(!tilled) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return plantFromInvenetory(farm, bc);
|
||||
}
|
||||
|
||||
protected boolean plantFromInvenetory(TileFarmStation farm, BlockCoord bc) {
|
||||
World worldObj = farm.getWorldObj();
|
||||
if(canPlant(worldObj, bc) && farm.getSeedFromSupplies(getSeeds(), bc)) {
|
||||
return plant(worldObj, bc);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
|
||||
if(!canHarvest(farm, bc, block, meta)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
World worldObj = farm.getWorldObj();
|
||||
List<EntityItem> result = new ArrayList<EntityItem>();
|
||||
|
||||
ArrayList<ItemStack> drops = block.getDrops(worldObj, bc.x, bc.y, bc.z, meta, farm.getMaxLootingValue());
|
||||
farm.damageMaxLootingItem();
|
||||
boolean removed = false;
|
||||
if(drops != null) {
|
||||
for (ItemStack stack : drops) {
|
||||
if(!removed && stack.isItemEqual(getSeeds())) {
|
||||
stack.stackSize--;
|
||||
removed = true;
|
||||
if(stack.stackSize > 0) {
|
||||
result.add(new EntityItem(worldObj, bc.x + 0.5, bc.y + 0.5, bc.z + 0.5, stack.copy()));
|
||||
}
|
||||
} else {
|
||||
result.add(new EntityItem(worldObj, bc.x + 0.5, bc.y + 0.5, bc.z + 0.5, stack.copy()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(removed) {
|
||||
if(!plant(worldObj, bc)) {
|
||||
result.add(new EntityItem(worldObj, bc.x + 0.5, bc.y + 0.5, bc.z + 0.5, getSeeds().copy()));
|
||||
worldObj.setBlock(bc.x, bc.y, bc.z, Blocks.air, 0, 1 | 2);
|
||||
}
|
||||
} else {
|
||||
worldObj.setBlock(bc.x, bc.y, bc.z, Blocks.air, 0, 1 | 2);
|
||||
}
|
||||
|
||||
return new HarvestResult(result, bc);
|
||||
}
|
||||
|
||||
|
||||
protected boolean tillBlock(TileFarmStation farm, BlockCoord plantingLocation) {
|
||||
World worldObj = farm.getWorldObj();
|
||||
BlockCoord dirtLoc = plantingLocation.getLocation(ForgeDirection.DOWN);
|
||||
Block dirtBlock = worldObj.getBlock(dirtLoc.x, dirtLoc.y, dirtLoc.z);
|
||||
if((dirtBlock == Blocks.dirt || dirtBlock == Blocks.grass) && farm.hasHoe()) {
|
||||
worldObj.setBlock(dirtLoc.x, dirtLoc.y, dirtLoc.z, Blocks.farmland);
|
||||
worldObj.playSoundEffect(dirtLoc.x + 0.5F, dirtLoc.y + 0.5F, dirtLoc.z + 0.5F, Blocks.farmland.stepSound.getStepResourcePath(),
|
||||
(Blocks.farmland.stepSound.getVolume() + 1.0F) / 2.0F, Blocks.farmland.stepSound.getPitch() * 0.8F);
|
||||
farm.damageHoe(1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isGroundTilled(TileFarmStation farm, BlockCoord plantingLocation) {
|
||||
World worldObj = farm.getWorldObj();
|
||||
BlockCoord dirtLoc = plantingLocation.getLocation(ForgeDirection.DOWN);
|
||||
Block dirtBlock = worldObj.getBlock(dirtLoc.x, dirtLoc.y, dirtLoc.z);
|
||||
return dirtBlock == Blocks.farmland;
|
||||
}
|
||||
|
||||
protected boolean canPlant(World worldObj, BlockCoord bc) {
|
||||
Block target = getPlantedBlock();
|
||||
Block ground = worldObj.getBlock(bc.x, bc.y - 1, bc.z);
|
||||
IPlantable plantable = (IPlantable) getPlantedBlock();
|
||||
if(target.canPlaceBlockAt(worldObj, bc.x, bc.y, bc.z) &&
|
||||
target.canBlockStay(worldObj, bc.x, bc.y, bc.z) &&
|
||||
ground.canSustainPlant(worldObj, bc.x, bc.y, bc.z, ForgeDirection.UP, plantable)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean plant(World worldObj, BlockCoord bc) {
|
||||
worldObj.setBlock(bc.x, bc.y, bc.z, Blocks.air, 0, 1 | 2);
|
||||
if(canPlant(worldObj, bc)) {
|
||||
worldObj.setBlock(bc.x, bc.y, bc.z, getPlantedBlock(), getPlantedBlockMeta(), 1 | 2);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,9 +4,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class FarmersComune implements IFarmerJoe {
|
||||
@@ -23,15 +23,18 @@ public class FarmersComune implements IFarmerJoe {
|
||||
}
|
||||
|
||||
static {
|
||||
joinComune(new PotatoeFarmerPaddy());
|
||||
joinComune(new DefaultSeedFarmer(Blocks.potatoes, new ItemStack(Items.potato)));
|
||||
joinComune(new DefaultSeedFarmer(Blocks.wheat, new ItemStack(Items.wheat_seeds)));
|
||||
joinComune(new DefaultSeedFarmer(Blocks.carrots, new ItemStack(Items.carrot)));
|
||||
joinComune(new NetherWartFarmer());
|
||||
}
|
||||
|
||||
private List<IFarmerJoe> farmers = new ArrayList<IFarmerJoe>();
|
||||
|
||||
@Override
|
||||
public boolean isFarmerForTheJob(World worldObj, BlockCoord bc, Block block, int meta, EntityPlayer player) {
|
||||
public boolean canHarvest(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
for (IFarmerJoe joe : farmers) {
|
||||
if(joe.isFarmerForTheJob(worldObj, bc, block, meta, player)) {
|
||||
if(joe.canHarvest(farm, bc, block, meta)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -39,22 +42,32 @@ public class FarmersComune implements IFarmerJoe {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntityItem> harvestBlock(World worldObj, BlockCoord bc, Block block, int meta, EntityPlayer player) {
|
||||
if(!block.canHarvestBlock(player, meta)) {
|
||||
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
if(!block.canHarvestBlock(farm.getFakePlayer(), meta)) {
|
||||
return null;
|
||||
}
|
||||
for (IFarmerJoe joe : farmers) {
|
||||
if(joe.isFarmerForTheJob(worldObj, bc, block, meta, player)) {
|
||||
return joe.harvestBlock(worldObj, bc, block, meta, player);
|
||||
if(joe.canHarvest(farm, bc, block, meta)) {
|
||||
return joe.harvestBlock(farm, bc, block, meta);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepareBlock(World worldObj, BlockCoord bc, Block block, int meta, EntityPlayer player) {
|
||||
public boolean prepareBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
for (IFarmerJoe joe : farmers) {
|
||||
if(joe.prepareBlock(worldObj, bc, block, meta, player)) {
|
||||
if(joe.prepareBlock(farm, bc, block, meta)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlant(ItemStack stack) {
|
||||
for (IFarmerJoe joe : farmers) {
|
||||
if(joe.canPlant(stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,19 +21,17 @@ public class FarmingStationRenderer implements ISimpleBlockRenderingHandler {
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
|
||||
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_CULL_FACE);
|
||||
Tessellator.instance.startDrawingQuads();
|
||||
renderWorldBlock(null, 0, 0, 0, block, 0, renderer);
|
||||
Tessellator.instance.draw();
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
|
||||
|
||||
BoundingBox bb = BoundingBox.UNIT_CUBE;
|
||||
TranslatedCubeRenderer.instance.renderBoundingBox(x, y, z, block, bb, xform, null, world != null);
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package crazypants.enderio.farm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class HarvestResult implements IHarvestResult {
|
||||
|
||||
List<EntityItem> drops;
|
||||
List<BlockCoord> harvestedBlocks;
|
||||
|
||||
public HarvestResult(List<EntityItem> drops, List<BlockCoord> harvestedBlocks) {
|
||||
this.drops = drops;
|
||||
this.harvestedBlocks = harvestedBlocks;
|
||||
}
|
||||
|
||||
public HarvestResult(List<EntityItem> drops, BlockCoord harvestedBlock) {
|
||||
this.drops = drops;
|
||||
this.harvestedBlocks = new ArrayList<BlockCoord>();
|
||||
harvestedBlocks.add(harvestedBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntityItem> getDrops() {
|
||||
return drops;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockCoord> getHarvestedBlocks() {
|
||||
return harvestedBlocks;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +1,18 @@
|
||||
package crazypants.enderio.farm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public interface IFarmerJoe {
|
||||
|
||||
boolean prepareBlock(World worldObj, BlockCoord bc, Block block, int meta, EntityPlayer player);
|
||||
boolean prepareBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta);
|
||||
|
||||
boolean isFarmerForTheJob(World worldObj, BlockCoord bc, Block block, int meta, EntityPlayer player);
|
||||
boolean canHarvest(TileFarmStation farm, BlockCoord bc, Block block, int meta);
|
||||
|
||||
List<EntityItem> harvestBlock(World worldObj, BlockCoord bc, Block block, int meta, EntityPlayer player);
|
||||
boolean canPlant(ItemStack stack);
|
||||
|
||||
IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package crazypants.enderio.farm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public interface IHarvestResult {
|
||||
|
||||
List<EntityItem> getDrops();
|
||||
List<BlockCoord> getHarvestedBlocks();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package crazypants.enderio.farm;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class NetherWartFarmer extends DefaultSeedFarmer {
|
||||
|
||||
public NetherWartFarmer() {
|
||||
super(Blocks.nether_wart, 3, new ItemStack(Items.nether_wart));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepareBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
if(block != Blocks.air) {
|
||||
return false;
|
||||
}
|
||||
World worldObj = farm.getWorldObj();
|
||||
BlockCoord grn = bc.getLocation(ForgeDirection.DOWN);
|
||||
Block blk = worldObj.getBlock(grn.x, grn.y, grn.z);
|
||||
if(blk == Blocks.soul_sand) {
|
||||
System.out.println("NetherWartFarmer.prepareBlock: !!");
|
||||
}
|
||||
|
||||
return plantFromInvenetory(farm, bc);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package crazypants.enderio.farm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemHoe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.Util;
|
||||
|
||||
public class PotatoeFarmerPaddy implements IFarmerJoe {
|
||||
|
||||
@Override
|
||||
public boolean isFarmerForTheJob(World worldObj, BlockCoord bc, Block block, int meta, EntityPlayer player) {
|
||||
return block == Blocks.potatoes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepareBlock(World worldObj, BlockCoord bc, Block block, int meta, EntityPlayer player) {
|
||||
if(block != Blocks.air || !Util.isEquipped(player, ItemHoe.class)) {
|
||||
return false;
|
||||
}
|
||||
BlockCoord loc = bc.getLocation(ForgeDirection.DOWN);
|
||||
Block blk = worldObj.getBlock(loc.x, loc.y, loc.z);
|
||||
if(blk == Blocks.dirt || blk == Blocks.grass) {
|
||||
worldObj.setBlock(loc.x, loc.y, loc.z, Blocks.farmland);
|
||||
worldObj.playSoundEffect(loc.x + 0.5F, loc.y+ 0.5F, loc.z+ 0.5F, Blocks.farmland.stepSound.getStepResourcePath(), (Blocks.farmland.stepSound.getVolume() + 1.0F) / 2.0F, Blocks.farmland.stepSound.getPitch() * 0.8F);
|
||||
player.getCurrentEquippedItem().damageItem(1, player);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntityItem> harvestBlock(World worldObj, BlockCoord bc, Block block, int meta, EntityPlayer player) {
|
||||
|
||||
if(meta < 7 || !isFarmerForTheJob(worldObj, bc, block, meta, player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<EntityItem> result = new ArrayList<EntityItem>();
|
||||
//todo: looting
|
||||
ArrayList<ItemStack> drops = block.getDrops(worldObj, bc.x, bc.y, bc.z, meta, 0);
|
||||
boolean removed = false;
|
||||
if(drops != null) {
|
||||
for (ItemStack stack : drops) {
|
||||
if(!removed && stack.getItem() == Items.potato) {
|
||||
stack.stackSize--;
|
||||
removed = true;
|
||||
if(stack.stackSize > 0) {
|
||||
result.add(new EntityItem(worldObj, bc.x + 0.5, bc.y + 0.5, bc.z + 0.5, stack.copy()));
|
||||
}
|
||||
} else {
|
||||
result.add(new EntityItem(worldObj, bc.x + 0.5, bc.y + 0.5, bc.z + 0.5, stack.copy()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(removed) {
|
||||
replant(worldObj, bc, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void replant(World worldObj, BlockCoord bc, List<EntityItem> result) {
|
||||
|
||||
worldObj.setBlock(bc.x, bc.y, bc.z, Blocks.air, 0, 1 | 2);
|
||||
|
||||
Block target = Blocks.potatoes;
|
||||
Block ground = worldObj.getBlock(bc.x, bc.y - 1, bc.z);
|
||||
IPlantable plantable = (IPlantable) Blocks.potatoes;
|
||||
if(target.canPlaceBlockAt(worldObj, bc.x, bc.y, bc.z) &&
|
||||
target.canBlockStay(worldObj, bc.x, bc.y, bc.z) &&
|
||||
ground.canSustainPlant(worldObj, bc.x, bc.y, bc.z, ForgeDirection.UP, plantable)) {
|
||||
|
||||
worldObj.setBlock(bc.x, bc.y, bc.z, Blocks.potatoes, 0, 1 | 2);
|
||||
} else {
|
||||
|
||||
result.add(new EntityItem(worldObj, bc.x + 0.5, bc.y + 0.5, bc.z + 0.5, new ItemStack(Blocks.potatoes)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,82 +4,132 @@ import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.command.IEntitySelector;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.IProjectile;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemAxe;
|
||||
import net.minecraft.item.ItemHoe;
|
||||
import net.minecraft.item.ItemShears;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.machine.AbstractMachineEntity;
|
||||
import crazypants.enderio.machine.AbstractPoweredTaskEntity;
|
||||
import crazypants.enderio.machine.IMachineRecipe;
|
||||
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
|
||||
import crazypants.enderio.machine.IPoweredTask;
|
||||
import crazypants.enderio.machine.SlotDefinition;
|
||||
import crazypants.render.BoundingBox;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.ItemUtil;
|
||||
import crazypants.util.Util;
|
||||
|
||||
public class TileFarmStation extends AbstractMachineEntity implements IEntitySelector {
|
||||
public class TileFarmStation extends AbstractPoweredTaskEntity implements IEntitySelector {
|
||||
|
||||
private static final float ENERGY_PER_TICK = 4;
|
||||
|
||||
private crazypants.util.BlockCoord lastScanned;
|
||||
private FakePlayer farmerJoe;
|
||||
|
||||
private int farmSize = 4;
|
||||
private int farmSize = 3;
|
||||
private int minToolSlot = 0;
|
||||
private int maxToolSlot = 1;
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return EnderIO.blockFarmStation.getLocalizedName();
|
||||
}
|
||||
private int minSupSlot = maxToolSlot + 1;
|
||||
private int maxSupSlot = minSupSlot + 4;
|
||||
|
||||
private static final DummyTask TASK = new DummyTask();
|
||||
|
||||
public TileFarmStation() {
|
||||
super(new SlotDefinition(6, 4));
|
||||
super(new SlotDefinition(6, 4, 0));
|
||||
currentTask = TASK;
|
||||
}
|
||||
|
||||
public boolean hasHoe() {
|
||||
return hasTool(ItemHoe.class);
|
||||
}
|
||||
|
||||
private boolean hasTool(Class<ItemHoe> class1) {
|
||||
return getTool(class1) != null;
|
||||
}
|
||||
|
||||
private ItemStack getTool(Class<ItemHoe> class1) {
|
||||
for(int i=minToolSlot;i<=maxToolSlot;i++) {
|
||||
if(Util.isType(inventory[i], class1)) {
|
||||
return inventory[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void damageHoe(int i) {
|
||||
ItemStack tool = getTool(ItemHoe.class);
|
||||
if(tool != null) {
|
||||
tool.damageItem(1, farmerJoe);
|
||||
}
|
||||
}
|
||||
|
||||
public EntityPlayer getFakePlayer() {
|
||||
return farmerJoe;
|
||||
}
|
||||
|
||||
public int getMaxLootingValue() {
|
||||
int result = 0;
|
||||
for(int i=minToolSlot;i<=maxToolSlot;i++) {
|
||||
if(inventory[i] != null) {
|
||||
int level = EnchantmentHelper.getEnchantmentLevel(Enchantment.looting.effectId, inventory[i]);
|
||||
if(level > result) {
|
||||
result = level;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void damageMaxLootingItem() {
|
||||
int maxLooting = 0;
|
||||
ItemStack toDamage = null;
|
||||
for(int i=minToolSlot;i<=maxToolSlot;i++) {
|
||||
if(inventory[i] != null) {
|
||||
int level = EnchantmentHelper.getEnchantmentLevel(Enchantment.looting.effectId, inventory[i]);
|
||||
if(level > maxLooting) {
|
||||
maxLooting = level;
|
||||
toDamage = inventory[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
if(toDamage != null) {
|
||||
toDamage.damageItem(1, farmerJoe);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
protected boolean isMachineItemValidForSlot(int i, ItemStack stack) {
|
||||
if(i < 2) {
|
||||
return Util.isType(stack, ItemHoe.class) || Util.isType(stack, ItemAxe.class) || Util.isType(stack, ItemShears.class);
|
||||
}
|
||||
return FarmersComune.instance.canPlant(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMachineName() {
|
||||
return ModObject.blockFarmStation.unlocalisedName;
|
||||
protected boolean checkProgress(boolean redstoneChecksPassed) {
|
||||
return super.checkProgress(redstoneChecksPassed) || doTick(redstoneChecksPassed);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isMachineItemValidForSlot(int i, ItemStack itemstack) {
|
||||
return slotDefinition.isInputSlot(i);
|
||||
}
|
||||
protected boolean doTick(boolean redstoneCheckPassed) {
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getProgress() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
doHoover();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean processTasks(boolean redstoneCheckPassed) {
|
||||
|
||||
|
||||
|
||||
if(!redstoneCheckPassed) {
|
||||
if(!redstoneCheckPassed || !hasPower()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(worldObj.getWorldTime() % 10 != 0) {
|
||||
if(worldObj.getWorldTime() % 4 != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -96,25 +146,52 @@ public class TileFarmStation extends AbstractMachineEntity implements IEntitySel
|
||||
int meta = worldObj.getBlockMetadata(bc.x, bc.y, bc.z);
|
||||
if(farmerJoe == null) {
|
||||
farmerJoe = FakePlayerFactory.getMinecraft(MinecraftServer.getServer().worldServerForDimension(worldObj.provider.dimensionId));
|
||||
farmerJoe.inventory.currentItem = 0;
|
||||
farmerJoe.inventory.setInventorySlotContents(0, new ItemStack(Items.iron_hoe));
|
||||
}
|
||||
|
||||
FarmersComune.instance.prepareBlock(worldObj, bc, block, meta, farmerJoe);
|
||||
List<EntityItem> harvest = FarmersComune.instance.harvestBlock(worldObj, bc, block, meta, farmerJoe);
|
||||
if(harvest != null) {
|
||||
for (EntityItem ei : harvest) {
|
||||
FarmersComune.instance.prepareBlock(this, bc, block, meta);
|
||||
IHarvestResult harvest = FarmersComune.instance.harvestBlock(this, bc, block, meta);
|
||||
if(harvest != null && harvest.getDrops() != null) {
|
||||
for (EntityItem ei : harvest.getDrops()) {
|
||||
if(ei != null) {
|
||||
worldObj.spawnEntityInWorld(ei);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasSeed(ItemStack seeds, BlockCoord bc) {
|
||||
for(int i=minSupSlot;i<maxSupSlot;i++) {
|
||||
ItemStack inv = inventory[i];
|
||||
if(inv != null && inv.isItemEqual(seeds)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean getSeedFromSupplies(ItemStack stack, BlockCoord forBlock) {
|
||||
if(stack == null || forBlock == null) {
|
||||
return false;
|
||||
}
|
||||
for(int i=minSupSlot;i<maxSupSlot;i++) {
|
||||
ItemStack inv = inventory[i];
|
||||
if(inv != null && inv.isItemEqual(stack)) {
|
||||
inv.stackSize--;
|
||||
if(inv.stackSize == 0) {
|
||||
inv = null;
|
||||
}
|
||||
setInventorySlotContents(i, inv);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void doHoover() {
|
||||
//TODO: dont do this when your full
|
||||
if(isFull()) {
|
||||
return;
|
||||
}
|
||||
BoundingBox bb = new BoundingBox(getLocation());
|
||||
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ);
|
||||
aabb = aabb.expand(farmSize + 1, farmSize + 1, farmSize + 1);
|
||||
@@ -126,38 +203,67 @@ public class TileFarmStation extends AbstractMachineEntity implements IEntitySel
|
||||
double z = (zCoord + 0.5D - entity.posZ);
|
||||
|
||||
double distance = Math.sqrt(x * x + y * y + z * z);
|
||||
if(distance < 1.1) {
|
||||
if(distance < 1.25) {
|
||||
hooverEntity(entity);
|
||||
} else {
|
||||
double var11 = 1.0 - distance / 15.0;
|
||||
|
||||
if(var11 > 0.0D) {
|
||||
var11 *= var11;
|
||||
entity.motionX += x / distance * var11 * 0.05;
|
||||
entity.motionY += y / distance * var11 * 0.2;
|
||||
entity.motionZ += z / distance * var11 * 0.05;
|
||||
}
|
||||
double speed = 0.035;
|
||||
entity.motionX += x / distance * speed;
|
||||
entity.motionY += y * speed;
|
||||
entity.motionZ += z / distance * speed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isFull() {
|
||||
for (int i = minSupSlot; i <= maxSupSlot; i++) {
|
||||
ItemStack stack = inventory[i];
|
||||
if(stack == null || stack.stackSize < stack.getMaxStackSize()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (int i = slotDefinition.getMinOutputSlot(); i <= slotDefinition.getMaxOutputSlot(); i++) {
|
||||
ItemStack stack = inventory[i];
|
||||
if(stack == null || stack.stackSize < stack.getMaxStackSize()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void hooverEntity(Entity entity) {
|
||||
if(!worldObj.isRemote) {
|
||||
if(entity instanceof EntityItem && !entity.isDead) {
|
||||
EntityItem item = (EntityItem) entity;
|
||||
ItemStack stack = item.getEntityItem().copy();
|
||||
int numInserted = ItemUtil.doInsertItem(this, stack);
|
||||
|
||||
int numInserted = insertResult(stack);
|
||||
stack.stackSize -= numInserted;
|
||||
item.setEntityItemStack(stack);
|
||||
if(stack.stackSize == 0) {
|
||||
item.setDead();
|
||||
} else {
|
||||
item.setEntityItemStack(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int insertResult(ItemStack stack) {
|
||||
|
||||
int origSize = stack.stackSize;
|
||||
stack = stack.copy();
|
||||
|
||||
//try and place in the inputs first to restock
|
||||
int inserted = ItemUtil.doInsertItem(this, stack, ForgeDirection.UNKNOWN);
|
||||
if(inserted >= origSize) {
|
||||
return origSize;
|
||||
}
|
||||
stack.stackSize -= inserted;
|
||||
ResultStack[] in = new ResultStack[] { new ResultStack(stack) };
|
||||
mergeResults(in);
|
||||
return origSize - (in[0].item == null ? 0 : in[0].item.stackSize);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEntityApplicable(Entity entity) {
|
||||
if(entity.isDead) {
|
||||
@@ -168,7 +274,6 @@ public class TileFarmStation extends AbstractMachineEntity implements IEntitySel
|
||||
}
|
||||
if(entity instanceof EntityItem) {
|
||||
ItemStack stack = ((EntityItem) entity).getEntityItem();
|
||||
//TODO: What if the inventory is full?
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -195,4 +300,88 @@ public class TileFarmStation extends AbstractMachineEntity implements IEntitySel
|
||||
return new BlockCoord(nextX, lastScanned.y, nextZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return EnderIO.blockFarmStation.getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMachineName() {
|
||||
return ModObject.blockFarmStation.unlocalisedName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getProgress() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
doHoover();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPowerUsePerTick() {
|
||||
return ENERGY_PER_TICK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCustomNBT(NBTTagCompound nbtRoot) {
|
||||
super.readCustomNBT(nbtRoot);
|
||||
currentTask = TASK;
|
||||
}
|
||||
|
||||
private static class DummyTask implements IPoweredTask {
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbtRoot) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float availableEnergy) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplete() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRequiredEnergy() {
|
||||
return ENERGY_PER_TICK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMachineRecipe getRecipe() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getProgress() {
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultStack[] getCompletedResult() {
|
||||
return new ResultStack[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChance() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package crazypants.enderio.farm;
|
||||
|
||||
public class WheatFarmerBruce {
|
||||
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public abstract class AbstractMachineContainer extends Container {
|
||||
//Check from inv->input then inv->upgrade then inv->hotbar or hotbar->inv
|
||||
if(slotIndex >= startPlayerSlot) {
|
||||
if(!mergeItemStack(origStack, slotDef.getMinInputSlot(), slotDef.getMaxInputSlot() + 1, false)) {
|
||||
if(slotDef.getNumOutputSlots() > 0 && !mergeItemStack(origStack, slotDef.getMinUpgradeSlot(), slotDef.getMaxUpgradeSlot() + 1, false)) {
|
||||
if(slotDef.getNumUpgradeSlots() > 0 && !mergeItemStack(origStack, slotDef.getMinUpgradeSlot(), slotDef.getMaxUpgradeSlot() + 1, false)) {
|
||||
if(slotIndex <= endPlayerSlot) {
|
||||
if(!mergeItemStack(origStack, startHotBarSlot, endHotBarSlot, false)) {
|
||||
return null;
|
||||
|
||||
@@ -12,7 +12,7 @@ import crazypants.enderio.machine.IMachineRecipe.ResultStack;
|
||||
|
||||
public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity implements ISidedInventory {
|
||||
|
||||
protected PoweredTask currentTask = null;
|
||||
protected IPoweredTask currentTask = null;
|
||||
protected IMachineRecipe lastCompletedRecipe;
|
||||
|
||||
protected final Random random = new Random();
|
||||
@@ -134,46 +134,12 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity im
|
||||
}
|
||||
|
||||
protected void taskComplete() {
|
||||
|
||||
if(currentTask != null) {
|
||||
lastCompletedRecipe = currentTask.getRecipe();
|
||||
ResultStack[] output = currentTask.getCompletedResult();
|
||||
|
||||
if(output != null && output.length > 0) {
|
||||
|
||||
ResultStack[] results = currentTask.getCompletedResult();
|
||||
|
||||
List<ItemStack> outputStacks = new ArrayList<ItemStack>(slotDefinition.getNumOutputSlots());
|
||||
if(slotDefinition.getNumOutputSlots() > 0) {
|
||||
for (int i = slotDefinition.minOutputSlot; i <= slotDefinition.maxOutputSlot; i++) {
|
||||
ItemStack it = inventory[i];
|
||||
if(it != null) {
|
||||
it = it.copy();
|
||||
}
|
||||
outputStacks.add(it);
|
||||
}
|
||||
}
|
||||
|
||||
for (ResultStack result : results) {
|
||||
if(result.item != null) {
|
||||
mergeItemResult(result.item, outputStacks);
|
||||
} else if(result.fluid != null) {
|
||||
mergeFluidResult(result);
|
||||
}
|
||||
}
|
||||
|
||||
if(slotDefinition.getNumOutputSlots() > 0) {
|
||||
int listIndex = 0;
|
||||
for (int i = slotDefinition.minOutputSlot; i <= slotDefinition.maxOutputSlot; i++) {
|
||||
ItemStack st = outputStacks.get(listIndex);
|
||||
if(st != null) {
|
||||
st = st.copy();
|
||||
}
|
||||
inventory[i] = st;
|
||||
listIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
mergeResults(results);
|
||||
} else {
|
||||
System.out.println("AbstractPoweredTaskEntity.taskComplete: no output " + output);
|
||||
}
|
||||
@@ -184,6 +150,42 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity im
|
||||
currentTask = null;
|
||||
}
|
||||
|
||||
protected void mergeResults(ResultStack[] results) {
|
||||
List<ItemStack> outputStacks = new ArrayList<ItemStack>(slotDefinition.getNumOutputSlots());
|
||||
if(slotDefinition.getNumOutputSlots() > 0) {
|
||||
for (int i = slotDefinition.minOutputSlot; i <= slotDefinition.maxOutputSlot; i++) {
|
||||
ItemStack it = inventory[i];
|
||||
if(it != null) {
|
||||
it = it.copy();
|
||||
}
|
||||
outputStacks.add(it);
|
||||
}
|
||||
}
|
||||
|
||||
for (ResultStack result : results) {
|
||||
if(result.item != null) {
|
||||
int numMerged = mergeItemResult(result.item, outputStacks);
|
||||
if(numMerged > 0) {
|
||||
result.item.stackSize -= numMerged;
|
||||
}
|
||||
} else if(result.fluid != null) {
|
||||
mergeFluidResult(result);
|
||||
}
|
||||
}
|
||||
|
||||
if(slotDefinition.getNumOutputSlots() > 0) {
|
||||
int listIndex = 0;
|
||||
for (int i = slotDefinition.minOutputSlot; i <= slotDefinition.maxOutputSlot; i++) {
|
||||
ItemStack st = outputStacks.get(listIndex);
|
||||
if(st != null) {
|
||||
st = st.copy();
|
||||
}
|
||||
inventory[i] = st;
|
||||
listIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void mergeFluidResult(ResultStack result) {
|
||||
}
|
||||
|
||||
@@ -194,17 +196,21 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity im
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean mergeItemResult(ItemStack item, List<ItemStack> outputStacks) {
|
||||
protected int mergeItemResult(ItemStack item, List<ItemStack> outputStacks) {
|
||||
|
||||
int res = 0;
|
||||
|
||||
ItemStack copy = item.copy();
|
||||
//try to add it to existing stacks first
|
||||
item = item.copy();
|
||||
copy = copy.copy();
|
||||
for (ItemStack outStack : outputStacks) {
|
||||
if(outStack != null && item != null) {
|
||||
int num = getNumCanMerge(outStack, item);
|
||||
if(outStack != null && copy != null) {
|
||||
int num = getNumCanMerge(outStack, copy);
|
||||
outStack.stackSize += num;
|
||||
item.stackSize -= num;
|
||||
if(item.stackSize <= 0) {
|
||||
return true;
|
||||
res += num;
|
||||
copy.stackSize -= num;
|
||||
if(copy.stackSize <= 0) {
|
||||
return item.stackSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -213,12 +219,12 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity im
|
||||
for (int i = 0; i < outputStacks.size(); i++) {
|
||||
ItemStack outStack = outputStacks.get(i);
|
||||
if(outStack == null) {
|
||||
outputStacks.set(i, item);
|
||||
return true;
|
||||
outputStacks.set(i, copy);
|
||||
return item.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected MachineRecipeInput[] getInputs() {
|
||||
@@ -257,7 +263,7 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity im
|
||||
|
||||
for (ResultStack result : nextResults) {
|
||||
if(result.item != null) {
|
||||
if(!mergeItemResult(result.item, outputStacks)) {
|
||||
if(mergeItemResult(result.item, outputStacks) == 0) {
|
||||
return false;
|
||||
}
|
||||
} else if(result.fluid != null) {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package crazypants.enderio.machine;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
|
||||
|
||||
public interface IPoweredTask {
|
||||
|
||||
void update(float availableEnergy);
|
||||
|
||||
boolean isComplete();
|
||||
|
||||
float getProgress();
|
||||
|
||||
ResultStack[] getCompletedResult();
|
||||
|
||||
float getRequiredEnergy();
|
||||
|
||||
float getChance();
|
||||
|
||||
void writeToNBT(NBTTagCompound nbtRoot);
|
||||
|
||||
IMachineRecipe getRecipe();
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
|
||||
|
||||
public class PoweredTask {
|
||||
public class PoweredTask implements IPoweredTask {
|
||||
|
||||
public static final String KEY_INPUT_STACKS = "inputsStacks";
|
||||
|
||||
@@ -59,18 +59,25 @@ public class PoweredTask {
|
||||
requiredEnergy = recipe.getEnergyRequired(inputsIn);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(float availableEnergy) {
|
||||
usedEnergy += availableEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplete() {
|
||||
return usedEnergy >= requiredEnergy;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getProgress() {
|
||||
return MathHelper.clamp_float(usedEnergy / requiredEnergy, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResultStack[] getCompletedResult() {
|
||||
return recipe.getCompletedResult(chance, inputs);
|
||||
}
|
||||
@@ -83,6 +90,10 @@ public class PoweredTask {
|
||||
this.inputs = inputs;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see crazypants.enderio.machine.IPoweredTask#getRequiredEnergy()
|
||||
*/
|
||||
@Override
|
||||
public float getRequiredEnergy() {
|
||||
return requiredEnergy;
|
||||
}
|
||||
@@ -91,6 +102,10 @@ public class PoweredTask {
|
||||
this.requiredEnergy = requiredEnergy;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see crazypants.enderio.machine.IPoweredTask#getChance()
|
||||
*/
|
||||
@Override
|
||||
public float getChance() {
|
||||
return chance;
|
||||
}
|
||||
@@ -99,6 +114,10 @@ public class PoweredTask {
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see crazypants.enderio.machine.IPoweredTask#writeToNBT(net.minecraft.nbt.NBTTagCompound)
|
||||
*/
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbtRoot) {
|
||||
NBTTagCompound stackRoot;
|
||||
|
||||
|
||||
@@ -11,6 +11,15 @@ public class SlotDefinition {
|
||||
public final int minOutputSlot;
|
||||
public final int maxOutputSlot;
|
||||
|
||||
public SlotDefinition(int numInputs, int numOutputs, int numUpgradeSlots) {
|
||||
this.minInputSlot = 0;
|
||||
this.maxInputSlot = numInputs - 1;
|
||||
this.minOutputSlot = numOutputs > 0 ? numInputs : -10;
|
||||
this.maxOutputSlot = minOutputSlot + (numOutputs - 1);
|
||||
this.minUpgradeSlot = -1;
|
||||
this.maxUpgradeSlot = -1;
|
||||
}
|
||||
|
||||
public SlotDefinition(int numInputs, int numOutputs) {
|
||||
this.minInputSlot = 0;
|
||||
this.maxInputSlot = numInputs - 1;
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.machine.AbstractPoweredTaskEntity;
|
||||
import crazypants.enderio.machine.IMachineRecipe;
|
||||
import crazypants.enderio.machine.IPoweredTask;
|
||||
import crazypants.enderio.machine.MachineRecipeInput;
|
||||
import crazypants.enderio.machine.PoweredTask;
|
||||
import crazypants.enderio.machine.SlotDefinition;
|
||||
@@ -67,7 +68,7 @@ public class TileCrusher extends AbstractPoweredTaskEntity {
|
||||
|
||||
@Override
|
||||
protected void taskComplete() {
|
||||
PoweredTask ct = currentTask;
|
||||
IPoweredTask ct = currentTask;
|
||||
super.taskComplete();
|
||||
//run it again if the ball says so
|
||||
if(gb != null) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import crazypants.enderio.machine.GuiMachineBase;
|
||||
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
|
||||
import crazypants.enderio.machine.IoMode;
|
||||
import crazypants.enderio.machine.MachineRecipeInput;
|
||||
import crazypants.enderio.machine.PoweredTask;
|
||||
import crazypants.gui.GuiToolTip;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.Lang;
|
||||
@@ -91,15 +92,16 @@ public class GuiVat extends GuiMachineBase {
|
||||
drawTexturedModalRect(guiLeft + 81, guiTop + 76 - scaled, 176, 12 - scaled, 14, scaled + 2);
|
||||
|
||||
IIcon inputIcon = null;
|
||||
for (MachineRecipeInput input : vat.getCurrentTask().getInputs()) {
|
||||
PoweredTask task = (PoweredTask)vat.getCurrentTask();
|
||||
for (MachineRecipeInput input : task.getInputs()) {
|
||||
if(input.fluid != null && input.fluid.getFluid() != null) {
|
||||
inputIcon = input.fluid.getFluid().getStillIcon();
|
||||
break;
|
||||
}
|
||||
}
|
||||
VatMachineRecipe rec = (VatMachineRecipe) vat.getCurrentTask().getRecipe();
|
||||
VatMachineRecipe rec = (VatMachineRecipe) task.getRecipe();
|
||||
IIcon outputIcon = null;
|
||||
for (ResultStack res : rec.getCompletedResult(1.0f, vat.getCurrentTask().getInputs())) {
|
||||
for (ResultStack res : rec.getCompletedResult(1.0f, task.getInputs())) {
|
||||
if(res.fluid != null && res.fluid.getFluid() != null) {
|
||||
outputIcon = res.fluid.getFluid().getStillIcon();
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ import crazypants.enderio.Config;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.machine.AbstractPoweredTaskEntity;
|
||||
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
|
||||
import crazypants.enderio.machine.IPoweredTask;
|
||||
import crazypants.enderio.machine.MachineRecipeInput;
|
||||
import crazypants.enderio.machine.PoweredTask;
|
||||
import crazypants.enderio.machine.SlotDefinition;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.FluidUtil;
|
||||
@@ -280,7 +280,7 @@ public class TileVat extends AbstractPoweredTaskEntity implements IFluidHandler
|
||||
|
||||
}
|
||||
|
||||
public PoweredTask getCurrentTask() {
|
||||
public IPoweredTask getCurrentTask() {
|
||||
return currentTask;
|
||||
}
|
||||
|
||||
|
||||
@@ -281,4 +281,12 @@ public class Util {
|
||||
}
|
||||
|
||||
|
||||
public static boolean isType(ItemStack stack, Class<? extends Item> class1) {
|
||||
if(stack == null || class1 == null) {
|
||||
return false;
|
||||
}
|
||||
return class1.isAssignableFrom(stack.getItem().getClass());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user