mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-27 23:45:55 +00:00
#697 Added support for IC2 rubber trees to farming station.
This commit is contained in:
1 parent
955603fd86
commit
7e9e4c6047
10 files changed
+134
-29
No files matched your search
@@ -1,9 +1,13 @@
|
||||
package crazypants.enderio.machine.farm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemAxe;
|
||||
import net.minecraft.item.ItemHoe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
@@ -20,7 +24,18 @@ public class FarmersCommune implements IFarmerJoe {
|
||||
}
|
||||
|
||||
private List<IFarmerJoe> farmers = new ArrayList<IFarmerJoe>();
|
||||
|
||||
|
||||
private Set<Class<?>> toolTypes = new HashSet<Class<?>>();
|
||||
|
||||
private FarmersCommune() {
|
||||
registerToolType(ItemHoe.class);
|
||||
registerToolType(ItemAxe.class);
|
||||
}
|
||||
|
||||
public void registerToolType(Class<?> clz) {
|
||||
toolTypes.add(clz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHarvest(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
for (IFarmerJoe joe : farmers) {
|
||||
@@ -33,9 +48,6 @@ public class FarmersCommune implements IFarmerJoe {
|
||||
|
||||
@Override
|
||||
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.canHarvest(farm, bc, block, meta)) {
|
||||
return joe.harvestBlock(farm, bc, block, meta);
|
||||
@@ -64,6 +76,10 @@ public class FarmersCommune implements IFarmerJoe {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Set<Class<?>> getToolTypes() {
|
||||
return toolTypes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -26,6 +26,14 @@ public final class FarmersRegistry {
|
||||
addNutura();
|
||||
addTiC();
|
||||
addStillHungry();
|
||||
addIC2();
|
||||
}
|
||||
|
||||
private static void addIC2() {
|
||||
RubberTreeFarmerIC2 rtf = new RubberTreeFarmerIC2();
|
||||
if(rtf.isValid()) {
|
||||
FarmersCommune.instance.joinCommune(rtf);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addStillHungry() {
|
||||
|
||||
@@ -17,14 +17,14 @@ public class NaturaBerryFarmer extends PickableFarmer {
|
||||
@Override
|
||||
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
|
||||
if(block != getPlantedBlock() || !farm.hasHarvestTool()) {
|
||||
if(block != getPlantedBlock() || !farm.hasDefaultHarvestTool()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IHarvestResult res = new HarvestResult();
|
||||
|
||||
BlockCoord checkBlock = bc;
|
||||
for(int i=0; i < 5 && farm.hasHarvestTool(); i++) {
|
||||
for(int i=0; i < 5 && farm.hasDefaultHarvestTool(); i++) {
|
||||
meta = farm.getBlockMeta(checkBlock);
|
||||
IHarvestResult blockRes = super.harvestBlock(farm, checkBlock, block, meta);
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class PickableFarmer extends SeedFarmer {
|
||||
@Override
|
||||
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
|
||||
if(!canHarvest(farm, bc, block, meta) || !farm.hasHarvestTool()) {
|
||||
if(!canHarvest(farm, bc, block, meta) || !farm.hasDefaultHarvestTool()) {
|
||||
return null;
|
||||
}
|
||||
EntityPlayerMP player = farm.getFakePlayer();
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package crazypants.enderio.machine.farm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import crazypants.util.BlockCoord;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RubberTreeFarmerIC2 extends TreeFarmer {
|
||||
|
||||
private Class<?> treeTap;
|
||||
private ItemStack stickyResin;
|
||||
|
||||
public RubberTreeFarmerIC2() {
|
||||
super(GameRegistry.findBlock("IC2", "blockRubSapling"), GameRegistry.findBlock("IC2", "blockRubWood"));
|
||||
Item item = GameRegistry.findItem("IC2", "itemTreetap");
|
||||
if(item != null) {
|
||||
treeTap = item.getClass();
|
||||
FarmersCommune.instance.registerToolType(treeTap);
|
||||
}
|
||||
item = GameRegistry.findItem("IC2", "itemHarz");
|
||||
if(item != null) {
|
||||
stickyResin = new ItemStack(item);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return woods != null && woods.length > 0 && sapling != null && saplingItem != null && treeTap != null && stickyResin != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
HarvestResult res = new HarvestResult();
|
||||
int y = bc.y;
|
||||
boolean done = false;
|
||||
while (!done && farm.hasTool(treeTap)) {
|
||||
bc = new BlockCoord(bc.x, y, bc.z);
|
||||
block = farm.getBlock(bc);
|
||||
if(!isWood(block)) {
|
||||
done = true;
|
||||
} else {
|
||||
meta = farm.getBlockMeta(bc);
|
||||
if(attemptHarvest(res, farm.getWorldObj(), bc.x, y, bc.z, meta)) {
|
||||
farm.damageTool(treeTap, woods[0], bc, 1);
|
||||
}
|
||||
}
|
||||
y++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private boolean attemptHarvest(HarvestResult res, World world, int x, int y, int z, int meta) {
|
||||
if(meta > 1 && meta < 6) {
|
||||
world.setBlockMetadataWithNotify(x, y, z, meta + 6, 3);
|
||||
world.scheduleBlockUpdate(x, y, z, woods[0], woods[0].tickRate(world));
|
||||
ItemStack drop = stickyResin.copy();
|
||||
drop.stackSize = world.rand.nextInt(3) + 1;
|
||||
EntityItem dropEnt = new EntityItem(world, x + 0.5, y + 1, z + 0.5, drop);
|
||||
res.getDrops().add(dropEnt);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public class SeedFarmer implements IFarmerJoe {
|
||||
@Override
|
||||
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
|
||||
if(!canHarvest(farm, bc, block, meta) || !farm.hasHarvestTool()) {
|
||||
if(!canHarvest(farm, bc, block, meta) || !farm.hasDefaultHarvestTool()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public class StemFarmer extends SeedFarmer {
|
||||
boolean done = false;
|
||||
do{
|
||||
harvestCoord = harvestCoord.getLocation(ForgeDirection.UP);
|
||||
if(plantedBlock == farm.getBlock(harvestCoord) && farm.hasHarvestTool()) {
|
||||
if(plantedBlock == farm.getBlock(harvestCoord) && farm.hasDefaultHarvestTool()) {
|
||||
res.harvestedBlocks.add(harvestCoord);
|
||||
ArrayList<ItemStack> drops = plantedBlock.getDrops(farm.getWorld(), harvestCoord.x, harvestCoord.y, harvestCoord.z, meta, farm.getMaxLootingValue());
|
||||
if(drops != null) {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package crazypants.enderio.machine.farm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
@@ -56,6 +59,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
|
||||
super(new SlotDefinition(6, 4, 1));
|
||||
currentTask = TASK;
|
||||
powerHandler = PowerHandlerUtil.createHandler(cap, this, Type.MACHINE);
|
||||
|
||||
}
|
||||
|
||||
public int getFarmSize() {
|
||||
@@ -117,7 +121,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
|
||||
return hasTool(ItemAxe.class);
|
||||
}
|
||||
|
||||
public boolean hasHarvestTool() {
|
||||
public boolean hasDefaultHarvestTool() {
|
||||
return hasAxe() || hasHoe();
|
||||
}
|
||||
|
||||
@@ -138,11 +142,11 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
|
||||
damageTool(ItemHoe.class, null, bc, i);
|
||||
}
|
||||
|
||||
private boolean hasTool(Class<? extends Item> class1) {
|
||||
public boolean hasTool(Class<?> class1) {
|
||||
return getTool(class1) != null;
|
||||
}
|
||||
|
||||
private ItemStack getTool(Class<? extends Item> class1) {
|
||||
private ItemStack getTool(Class<?> class1) {
|
||||
for (int i = minToolSlot; i <= maxToolSlot; i++) {
|
||||
if(Util.isType(inventory[i], class1)) {
|
||||
return inventory[i];
|
||||
@@ -151,17 +155,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
|
||||
return null;
|
||||
}
|
||||
|
||||
private void destroyTool(Class<? extends Item> class1) {
|
||||
for (int i = minToolSlot; i <= maxToolSlot; i++) {
|
||||
if(Util.isType(inventory[i], class1)) {
|
||||
inventory[i] = null;
|
||||
markDirty();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void damageTool(Class<? extends Item> class1, Block blk, BlockCoord bc, int damage) {
|
||||
public void damageTool(Class<?> class1, Block blk, BlockCoord bc, int damage) {
|
||||
|
||||
float rand = worldObj.rand.nextFloat();
|
||||
if (rand >= Config.farmToolTakeDamageChance)
|
||||
@@ -176,6 +170,8 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
|
||||
tool.getItem().onBlockDestroyed(tool, worldObj, blk, bc.x, bc.y, bc.z, farmerJoe);
|
||||
} else if(tool.getItem() instanceof ItemHoe) {
|
||||
tool.getItem().onItemUse(tool, farmerJoe, worldObj, bc.x, bc.y, bc.z, 1, 0.5f, 0.5f, 0.5f);
|
||||
} else if(tool.isItemStackDamageable()) {
|
||||
tool.damageItem(1, farmerJoe);
|
||||
}
|
||||
|
||||
if(tool.isItemStackDamageable() && tool.getItemDamage() >= tool.getMaxDamage()) {
|
||||
@@ -183,6 +179,16 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
|
||||
}
|
||||
}
|
||||
|
||||
private void destroyTool(Class<?> class1) {
|
||||
for (int i = minToolSlot; i <= maxToolSlot; i++) {
|
||||
if(Util.isType(inventory[i], class1)) {
|
||||
inventory[i] = null;
|
||||
markDirty();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getLooting(ItemStack stack) {
|
||||
return Math.max(
|
||||
EnchantmentHelper.getEnchantmentLevel(Enchantment.looting.effectId, stack),
|
||||
@@ -212,10 +218,12 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
|
||||
return false;
|
||||
}
|
||||
if(i < 2) {
|
||||
return
|
||||
(Util.isType(stack, ItemHoe.class) && !hasHoe()) ||
|
||||
(Util.isType(stack, ItemAxe.class) && !hasAxe()) ||
|
||||
(getTool(stack.getItem().getClass()) == null && getLooting(stack) > 0);
|
||||
for(Class<?> toolType : FarmersCommune.instance.getToolTypes()) {
|
||||
if(getTool(stack.getItem().getClass()) == null && (Util.isType(stack, toolType) || getLooting(stack) > 0)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return FarmersCommune.instance.canPlant(stack);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,9 @@ public class TreeFarmer implements IFarmerJoe {
|
||||
|
||||
public TreeFarmer(Block sapling, Block... wood) {
|
||||
this.sapling = sapling;
|
||||
saplingItem = new ItemStack(sapling);
|
||||
if(sapling != null) {
|
||||
saplingItem = new ItemStack(sapling);
|
||||
}
|
||||
this.woods = wood;
|
||||
}
|
||||
|
||||
|
||||
@@ -297,7 +297,7 @@ public class Util {
|
||||
return class1.isAssignableFrom(player.inventory.getCurrentItem().getItem().getClass());
|
||||
}
|
||||
|
||||
public static boolean isType(ItemStack stack, Class<? extends Item> class1) {
|
||||
public static boolean isType(ItemStack stack, Class<?> class1) {
|
||||
if(stack == null || class1 == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user