mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 12:32:23 +00:00
Fix #220. More robust world object for FarmLogic
This commit is contained in:
1 parent
52e38f0f9a
commit
ad8c90f5f2
13 files changed
+54
-39
No files matched your search
@@ -26,7 +26,6 @@ import forestry.core.utils.Vect;
|
||||
|
||||
public abstract class FarmLogic implements IFarmLogic {
|
||||
|
||||
World world;
|
||||
IFarmHousing housing;
|
||||
|
||||
boolean isManual;
|
||||
@@ -40,30 +39,34 @@ public abstract class FarmLogic implements IFarmLogic {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected World getWorld() {
|
||||
return housing.getWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getSpriteSheet() {
|
||||
return SpriteSheet.ITEMS.getLocation();
|
||||
}
|
||||
|
||||
protected final boolean isAirBlock(Vect position) {
|
||||
return world.isAirBlock(position.x, position.y, position.z);
|
||||
return getWorld().isAirBlock(position.x, position.y, position.z);
|
||||
}
|
||||
|
||||
protected final boolean isWaterBlock(Vect position) {
|
||||
return world.getBlock(position.x, position.y, position.z) == Blocks.water;
|
||||
return getWorld().getBlock(position.x, position.y, position.z) == Blocks.water;
|
||||
}
|
||||
|
||||
protected final boolean isWoodBlock(Vect position) {
|
||||
Block block = getBlock(position);
|
||||
return block.isWood(world, position.x, position.y, position.z);
|
||||
return block.isWood(getWorld(), position.x, position.y, position.z);
|
||||
}
|
||||
|
||||
protected final Block getBlock(Vect position) {
|
||||
return world.getBlock(position.x, position.y, position.z);
|
||||
return getWorld().getBlock(position.x, position.y, position.z);
|
||||
}
|
||||
|
||||
protected final int getBlockMeta(Vect position) {
|
||||
return world.getBlockMetadata(position.x, position.y, position.z);
|
||||
return getWorld().getBlockMetadata(position.x, position.y, position.z);
|
||||
}
|
||||
|
||||
protected final ItemStack getAsItemStack(Vect position) {
|
||||
@@ -75,7 +78,7 @@ public abstract class FarmLogic implements IFarmLogic {
|
||||
}
|
||||
|
||||
protected final void setBlock(Vect position, Block block, int meta) {
|
||||
world.setBlock(position.x, position.y, position.z, block, meta, Defaults.FLAG_BLOCK_SYNCH);
|
||||
getWorld().setBlock(position.x, position.y, position.z, block, meta, Defaults.FLAG_BLOCK_SYNCH);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.Farmables;
|
||||
@@ -92,7 +93,7 @@ public class FarmLogicArboreal extends FarmLogicHomogenous {
|
||||
Vect max = coords.add(offset).add(area);
|
||||
|
||||
AxisAlignedBB harvestBox = AxisAlignedBB.getBoundingBox(min.x, min.y, min.z, max.x, max.y, max.z);
|
||||
List<Entity> list = housing.getWorld().getEntitiesWithinAABB(Entity.class, harvestBox);
|
||||
List<Entity> list = getWorld().getEntitiesWithinAABB(Entity.class, harvestBox);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < list.size(); i++) {
|
||||
@@ -118,8 +119,6 @@ public class FarmLogicArboreal extends FarmLogicHomogenous {
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
|
||||
world = housing.getWorld();
|
||||
|
||||
Collection<ICrop> crops = null;
|
||||
|
||||
Vect start = new Vect(x, y, z);
|
||||
@@ -140,6 +139,8 @@ public class FarmLogicArboreal extends FarmLogicHomogenous {
|
||||
|
||||
private Collection<ICrop> getHarvestBlocks(Vect position) {
|
||||
|
||||
World world = getWorld();
|
||||
|
||||
ArrayList<Vect> seen = new ArrayList<Vect>();
|
||||
Stack<ICrop> crops = new Stack<ICrop>();
|
||||
|
||||
@@ -176,6 +177,8 @@ public class FarmLogicArboreal extends FarmLogicHomogenous {
|
||||
|
||||
private ArrayList<Vect> processHarvestBlock(IFarmable germling, Stack<ICrop> crops, Collection<Vect> seen, Vect start, Vect position) {
|
||||
|
||||
World world = getWorld();
|
||||
|
||||
ArrayList<Vect> candidates = new ArrayList<Vect>();
|
||||
|
||||
// Get additional candidates to return
|
||||
@@ -238,6 +241,7 @@ public class FarmLogicArboreal extends FarmLogicHomogenous {
|
||||
|
||||
private boolean plantSapling(Vect position) {
|
||||
|
||||
World world = getWorld();
|
||||
for (IFarmable candidate : germlings)
|
||||
if (housing.plantGermling(candidate, world, position.x, position.y, position.z))
|
||||
return true;
|
||||
|
||||
@@ -24,6 +24,7 @@ import net.minecraft.util.IIcon;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
@@ -80,8 +81,6 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
@Override
|
||||
public boolean cultivate(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
|
||||
world = housing.getWorld();
|
||||
|
||||
Vect start = new Vect(x, y, z);
|
||||
if (!lastExtentsCultivation.containsKey(start))
|
||||
lastExtentsCultivation.put(start, 0);
|
||||
@@ -104,8 +103,6 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
|
||||
world = housing.getWorld();
|
||||
|
||||
Collection<ICrop> crops = null;
|
||||
|
||||
Vect start = new Vect(x, y, z);
|
||||
@@ -126,6 +123,8 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
|
||||
private boolean tryPlantingCocoa(Vect position) {
|
||||
|
||||
World world = getWorld();
|
||||
|
||||
Vect current = position;
|
||||
while (isWoodBlock(current) && BlockLog.func_150165_c(getBlockMeta(current)) == 3) {
|
||||
|
||||
@@ -155,8 +154,8 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
Block block = getBlock(position);
|
||||
|
||||
ICrop crop = null;
|
||||
if (!block.isWood(world, position.x, position.y, position.z)) {
|
||||
crop = cocoa.getCropAt(world, position.x, position.y, position.z);
|
||||
if (!block.isWood(getWorld(), position.x, position.y, position.z)) {
|
||||
crop = cocoa.getCropAt(getWorld(), position.x, position.y, position.z);
|
||||
if (crop == null)
|
||||
return crops;
|
||||
}
|
||||
@@ -180,6 +179,8 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
|
||||
private ArrayList<Vect> processHarvestBlock(Stack<ICrop> crops, Collection<Vect> seen, Vect start, Vect position) {
|
||||
|
||||
World world = getWorld();
|
||||
|
||||
ArrayList<Vect> candidates = new ArrayList<Vect>();
|
||||
|
||||
// Get additional candidates to return
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
@@ -96,7 +97,7 @@ public abstract class FarmLogicCrops extends FarmLogicWatered {
|
||||
|
||||
for (int i = 0; i < extent; i++) {
|
||||
Vect position = translateWithOffset(x, y, z, direction, i);
|
||||
if (!isAirBlock(position) && !Utils.isReplaceableBlock(world, position.x, position.y, position.z))
|
||||
if (!isAirBlock(position) && !Utils.isReplaceableBlock(getWorld(), position.x, position.y, position.z))
|
||||
continue;
|
||||
|
||||
ItemStack below = getAsItemStack(position.add(new Vect(0, -1, 0)));
|
||||
@@ -112,6 +113,7 @@ public abstract class FarmLogicCrops extends FarmLogicWatered {
|
||||
}
|
||||
|
||||
private boolean trySetCrop(Vect position) {
|
||||
World world = getWorld();
|
||||
|
||||
for (IFarmable candidate : seeds)
|
||||
if (housing.plantGermling(candidate, world, position.x, position.y, position.z))
|
||||
@@ -122,8 +124,7 @@ public abstract class FarmLogicCrops extends FarmLogicWatered {
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
|
||||
world = housing.getWorld();
|
||||
World world = getWorld();
|
||||
|
||||
Stack<ICrop> crops = new Stack<ICrop>();
|
||||
for (int i = 0; i < extent; i++) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import net.minecraft.util.IIcon;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.Farmables;
|
||||
@@ -80,8 +81,7 @@ public class FarmLogicGourd extends FarmLogic {
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
|
||||
world = housing.getWorld();
|
||||
World world = getWorld();
|
||||
|
||||
Stack<ICrop> crops = new Stack<ICrop>();
|
||||
for (int i = 0; i < extent; i++) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
@@ -61,7 +62,6 @@ public abstract class FarmLogicHomogenous extends FarmLogic {
|
||||
|
||||
@Override
|
||||
public boolean cultivate(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
world = housing.getWorld();
|
||||
|
||||
if (maintainSoil(x, y, z, direction, extent))
|
||||
return true;
|
||||
@@ -73,6 +73,7 @@ public abstract class FarmLogicHomogenous extends FarmLogic {
|
||||
}
|
||||
|
||||
private boolean maintainSoil(int x, int yGround, int z, ForgeDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
if (!housing.hasResources(resource))
|
||||
return false;
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.util.IIcon;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.Farmables;
|
||||
@@ -65,8 +66,7 @@ public class FarmLogicInfernal extends FarmLogicHomogenous {
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
|
||||
world = housing.getWorld();
|
||||
World world = getWorld();
|
||||
|
||||
Stack<ICrop> crops = new Stack<ICrop>();
|
||||
for (int i = 0; i < extent; i++) {
|
||||
@@ -84,6 +84,7 @@ public class FarmLogicInfernal extends FarmLogicHomogenous {
|
||||
|
||||
@Override
|
||||
protected boolean maintainGermlings(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
for (int i = 0; i < extent; i++) {
|
||||
Vect position = translateWithOffset(x, y, z, direction, i);
|
||||
@@ -101,6 +102,7 @@ public class FarmLogicInfernal extends FarmLogicHomogenous {
|
||||
}
|
||||
|
||||
private boolean trySetCrop(Vect position) {
|
||||
World world = getWorld();
|
||||
|
||||
for (IFarmable candidate : germlings)
|
||||
if (housing.plantGermling(candidate, world, position.x, position.y, position.z))
|
||||
|
||||
@@ -23,6 +23,7 @@ import net.minecraft.util.IIcon;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
@@ -83,8 +84,6 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
|
||||
world = housing.getWorld();
|
||||
|
||||
Collection<ICrop> crops = null;
|
||||
|
||||
Vect start = new Vect(x, y, z);
|
||||
@@ -113,7 +112,7 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
// Determine what type we want to harvest.
|
||||
IFruitBearer bearer = getFruitBlock(position);
|
||||
Block block = getBlock(position);
|
||||
if ((!block.isWood(world, position.x, position.y, position.z)) && bearer == null)
|
||||
if ((!block.isWood(getWorld(), position.x, position.y, position.z)) && bearer == null)
|
||||
return crops;
|
||||
|
||||
ArrayList<Vect> candidates = processHarvestBlock(crops, seen, position, position);
|
||||
@@ -131,6 +130,7 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
}
|
||||
|
||||
private ArrayList<Vect> processHarvestBlock(Stack<ICrop> crops, Collection<Vect> seen, Vect start, Vect position) {
|
||||
World world = getWorld();
|
||||
|
||||
ArrayList<Vect> candidates = new ArrayList<Vect>();
|
||||
|
||||
@@ -173,7 +173,7 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
}
|
||||
|
||||
private IFruitBearer getFruitBlock(Vect position) {
|
||||
TileEntity tile = world.getTileEntity(position.x, position.y, position.z);
|
||||
TileEntity tile = getWorld().getTileEntity(position.x, position.y, position.z);
|
||||
if (!(tile instanceof IFruitBearer))
|
||||
return null;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import net.minecraft.util.IIcon;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
@@ -57,8 +58,7 @@ public class FarmLogicPeat extends FarmLogicWatered {
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
|
||||
world = housing.getWorld();
|
||||
World world = getWorld();
|
||||
|
||||
Stack<ICrop> crops = new Stack<ICrop>();
|
||||
for (int i = 0; i < extent; i++) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.util.IIcon;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.Farmables;
|
||||
@@ -91,8 +92,7 @@ public class FarmLogicPoale extends FarmLogic {
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
|
||||
world = housing.getWorld();
|
||||
World world = getWorld();
|
||||
|
||||
Stack<ICrop> crops = new Stack<ICrop>();
|
||||
for (int i = 0; i < extent; i++) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import net.minecraft.util.IIcon;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
@@ -95,8 +96,6 @@ public class FarmLogicRubber extends FarmLogic {
|
||||
if (inActive)
|
||||
return null;
|
||||
|
||||
world = housing.getWorld();
|
||||
|
||||
Collection<ICrop> crops = null;
|
||||
Vect start = new Vect(x, y, z);
|
||||
if (!lastExtents.containsKey(start))
|
||||
@@ -126,7 +125,7 @@ public class FarmLogicRubber extends FarmLogic {
|
||||
|
||||
int meta = this.getBlockMeta(position);
|
||||
if (meta >= 2 && meta <= 5)
|
||||
crops.push(new CropRubber(world, block, meta, position));
|
||||
crops.push(new CropRubber(getWorld(), block, meta, position));
|
||||
|
||||
ArrayList<Vect> candidates = processHarvestBlock(crops, seen, position);
|
||||
ArrayList<Vect> temp = new ArrayList<Vect>();
|
||||
@@ -142,6 +141,7 @@ public class FarmLogicRubber extends FarmLogic {
|
||||
}
|
||||
|
||||
private ArrayList<Vect> processHarvestBlock(Stack<ICrop> crops, Collection<Vect> seen, Vect position) {
|
||||
World world = getWorld();
|
||||
|
||||
ArrayList<Vect> candidates = new ArrayList<Vect>();
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.util.IIcon;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.Farmables;
|
||||
@@ -91,8 +92,7 @@ public class FarmLogicSucculent extends FarmLogic {
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
|
||||
world = housing.getWorld();
|
||||
World world = getWorld();
|
||||
|
||||
Stack<ICrop> crops = new Stack<ICrop>();
|
||||
for (int i = 0; i < extent; i++) {
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.Collection;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@@ -68,8 +69,6 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
@Override
|
||||
public boolean cultivate(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
|
||||
world = housing.getWorld();
|
||||
|
||||
if (maintainSoil(x, y, z, direction, extent))
|
||||
return true;
|
||||
|
||||
@@ -91,6 +90,8 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
|
||||
private boolean maintainSoil(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
|
||||
World world = getWorld();
|
||||
|
||||
for (int i = 0; i < extent; i++) {
|
||||
Vect position = translateWithOffset(x, y, z, direction, i);
|
||||
if (!isAirBlock(position) && !Utils.isReplaceableBlock(world, position.x, position.y, position.z)) {
|
||||
@@ -132,6 +133,8 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
|
||||
private boolean maintainWater(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
// Still not done, check water then
|
||||
World world = getWorld();
|
||||
|
||||
for (int i = 0; i < extent; i++) {
|
||||
Vect position = translateWithOffset(x, y, z, direction, i);
|
||||
if ((!isAirBlock(position) && !Utils.isReplaceableBlock(world, position.x, position.y, position.z))
|
||||
|
||||
Reference in new issue
Block a user