make builders display stack sizes up to 99k
This commit is contained in:
parent
0815e5f118
commit
fc62748f63
6 changed files with 124 additions and 50 deletions
|
@ -16,6 +16,7 @@ import java.util.List;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
@ -33,6 +34,7 @@ import net.minecraftforge.fluids.IFluidHandler;
|
||||||
|
|
||||||
import buildcraft.BuildCraftBuilders;
|
import buildcraft.BuildCraftBuilders;
|
||||||
import buildcraft.BuildCraftCore;
|
import buildcraft.BuildCraftCore;
|
||||||
|
import buildcraft.api.core.BCLog;
|
||||||
import buildcraft.api.core.BlockIndex;
|
import buildcraft.api.core.BlockIndex;
|
||||||
import buildcraft.api.core.IInvSlot;
|
import buildcraft.api.core.IInvSlot;
|
||||||
import buildcraft.api.core.Position;
|
import buildcraft.api.core.Position;
|
||||||
|
@ -52,6 +54,7 @@ import buildcraft.core.blueprints.BlueprintBase;
|
||||||
import buildcraft.core.blueprints.BptBuilderBase;
|
import buildcraft.core.blueprints.BptBuilderBase;
|
||||||
import buildcraft.core.blueprints.BptBuilderBlueprint;
|
import buildcraft.core.blueprints.BptBuilderBlueprint;
|
||||||
import buildcraft.core.blueprints.BptBuilderTemplate;
|
import buildcraft.core.blueprints.BptBuilderTemplate;
|
||||||
|
import buildcraft.core.blueprints.RequirementItemStack;
|
||||||
import buildcraft.core.builders.TileAbstractBuilder;
|
import buildcraft.core.builders.TileAbstractBuilder;
|
||||||
import buildcraft.core.lib.fluids.Tank;
|
import buildcraft.core.lib.fluids.Tank;
|
||||||
import buildcraft.core.lib.fluids.TankManager;
|
import buildcraft.core.lib.fluids.TankManager;
|
||||||
|
@ -84,7 +87,7 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
|
||||||
private BptBuilderBase currentBuilder;
|
private BptBuilderBase currentBuilder;
|
||||||
private RecursiveBlueprintBuilder recursiveBuilder;
|
private RecursiveBlueprintBuilder recursiveBuilder;
|
||||||
private LinkedList<BlockIndex> path;
|
private LinkedList<BlockIndex> path;
|
||||||
private ArrayList<ItemStack> requiredToBuild;
|
private ArrayList<RequirementItemStack> requiredToBuild;
|
||||||
private NBTTagCompound initNBT = null;
|
private NBTTagCompound initNBT = null;
|
||||||
private boolean done = true;
|
private boolean done = true;
|
||||||
private boolean isBuilding = false;
|
private boolean isBuilding = false;
|
||||||
|
@ -623,7 +626,7 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
|
||||||
return getStackInSlot(0) != null && getStackInSlot(0).getItem() instanceof ItemBlueprint;
|
return getStackInSlot(0) != null && getStackInSlot(0).getItem() instanceof ItemBlueprint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ItemStack> getNeededItems() {
|
public List<RequirementItemStack> getNeededItems() {
|
||||||
return requiredToBuild;
|
return requiredToBuild;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,12 +637,24 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
|
||||||
if ("clearItemRequirements".equals(command)) {
|
if ("clearItemRequirements".equals(command)) {
|
||||||
requiredToBuild = null;
|
requiredToBuild = null;
|
||||||
} else if ("setItemRequirements".equals(command)) {
|
} else if ("setItemRequirements".equals(command)) {
|
||||||
int size = stream.readUnsignedShort();
|
int size = stream.readUnsignedMedium();
|
||||||
requiredToBuild = new ArrayList<ItemStack>();
|
requiredToBuild = new ArrayList<RequirementItemStack>();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
ItemStack stack = NetworkUtils.readStack(stream);
|
int itemId = stream.readUnsignedShort();
|
||||||
stack.stackSize = Math.min(999, stream.readUnsignedShort());
|
int itemDamage = stream.readShort();
|
||||||
requiredToBuild.add(stack);
|
int stackSize = stream.readUnsignedMedium();
|
||||||
|
boolean hasCompound = stackSize >= 0x800000;
|
||||||
|
|
||||||
|
ItemStack stack = new ItemStack(Item.getItemById(itemId), 1, itemDamage);
|
||||||
|
if (hasCompound) {
|
||||||
|
stack.setTagCompound(NetworkUtils.readNBT(stream));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stack != null && stack.getItem() != null){
|
||||||
|
requiredToBuild.add(new RequirementItemStack(stack, stackSize & 0x7FFFFF));
|
||||||
|
} else {
|
||||||
|
BCLog.logger.error("Corrupt ItemStack in TileBuilder.receiveCommand! This should not happen! (ID " + itemId + ", damage " + itemDamage + ")");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (side.isServer()) {
|
} else if (side.isServer()) {
|
||||||
|
@ -657,14 +672,18 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Packet getItemRequirementsPacket(final ArrayList<ItemStack> items) {
|
private Packet getItemRequirementsPacket(final List<RequirementItemStack> items) {
|
||||||
if (items != null) {
|
if (items != null) {
|
||||||
return new PacketCommand(this, "setItemRequirements", new CommandWriter() {
|
return new PacketCommand(this, "setItemRequirements", new CommandWriter() {
|
||||||
public void write(ByteBuf data) {
|
public void write(ByteBuf data) {
|
||||||
data.writeShort(items.size());
|
data.writeMedium(items.size());
|
||||||
for (ItemStack rb : items) {
|
for (RequirementItemStack rb : items) {
|
||||||
NetworkUtils.writeStack(data, rb);
|
data.writeShort(Item.getIdFromItem(rb.stack.getItem()));
|
||||||
data.writeShort(rb.stackSize);
|
data.writeShort(rb.stack.getItemDamage());
|
||||||
|
data.writeMedium((rb.stack.hasTagCompound() ? 0x800000 : 0x000000) | Math.min(0x7FFFFF, rb.size));
|
||||||
|
if (rb.stack.hasTagCompound()) {
|
||||||
|
NetworkUtils.writeNBT(data, rb.stack.getTagCompound());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -718,7 +737,7 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateRequirements() {
|
public void updateRequirements() {
|
||||||
ArrayList<ItemStack> reqCopy = null;
|
List<RequirementItemStack> reqCopy = null;
|
||||||
if (currentBuilder instanceof BptBuilderBlueprint) {
|
if (currentBuilder instanceof BptBuilderBlueprint) {
|
||||||
currentBuilder.initialize();
|
currentBuilder.initialize();
|
||||||
reqCopy = ((BptBuilderBlueprint) currentBuilder).neededItems;
|
reqCopy = ((BptBuilderBlueprint) currentBuilder).neededItems;
|
||||||
|
@ -730,7 +749,7 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateRequirements(EntityPlayer caller) {
|
public void updateRequirements(EntityPlayer caller) {
|
||||||
ArrayList<ItemStack> reqCopy = null;
|
List<RequirementItemStack> reqCopy = null;
|
||||||
if (currentBuilder instanceof BptBuilderBlueprint) {
|
if (currentBuilder instanceof BptBuilderBlueprint) {
|
||||||
currentBuilder.initialize();
|
currentBuilder.initialize();
|
||||||
reqCopy = ((BptBuilderBlueprint) currentBuilder).neededItems;
|
reqCopy = ((BptBuilderBlueprint) currentBuilder).neededItems;
|
||||||
|
@ -843,9 +862,9 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack requirement = bpt.neededItems.get(i);
|
RequirementItemStack requirement = bpt.neededItems.get(i);
|
||||||
|
|
||||||
int qty = quantityMissing(requirement);
|
int qty = quantityMissing(requirement.stack, requirement.size);
|
||||||
|
|
||||||
if (qty <= 0) {
|
if (qty <= 0) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -855,7 +874,7 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
|
||||||
|
|
||||||
request.index = i;
|
request.index = i;
|
||||||
request.requester = this;
|
request.requester = this;
|
||||||
request.stack = requirement;
|
request.stack = requirement.stack;
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
@ -885,9 +904,9 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack requirement = bpt.neededItems.get(i);
|
RequirementItemStack requirement = bpt.neededItems.get(i);
|
||||||
|
|
||||||
int qty = quantityMissing(requirement);
|
int qty = quantityMissing(requirement.stack, requirement.size);
|
||||||
|
|
||||||
if (qty <= 0) {
|
if (qty <= 0) {
|
||||||
return stack;
|
return stack;
|
||||||
|
@ -911,8 +930,8 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int quantityMissing(ItemStack requirement) {
|
private int quantityMissing(ItemStack requirement, int amount) {
|
||||||
int left = requirement.stackSize;
|
int left = amount <= 0 ? requirement.stackSize : amount;
|
||||||
|
|
||||||
for (IInvSlot slot : InventoryIterator.getIterable(this)) {
|
for (IInvSlot slot : InventoryIterator.getIterable(this)) {
|
||||||
if (slot.getStackInSlot() != null) {
|
if (slot.getStackInSlot() != null) {
|
||||||
|
|
40
common/buildcraft/builders/gui/BuilderRequirementSlot.java
Normal file
40
common/buildcraft/builders/gui/BuilderRequirementSlot.java
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package buildcraft.builders.gui;
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import buildcraft.core.blueprints.RequirementItemStack;
|
||||||
|
import buildcraft.core.lib.gui.AdvancedSlot;
|
||||||
|
import buildcraft.core.lib.gui.GuiAdvancedInterface;
|
||||||
|
|
||||||
|
public class BuilderRequirementSlot extends AdvancedSlot {
|
||||||
|
public RequirementItemStack stack;
|
||||||
|
|
||||||
|
public BuilderRequirementSlot(GuiAdvancedInterface gui, int x, int y) {
|
||||||
|
super(gui, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getItemStack() {
|
||||||
|
return stack != null ? stack.stack : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawStack(ItemStack item) {
|
||||||
|
int cornerX = (gui.width - gui.getXSize()) / 2;
|
||||||
|
int cornerY = (gui.height - gui.getYSize()) / 2;
|
||||||
|
|
||||||
|
gui.drawStack(item, cornerX + x, cornerY + y);
|
||||||
|
|
||||||
|
if (stack != null) {
|
||||||
|
// Render real stack size
|
||||||
|
String s = String.valueOf(stack.size > 999 ? Math.min(99, stack.size / 1000) + "K" : stack.size);
|
||||||
|
GL11.glDisable(GL11.GL_LIGHTING);
|
||||||
|
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||||
|
GL11.glDisable(GL11.GL_BLEND);
|
||||||
|
gui.getFontRenderer().drawStringWithShadow(s,
|
||||||
|
cornerX + x + 17 - gui.getFontRenderer().getStringWidth(s), cornerY + y + 9, 16777215);
|
||||||
|
GL11.glEnable(GL11.GL_LIGHTING);
|
||||||
|
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,14 +16,13 @@ import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
import buildcraft.BuildCraftCore;
|
import buildcraft.BuildCraftCore;
|
||||||
import buildcraft.builders.TileBuilder;
|
import buildcraft.builders.TileBuilder;
|
||||||
|
import buildcraft.core.blueprints.RequirementItemStack;
|
||||||
import buildcraft.core.lib.fluids.Tank;
|
import buildcraft.core.lib.fluids.Tank;
|
||||||
import buildcraft.core.lib.gui.GuiAdvancedInterface;
|
import buildcraft.core.lib.gui.GuiAdvancedInterface;
|
||||||
import buildcraft.core.lib.gui.ItemSlot;
|
|
||||||
import buildcraft.core.lib.network.command.CommandWriter;
|
import buildcraft.core.lib.network.command.CommandWriter;
|
||||||
import buildcraft.core.lib.network.command.PacketCommand;
|
import buildcraft.core.lib.network.command.PacketCommand;
|
||||||
import buildcraft.core.lib.utils.StringUtils;
|
import buildcraft.core.lib.utils.StringUtils;
|
||||||
|
@ -48,7 +47,7 @@ public class GuiBuilder extends GuiAdvancedInterface {
|
||||||
|
|
||||||
for (int i = 0; i < 6; ++i) {
|
for (int i = 0; i < 6; ++i) {
|
||||||
for (int j = 0; j < 4; ++j) {
|
for (int j = 0; j < 4; ++j) {
|
||||||
slots.set(i * 4 + j, new ItemSlot(this, 179 + j * 18, 18 + i * 18));
|
slots.set(i * 4 + j, new BuilderRequirementSlot(this, 179 + j * 18, 18 + i * 18));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +79,7 @@ public class GuiBuilder extends GuiAdvancedInterface {
|
||||||
drawTexturedModalRect(guiLeft + 169, guiTop, 169, 0, 256 - 169, ySize);
|
drawTexturedModalRect(guiLeft + 169, guiTop, 169, 0, 256 - 169, ySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ItemStack> needs = builder.getNeededItems();
|
List<RequirementItemStack> needs = builder.getNeededItems();
|
||||||
|
|
||||||
if (needs != null) {
|
if (needs != null) {
|
||||||
if (needs.size() > slots.size()) {
|
if (needs.size() > slots.size()) {
|
||||||
|
@ -102,9 +101,9 @@ public class GuiBuilder extends GuiAdvancedInterface {
|
||||||
for (int s = 0; s < slots.size(); s++) {
|
for (int s = 0; s < slots.size(); s++) {
|
||||||
int ts = offset + s;
|
int ts = offset + s;
|
||||||
if (ts >= needs.size()) {
|
if (ts >= needs.size()) {
|
||||||
((ItemSlot) slots.get(s)).stack = null;
|
((BuilderRequirementSlot) slots.get(s)).stack = null;
|
||||||
} else {
|
} else {
|
||||||
((ItemSlot) slots.get(s)).stack = needs.get(ts).copy();
|
((BuilderRequirementSlot) slots.get(s)).stack = needs.get(ts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +114,7 @@ public class GuiBuilder extends GuiAdvancedInterface {
|
||||||
sbPosition = 0;
|
sbPosition = 0;
|
||||||
sbLength = 0;
|
sbLength = 0;
|
||||||
for (int s = 0; s < slots.size(); s++) {
|
for (int s = 0; s < slots.size(); s++) {
|
||||||
((ItemSlot) slots.get(s)).stack = null;
|
((BuilderRequirementSlot) slots.get(s)).stack = null;
|
||||||
}
|
}
|
||||||
for (GuiButton b : (List<GuiButton>) buttonList) {
|
for (GuiButton b : (List<GuiButton>) buttonList) {
|
||||||
b.visible = false;
|
b.visible = false;
|
||||||
|
|
|
@ -59,7 +59,7 @@ import buildcraft.core.lib.utils.BlockUtils;
|
||||||
|
|
||||||
public class BptBuilderBlueprint extends BptBuilderBase {
|
public class BptBuilderBlueprint extends BptBuilderBase {
|
||||||
|
|
||||||
public ArrayList<ItemStack> neededItems = new ArrayList<ItemStack>();
|
public ArrayList<RequirementItemStack> neededItems = new ArrayList<RequirementItemStack>();
|
||||||
|
|
||||||
protected HashSet<Integer> builtEntities = new HashSet<Integer>();
|
protected HashSet<Integer> builtEntities = new HashSet<Integer>();
|
||||||
|
|
||||||
|
@ -702,33 +702,31 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Entry<StackKey, Integer> e : computeStacks.entrySet()) {
|
for (Entry<StackKey, Integer> e : computeStacks.entrySet()) {
|
||||||
ItemStack newStack = e.getKey().stack.copy();
|
neededItems.add(new RequirementItemStack(e.getKey().stack.copy(), e.getValue()));
|
||||||
newStack.stackSize = e.getValue();
|
|
||||||
|
|
||||||
neededItems.add(newStack);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort (neededItems, new Comparator<ItemStack>() {
|
Collections.sort(neededItems, new Comparator<RequirementItemStack>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(ItemStack o1, ItemStack o2) {
|
public int compare(RequirementItemStack o1, RequirementItemStack o2) {
|
||||||
if (o1.stackSize > o2.stackSize) {
|
if (o1.size != o2.size) {
|
||||||
return -1;
|
return o1.size < o2.size ? 1 : -1;
|
||||||
} else if (o1.stackSize < o2.stackSize) {
|
|
||||||
return 1;
|
|
||||||
} else if (Item.getIdFromItem(o1.getItem()) > Item.getIdFromItem(o2.getItem())) {
|
|
||||||
return -1;
|
|
||||||
} else if (Item.getIdFromItem(o1.getItem()) < Item.getIdFromItem(o2.getItem())) {
|
|
||||||
return 1;
|
|
||||||
} else if (o1.getItemDamage() > o2.getItemDamage()) {
|
|
||||||
return -1;
|
|
||||||
} else if (o1.getItemDamage() < o2.getItemDamage()) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
ItemStack os1 = o1.stack;
|
||||||
|
ItemStack os2 = o2.stack;
|
||||||
|
if (Item.getIdFromItem(os1.getItem()) > Item.getIdFromItem(os2.getItem())) {
|
||||||
|
return -1;
|
||||||
|
} else if (Item.getIdFromItem(os1.getItem()) < Item.getIdFromItem(os2.getItem())) {
|
||||||
|
return 1;
|
||||||
|
} else if (os1.getItemDamage() > os2.getItemDamage()) {
|
||||||
|
return -1;
|
||||||
|
} else if (os1.getItemDamage() < os2.getItemDamage()) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
19
common/buildcraft/core/blueprints/RequirementItemStack.java
Normal file
19
common/buildcraft/core/blueprints/RequirementItemStack.java
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package buildcraft.core.blueprints;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
public class RequirementItemStack {
|
||||||
|
public final ItemStack stack;
|
||||||
|
public final int size;
|
||||||
|
|
||||||
|
public RequirementItemStack(ItemStack stack, int size) {
|
||||||
|
this.stack = stack;
|
||||||
|
this.size = size;
|
||||||
|
stack.stackSize = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return this.stack.hashCode() * 13 + this.size;
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,7 +11,6 @@ package buildcraft.core.lib.gui;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
public class ItemSlot extends AdvancedSlot {
|
public class ItemSlot extends AdvancedSlot {
|
||||||
|
|
||||||
public ItemStack stack;
|
public ItemStack stack;
|
||||||
|
|
||||||
public ItemSlot(GuiAdvancedInterface gui, int x, int y) {
|
public ItemSlot(GuiAdvancedInterface gui, int x, int y) {
|
||||||
|
|
Loading…
Reference in a new issue