Merge branch 'master' of github.com:BuildCraft/BuildCraft

This commit is contained in:
Player 2013-02-20 16:54:30 +01:00
commit 7146463b21
10 changed files with 155 additions and 33 deletions

View file

@ -1,8 +1,8 @@
## Welcome to Buildcraft on GitHub
### Contributing
If you wish to submit a pull request to fix bugs or broken behaivor feel free to do so. If you would like to add
features or change existing behaivour or balance, please discuss it with Sengir or Krapht before submiting the pull request.
If you wish to submit a pull request to fix bugs or broken behaviour feel free to do so. If you would like to add
features or change existing behaviour or balance, please discuss it with Sengir or Krapht before submiting the pull request.
### Compiling and packaging Buildcraft
1. Ensure that `Apache Ant` (found [here](http://ant.apache.org/)) is installed correctly on your system.

View file

@ -19,7 +19,7 @@
<property name="mc.version" value="1.4.7"/>
<property name="forge.version" value="6.6.0.515"/>
<property name="project.version" value="3.4.1"/>
<property name="project.version" value="3.4.2"/>
<property name="forge.name" value="minecraftforge-src-${mc.version}-${forge.version}.zip"/>

View file

@ -24,6 +24,11 @@ public class CommandBuildCraft extends CommandBase {
public String getCommandUsage(ICommandSender sender) {
return "/" + this.getCommandName() + " help";
}
@Override
public boolean canCommandSenderUseCommand(ICommandSender par1ICommandSender) {
return true;
}
@Override
public List getCommandAliases() {

View file

@ -45,7 +45,7 @@ public class TransactorSimple extends Transactor {
continue;
}
if (inventory.getStackInSlot(i).stackSize >= inventory.getStackInSlot(i).getMaxStackSize()) {
if (inventory.getStackInSlot(i).stackSize >= inventory.getStackInSlot(i).getMaxStackSize() || inventory.getStackInSlot(i).stackSize >= inventory.getInventoryStackLimit()) {
continue;
}

View file

@ -65,14 +65,15 @@ public class BlockUtil {
}
public static boolean canChangeBlock(World world, int x, int y, int z) {
if (world.isAirBlock(x, y, z))
return true;
return canChangeBlock(world.getBlockId(x, y, z), world, x, y, z);
}
int blockID = world.getBlockId(x, y, z);
if (Block.blocksList[blockID] == null)
return true;
public static boolean canChangeBlock(int blockID, World world, int x, int y, int z) {
Block block = Block.blocksList[blockID];
if (blockID == 0 || block == null || block.isAirBlock(world, x, y, z))
return true;
if (block.getBlockHardness(world, x, y, z) < 0)
return false;
@ -86,12 +87,13 @@ public class BlockUtil {
}
public static boolean isSoftBlock(World world, int x, int y, int z) {
if (world.isAirBlock(x, y, z))
return true;
return isSoftBlock(world.getBlockId(x, y, z), world, x, y, z);
}
int blockId = world.getBlockId(x, y, z);
public static boolean isSoftBlock(int blockID, World world, int x, int y, int z) {
Block block = Block.blocksList[blockID];
return BuildCraftAPI.softBlocks[blockId] || Block.blocksList[blockId] == null;
return blockID == 0 || block == null || BuildCraftAPI.softBlocks[blockID] || block.isAirBlock(world, x, y, z);
}
/**

View file

@ -0,0 +1,78 @@
package buildcraft.core.utils;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.world.World;
public class CraftingHelper {
public static IRecipe findMatchingRecipe(InventoryCrafting par1InventoryCrafting, World par2World)
{
int var3 = 0;
ItemStack var4 = null;
ItemStack var5 = null;
int var6;
for (var6 = 0; var6 < par1InventoryCrafting.getSizeInventory(); ++var6)
{
ItemStack var7 = par1InventoryCrafting.getStackInSlot(var6);
if (var7 != null)
{
if (var3 == 0)
{
var4 = var7;
}
if (var3 == 1)
{
var5 = var7;
}
++var3;
}
}
if (var3 == 2 && var4.itemID == var5.itemID && var4.stackSize == 1 && var5.stackSize == 1 && Item.itemsList[var4.itemID].isRepairable())
{
Item var11 = Item.itemsList[var4.itemID];
int var13 = var11.getMaxDamage() - var4.getItemDamageForDisplay();
int var8 = var11.getMaxDamage() - var5.getItemDamageForDisplay();
int var9 = var13 + var8 + var11.getMaxDamage() * 5 / 100;
int var10 = var11.getMaxDamage() - var9;
if (var10 < 0)
{
var10 = 0;
}
ArrayList ingredients = new ArrayList<ItemStack>(2);
ingredients.add(var4);
ingredients.add(var5);
return new ShapelessRecipes(new ItemStack(var4.itemID, 1, var10),ingredients);
}
else
{
List recipes = CraftingManager.getInstance().getRecipeList();
for (var6 = 0; var6 < recipes.size(); ++var6)
{
IRecipe var12 = (IRecipe) recipes.get(var6);
if (var12.matches(par1InventoryCrafting, par2World))
{
return var12;
}
}
return null;
}
}
}

View file

@ -17,6 +17,7 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
@ -27,11 +28,13 @@ import buildcraft.api.inventory.ISpecialInventory;
import buildcraft.core.inventory.TransactorRoundRobin;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import buildcraft.core.utils.CraftingHelper;
public class TileAutoWorkbench extends TileEntity implements ISpecialInventory {
private ItemStack stackList[] = new ItemStack[9];
private IRecipe currentRecipe = null;
class LocalInventoryCrafting extends InventoryCrafting {
public LocalInventoryCrafting() {
@ -53,6 +56,11 @@ public class TileAutoWorkbench extends TileEntity implements ISpecialInventory {
}
public IRecipe getCurrentRecipe() {
return currentRecipe ;
}
@Override
public int getSizeInventory() {
@ -137,9 +145,10 @@ public class TileAutoWorkbench extends TileEntity implements ISpecialInventory {
craftMatrix.setInventorySlotContents(i, stack);
}
ItemStack recipe = CraftingManager.getInstance().findMatchingRecipe(craftMatrix, worldObj);
if(this.currentRecipe == null || !this.currentRecipe.matches(craftMatrix, worldObj))
currentRecipe = CraftingHelper.findMatchingRecipe(craftMatrix, worldObj);
return recipe;
return currentRecipe.getCraftingResult(craftMatrix);
}
public ItemStack extractItem(boolean doRemove, boolean removeRecipe) {
@ -177,7 +186,14 @@ public class TileAutoWorkbench extends TileEntity implements ISpecialInventory {
craftMatrix.setInventorySlotContents(i, stack);
}
ItemStack resultStack = CraftingManager.getInstance().findMatchingRecipe(craftMatrix, worldObj);
if(this.currentRecipe == null || !this.currentRecipe.matches(craftMatrix, worldObj))
currentRecipe = buildcraft.core.utils.CraftingHelper.findMatchingRecipe(craftMatrix, worldObj);
ItemStack resultStack = null;
if(currentRecipe != null) {
resultStack = currentRecipe.getCraftingResult(craftMatrix);
}
if (resultStack == null || !doRemove) {
resetPointers(pointerList);

33
common/buildcraft/factory/TileQuarry.java Normal file → Executable file
View file

@ -75,7 +75,7 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
boolean isDigging = false;
public static int MAX_ENERGY = 15000;
public static final int MAX_ENERGY = 15000;
public TileQuarry() {
powerProvider = PowerFramework.currentFramework.createPowerProvider();
@ -234,7 +234,7 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
headTrajectory = Math.atan2(target[2] - head[2], target[0] - head[0]);
}
private LinkedList<int[]> visitList = Lists.newLinkedList();
private final LinkedList<int[]> visitList = Lists.newLinkedList();
public boolean findTarget(boolean doSet) {
@ -251,7 +251,7 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
if (visitList.isEmpty())
return false;
boolean foundTarget = false;
boolean foundTarget;
int[] target;
do {
if (visitList.isEmpty()) {
@ -260,7 +260,8 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
target = visitList.removeFirst();
boolean alternativeTarget = false;
for (int y = target[1] + 1; y < yCoord + 3; y++) {
if (BlockUtil.canChangeBlock(worldObj, target[0], y, target[2]) && !BlockUtil.isSoftBlock(worldObj, target[0], y, target[2])) {
int blockID = worldObj.getBlockId(target[0], y, target[2]);
if (BlockUtil.canChangeBlock(blockID, worldObj, target[0], y, target[2]) && !BlockUtil.isSoftBlock(blockID, worldObj, target[0], y, target[2])) {
createColumnVisitList();
alternativeTarget = true;
break;
@ -278,6 +279,8 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
*/
private void createColumnVisitList() {
visitList.clear();
Integer[][] columnHeights = new Integer[bluePrintBuilder.bluePrint.sizeX - 2][bluePrintBuilder.bluePrint.sizeZ - 2];
boolean[][] blockedColumns = new boolean[bluePrintBuilder.bluePrint.sizeX - 2][bluePrintBuilder.bluePrint.sizeZ - 2];
for (int searchY = yCoord + 3; searchY >= 0; --searchY) {
int startX, endX, incX;
@ -307,11 +310,20 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
for (int searchZ = startZ; searchZ != endZ; searchZ += incZ) {
if (!blockedColumns[searchX][searchZ]) {
Integer height = columnHeights[searchX][searchZ];
int bx = box.xMin + searchX + 1, by = searchY, bz = box.zMin + searchZ + 1;
if (!BlockUtil.canChangeBlock(worldObj, bx, by, bz)) {
if (height == null)
columnHeights[searchX][searchZ] = height = worldObj.getHeightValue(bx, bz);
if (height < by)
continue;
int blockID = worldObj.getBlockId(bx, by, bz);
if (!BlockUtil.canChangeBlock(blockID, worldObj, bx, by, bz)) {
blockedColumns[searchX][searchZ] = true;
} else if (!BlockUtil.isSoftBlock(worldObj, bx, by, bz)) {
} else if (!BlockUtil.isSoftBlock(blockID, worldObj, bx, by, bz)) {
visitList.add(new int[] { bx, by, bz });
}
// Stop at two planes - generally any obstructions will have been found and will force a recompute prior to this
@ -321,7 +333,6 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
}
}
}
}
@Override
@ -461,7 +472,8 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
}
private boolean isQuarriableBlock(int bx, int by, int bz) {
return BlockUtil.canChangeBlock(worldObj, bx, by, bz) && !BlockUtil.isSoftBlock(worldObj, bx, by, bz);
int blockID = worldObj.getBlockId(bx, by, bz);
return BlockUtil.canChangeBlock(blockID, worldObj, bx, by, bz) && !BlockUtil.isSoftBlock(blockID, worldObj, bx, by, bz);
}
@Override
@ -529,7 +541,6 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
}
int xSize = a.xMax() - a.xMin() + 1;
int ySize = a.yMax() - a.yMin() + 1;
int zSize = a.zMax() - a.zMin() + 1;
if (xSize < 3 || zSize < 3 || ((xSize * zSize) >> 8) >= chunkTicket.getMaxChunkListDepth()) {
@ -544,7 +555,7 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
}
xSize = a.xMax() - a.xMin() + 1;
ySize = a.yMax() - a.yMin() + 1;
int ySize = a.yMax() - a.yMin() + 1;
zSize = a.zMax() - a.zMin() + 1;
box.initialize(a);
@ -555,7 +566,7 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
}
if (useDefault) {
int xMin = 0, zMin = 0;
int xMin, zMin;
ForgeDirection o = ForgeDirection.values()[worldObj.getBlockMetadata(xCoord, yCoord, zCoord)].getOpposite();

View file

@ -12,6 +12,7 @@ import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
@ -23,6 +24,7 @@ import buildcraft.core.network.PacketSlotChange;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.SimpleInventory;
import buildcraft.core.utils.Utils;
import buildcraft.core.utils.CraftingHelper;
import com.google.common.collect.Lists;
@ -117,6 +119,7 @@ public class TileAssemblyAdvancedWorkbench extends TileEntity implements IInvent
private int tick;
private int recentEnergyAverage;
private InternalPlayer internalPlayer;
private IRecipe currentRecipe;
@Override
public int getSizeInventory() {
@ -354,7 +357,14 @@ public class TileAssemblyAdvancedWorkbench extends TileEntity implements IInvent
}
private void updateCraftingResults() {
craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(internalInventoryCrafting, worldObj));
if(this.currentRecipe == null || !this.currentRecipe.matches(internalInventoryCrafting, worldObj))
currentRecipe = CraftingHelper.findMatchingRecipe(internalInventoryCrafting, worldObj);
ItemStack resultStack = null;
if(currentRecipe != null) {
resultStack = currentRecipe.getCraftingResult(internalInventoryCrafting);
}
craftResult.setInventorySlotContents(0, resultStack);
onInventoryChanged();
}

View file

@ -123,8 +123,8 @@ public class PipeTransportPower extends PipeTransport {
nearbyTransport.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), watts);
displayPower[j] += (short) Math.ceil(watts * DISPLAY_POWER_FACTOR);
displayPower[i] += (short) Math.ceil(watts * DISPLAY_POWER_FACTOR);
displayPower[j] += (short) (watts * DISPLAY_POWER_FACTOR + .9999);
displayPower[i] += (short) (watts * DISPLAY_POWER_FACTOR + .9999);
internalPower[i] -= watts;
} else if (tiles[j] instanceof IPowerReceptor) {
@ -135,8 +135,8 @@ public class PipeTransportPower extends PipeTransport {
if (prov != null) {
prov.receiveEnergy((float) watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
displayPower[j] += (short) Math.ceil(watts * DISPLAY_POWER_FACTOR);
displayPower[i] += (short) Math.ceil(watts * DISPLAY_POWER_FACTOR);
displayPower[j] += (short) (watts * DISPLAY_POWER_FACTOR + .9999);
displayPower[i] += (short) (watts * DISPLAY_POWER_FACTOR + .9999);
internalPower[i] -= watts;
}