From 6549ead866751debaedba6b40ccf6fd2e4ee4927 Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Tue, 1 Apr 2014 09:02:30 +0200 Subject: [PATCH] initial progress for #1503 --- common/buildcraft/builders/BuildingItem.java | 13 +++++++- common/buildcraft/builders/TileFiller.java | 21 ------------- .../core/blueprints/BptBuilderBase.java | 2 +- .../core/blueprints/BptBuilderTemplate.java | 30 +++++++++++++++++-- .../core/blueprints/BuildingSlot.java | 10 +++++++ 5 files changed, 50 insertions(+), 26 deletions(-) diff --git a/common/buildcraft/builders/BuildingItem.java b/common/buildcraft/builders/BuildingItem.java index 13f7d57f..ddc9e11f 100755 --- a/common/buildcraft/builders/BuildingItem.java +++ b/common/buildcraft/builders/BuildingItem.java @@ -43,6 +43,7 @@ public class BuildingItem implements IBuilder { double maxLifetime = 0; private boolean initialized = false; double vx, vy, vz; + double maxHeight; public BuildingSlot slotToBuild; public IBuilderContext context; @@ -57,6 +58,16 @@ public class BuildingItem implements IBuilder { maxLifetime = size * 7.0; + maxHeight = (5.0 + (destination.y - origin.y) / 2.0); + + double a = maxLifetime / 2.0; + double b = maxHeight; + double c = Math.sqrt(a * a + b * b); + + // Since the item is going to travel up as well, this is an + // approximation of the additional distance to go through. + maxLifetime += c * 2; + vx = dx / maxLifetime; vy = dy / maxLifetime; vz = dz / maxLifetime; @@ -81,7 +92,7 @@ public class BuildingItem implements IBuilder { Position result = new Position (); result.x = origin.x + vx * time; - result.y = origin.y + vy * time + Math.sin(time / maxLifetime * Math.PI) * (5.0 + (destination.y - origin.y) / 2.0); + result.y = origin.y + vy * time + Math.sin(time / maxLifetime * Math.PI) * maxHeight; result.z = origin.z + vz * time; return result; diff --git a/common/buildcraft/builders/TileFiller.java b/common/buildcraft/builders/TileFiller.java index 4c827c23..ceba601d 100644 --- a/common/buildcraft/builders/TileFiller.java +++ b/common/buildcraft/builders/TileFiller.java @@ -125,27 +125,6 @@ public class TileFiller extends TileAbstractBuilder implements IMachine, IAction sendNetworkUpdate(); } } - - /*ItemStack stackToUse = null; - int slotNum = 0; - - for (IInvSlot slot : InventoryIterator.getIterable(inv, ForgeDirection.UNKNOWN)) { - ItemStack stack = slot.getStackInSlot(); - if (stack != null && stack.stackSize > 0) { - stackToUse = stack; - slotNum = slot.getIndex(); - break; - } - } - - - if (stackToUse != null && stackToUse.stackSize <= 0) { - setInventorySlotContents(slotNum, null); - } - - if (done) { - sendNetworkUpdate(); - }*/ } @Override diff --git a/common/buildcraft/core/blueprints/BptBuilderBase.java b/common/buildcraft/core/blueprints/BptBuilderBase.java index 93ade901..35461b6f 100644 --- a/common/buildcraft/core/blueprints/BptBuilderBase.java +++ b/common/buildcraft/core/blueprints/BptBuilderBase.java @@ -49,7 +49,7 @@ public abstract class BptBuilderBase implements IAreaProvider { i.destination = slot.getDestination(); i.slotToBuild = slot; i.context = getContext(); - i.stacksToBuild = slot.getRequirements(getContext()); + i.stacksToBuild = slot.stackConsumed; builder.addBuildingItem(i); return true; diff --git a/common/buildcraft/core/blueprints/BptBuilderTemplate.java b/common/buildcraft/core/blueprints/BptBuilderTemplate.java index b96017ff..7f9c1f94 100644 --- a/common/buildcraft/core/blueprints/BptBuilderTemplate.java +++ b/common/buildcraft/core/blueprints/BptBuilderTemplate.java @@ -10,11 +10,16 @@ package buildcraft.core.blueprints; import java.util.LinkedList; +import net.minecraft.item.ItemStack; import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.BuildCraftBuilders; import buildcraft.api.blueprints.Schematic; import buildcraft.api.core.BuildCraftAPI; import buildcraft.builders.TileAbstractBuilder; import buildcraft.core.blueprints.BuildingSlotBlock.Mode; +import buildcraft.core.inventory.InventoryIterator; +import buildcraft.core.inventory.InventoryIterator.IInvSlot; public class BptBuilderTemplate extends BptBuilderBase { @@ -110,19 +115,38 @@ public class BptBuilderTemplate extends BptBuilderBase { public BuildingSlotBlock internalGetNextBlock(World world, TileAbstractBuilder inv, LinkedList list) { BuildingSlotBlock result = null; + IInvSlot firstSlotToConsume = null; + + for (IInvSlot invSlot : InventoryIterator.getIterable(inv, ForgeDirection.UNKNOWN)) { + ItemStack stack = invSlot.getStackInSlot(); + + if (stack != null && stack.stackSize > 0) { + firstSlotToConsume = invSlot; + break; + } + } + while (list.size() > 0) { - BuildingSlotBlock slot = list.removeFirst(); + BuildingSlotBlock slot = list.getFirst(); if (slot.mode == Mode.ClearIfInvalid && !BuildCraftAPI.softBlocks.contains(context.world() .getBlock(slot.x, slot.y, slot.z))) { + slot.addStackConsumed(new ItemStack(BuildCraftBuilders.stripesBlock)); result = slot; + list.removeFirst(); + break; } else if (slot.mode == Mode.Build && BuildCraftAPI.softBlocks.contains(context.world() .getBlock(slot.x, slot.y, slot.z))) { - result = slot; - break; + + if (firstSlotToConsume != null) { + slot.addStackConsumed(firstSlotToConsume.decreaseStackInSlot()); + result = slot; + list.removeFirst(); + break; + } } } diff --git a/common/buildcraft/core/blueprints/BuildingSlot.java b/common/buildcraft/core/blueprints/BuildingSlot.java index b07cb895..203c9bc1 100755 --- a/common/buildcraft/core/blueprints/BuildingSlot.java +++ b/common/buildcraft/core/blueprints/BuildingSlot.java @@ -16,6 +16,8 @@ import buildcraft.api.core.Position; public abstract class BuildingSlot { + public LinkedList stackConsumed; + public void writeToWorld(IBuilderContext context) { } @@ -29,4 +31,12 @@ public abstract class BuildingSlot { } public abstract Position getDestination (); + + public void addStackConsumed (ItemStack stack) { + if (stackConsumed == null) { + stackConsumed = new LinkedList(); + } + + stackConsumed.add (stack); + } }