Some more minor opts

This commit is contained in:
CovertJaguar 2012-12-12 23:10:56 -08:00
parent 2c888525d6
commit 9fbdd4040b
3 changed files with 46 additions and 37 deletions

View file

@ -119,13 +119,12 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
if (isPoweredTile(tile)) {
IPowerReceptor receptor = (IPowerReceptor) tile;
IPowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider();
float extracted = engine.extractEnergy(receptor.getPowerProvider().getMinEnergyReceived(),
receptor.getPowerProvider().getMaxEnergyReceived(), true);
float extracted = engine.extractEnergy(receptor.getMinEnergyReceived(), receptor.getMaxEnergyReceived(), true);
if (extracted > 0) {
receptor.getPowerProvider().receiveEnergy(extracted, engine.orientation.getOpposite());
receptor.receiveEnergy(extracted, engine.orientation.getOpposite());
}
}
} else if (engine.progress >= 1) {
@ -139,14 +138,14 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
if (isPoweredTile(tile)) {
IPowerReceptor receptor = (IPowerReceptor) tile;
IPowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider();
if (engine.extractEnergy(receptor.getPowerProvider().getMinEnergyReceived(),
receptor.getPowerProvider().getMaxEnergyReceived(), false) > 0) {
if (engine.extractEnergy(receptor.getMinEnergyReceived(), receptor.getMaxEnergyReceived(), false) > 0) {
progressPart = 1;
setActive(true);
} else
} else {
setActive(false);
}
} else
setActive(false);
@ -372,10 +371,9 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
public boolean isPoweredTile(TileEntity tile) {
if (tile instanceof IPowerReceptor) {
IPowerReceptor receptor = (IPowerReceptor) tile;
IPowerProvider provider = receptor.getPowerProvider();
IPowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider();
return provider != null && provider.getClass().getSuperclass().equals(PowerProvider.class);
return receptor != null && receptor.getClass().getSuperclass().equals(PowerProvider.class);
}
return false;

View file

@ -88,7 +88,7 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
if (meta > 5)
return;
Position pos = new Position(xCoord, yCoord, zCoord, ForgeDirection.values()[meta]);
Position pos = new Position(xCoord, yCoord, zCoord, ForgeDirection.getOrientation(meta));
pos.moveForwards(1);
TileEntity tile = w.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
@ -150,69 +150,80 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
ItemStack result = checkExtractGeneric(inv, doRemove, from, first, last);
if (result != null)
return new ItemStack[] { result };
if (result != null) {
return new ItemStack[]{result};
}
} else if (inventory.getSizeInventory() == 2) {
// This is an input-output inventory
int slotIndex = 0;
if (from == ForgeDirection.DOWN || from == ForgeDirection.UP)
if (from == ForgeDirection.DOWN || from == ForgeDirection.UP) {
slotIndex = 0;
else
} else {
slotIndex = 1;
}
ItemStack slot = inventory.getStackInSlot(slotIndex);
if (slot != null && slot.stackSize > 0)
if (doRemove)
return new ItemStack[] { inventory.decrStackSize(slotIndex, (int) powerProvider.useEnergy(1, slot.stackSize, true)) };
else
return new ItemStack[] { slot };
if (slot != null && slot.stackSize > 0) {
if (doRemove) {
return new ItemStack[]{inventory.decrStackSize(slotIndex, (int) powerProvider.useEnergy(1, slot.stackSize, true))};
} else {
return new ItemStack[]{slot};
}
}
} else if (inventory.getSizeInventory() == 3) {
// This is a furnace-like inventory
int slotIndex = 0;
if (from == ForgeDirection.UP)
if (from == ForgeDirection.UP) {
slotIndex = 0;
else if (from == ForgeDirection.DOWN)
} else if (from == ForgeDirection.DOWN) {
slotIndex = 1;
else
} else {
slotIndex = 2;
}
ItemStack slot = inventory.getStackInSlot(slotIndex);
if (slot != null && slot.stackSize > 0)
if (doRemove)
return new ItemStack[] { inventory.decrStackSize(slotIndex, (int) powerProvider.useEnergy(1, slot.stackSize, true)) };
else
return new ItemStack[] { slot };
if (slot != null && slot.stackSize > 0) {
if (doRemove) {
return new ItemStack[]{inventory.decrStackSize(slotIndex, (int) powerProvider.useEnergy(1, slot.stackSize, true))};
} else {
return new ItemStack[]{slot};
}
}
} else {
// This is a generic inventory
IInventory inv = Utils.getInventory(inventory);
ItemStack result = checkExtractGeneric(inv, doRemove, from, 0, inv.getSizeInventory() - 1);
if (result != null)
return new ItemStack[] { result };
if (result != null) {
return new ItemStack[]{result};
}
}
return null;
}
public ItemStack checkExtractGeneric(IInventory inventory, boolean doRemove, ForgeDirection from, int start, int stop) {
for (int k = start; k <= stop; ++k)
for (int k = start; k <= stop; ++k) {
if (inventory.getStackInSlot(k) != null && inventory.getStackInSlot(k).stackSize > 0) {
ItemStack slot = inventory.getStackInSlot(k);
if (slot != null && slot.stackSize > 0)
if (doRemove)
if (slot != null && slot.stackSize > 0) {
if (doRemove) {
return inventory.decrStackSize(k, (int) powerProvider.useEnergy(1, slot.stackSize, true));
else
} else {
return slot;
}
}
}
}
return null;
}

View file

@ -60,7 +60,7 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor {
if (meta > 5)
return;
Position pos = new Position(xCoord, yCoord, zCoord, ForgeDirection.values()[meta]);
Position pos = new Position(xCoord, yCoord, zCoord, ForgeDirection.getOrientation(meta));
pos.moveForwards(1);
TileEntity tile = w.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
@ -90,7 +90,7 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor {
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
if (liquidToExtract > 0 && meta < 6) {
Position pos = new Position(xCoord, yCoord, zCoord, ForgeDirection.values()[meta]);
Position pos = new Position(xCoord, yCoord, zCoord, ForgeDirection.getOrientation(meta));
pos.moveForwards(1);
TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);