make the request items action able to request more than one item at a time
This commit is contained in:
parent
37bda2f153
commit
7a9e0e484d
4 changed files with 123 additions and 1 deletions
|
@ -148,6 +148,7 @@ import buildcraft.core.statements.ActionRedstoneOutput;
|
|||
import buildcraft.core.statements.DefaultActionProvider;
|
||||
import buildcraft.core.statements.DefaultTriggerProvider;
|
||||
import buildcraft.core.statements.StatementParameterDirection;
|
||||
import buildcraft.core.statements.StatementParameterItemStackExact;
|
||||
import buildcraft.core.statements.StatementParameterRedstoneGateSideOnly;
|
||||
import buildcraft.core.statements.TriggerEnergy;
|
||||
import buildcraft.core.statements.TriggerFluidContainer;
|
||||
|
@ -396,6 +397,7 @@ public class BuildCraftCore extends BuildCraftMod {
|
|||
StatementManager.registerParameterClass("buildcraft:stackAction", StatementParameterItemStack.class);
|
||||
|
||||
StatementManager.registerParameterClass(StatementParameterItemStack.class);
|
||||
StatementManager.registerParameterClass(StatementParameterItemStackExact.class);
|
||||
StatementManager.registerParameterClass(StatementParameterDirection.class);
|
||||
StatementManager.registerParameterClass(StatementParameterRedstoneGateSideOnly.class);
|
||||
StatementManager.registerTriggerProvider(new DefaultTriggerProvider());
|
||||
|
|
|
@ -53,6 +53,7 @@ import buildcraft.core.Version;
|
|||
import buildcraft.core.config.ConfigManager;
|
||||
import buildcraft.core.network.EntityIds;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.statements.StatementParameterItemStackExact;
|
||||
import buildcraft.robotics.BlockRequester;
|
||||
import buildcraft.robotics.BlockZonePlan;
|
||||
import buildcraft.robotics.BoardProgrammingRecipe;
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
package buildcraft.core.statements;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
import buildcraft.api.statements.IStatement;
|
||||
import buildcraft.api.statements.IStatementContainer;
|
||||
import buildcraft.api.statements.IStatementParameter;
|
||||
import buildcraft.api.statements.StatementMouseClick;
|
||||
|
||||
public class StatementParameterItemStackExact implements IStatementParameter {
|
||||
|
||||
protected ItemStack stack;
|
||||
|
||||
@Override
|
||||
public IIcon getIcon() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(IStatementContainer source, IStatement stmt, ItemStack stack, StatementMouseClick mouse) {
|
||||
if (stack != null) {
|
||||
if (areItemsEqual(this.stack, stack)) {
|
||||
if (mouse.getButton() == 0) {
|
||||
this.stack.stackSize += (mouse.isShift()) ? 16 : 1;
|
||||
if (this.stack.stackSize > 64) {
|
||||
this.stack.stackSize = 64;
|
||||
}
|
||||
} else {
|
||||
this.stack.stackSize -= (mouse.isShift()) ? 16 : 1;
|
||||
if (this.stack.stackSize < 0) {
|
||||
this.stack.stackSize = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.stack = stack.copy();
|
||||
}
|
||||
} else {
|
||||
if (this.stack != null) {
|
||||
if (mouse.getButton() == 0) {
|
||||
this.stack.stackSize += (mouse.isShift()) ? 16 : 1;
|
||||
if (this.stack.stackSize > 64) {
|
||||
this.stack.stackSize = 64;
|
||||
}
|
||||
} else {
|
||||
this.stack.stackSize -= (mouse.isShift()) ? 16 : 1;
|
||||
if (this.stack.stackSize < 0) {
|
||||
this.stack = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
if (stack != null) {
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
stack.writeToNBT(tagCompound);
|
||||
compound.setTag("stack", tagCompound);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
stack = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("stack"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object instanceof StatementParameterItemStackExact) {
|
||||
StatementParameterItemStackExact param = (StatementParameterItemStackExact) object;
|
||||
|
||||
return areItemsEqual(stack, param.stack);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean areItemsEqual(ItemStack stack1, ItemStack stack2) {
|
||||
if (stack1 != null) {
|
||||
return stack1.isItemEqual(stack2) && ItemStack.areItemStackTagsEqual(stack1, stack2);
|
||||
} else {
|
||||
return stack2 == null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
if (stack != null) {
|
||||
return stack.getDisplayName();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return "buildcraft:stackExact";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister iconRegister) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatementParameter rotateLeft() {
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ import net.minecraft.client.renderer.texture.IIconRegister;
|
|||
import buildcraft.api.statements.IStatementParameter;
|
||||
import buildcraft.api.statements.StatementParameterItemStack;
|
||||
import buildcraft.core.lib.utils.StringUtils;
|
||||
import buildcraft.core.statements.StatementParameterItemStackExact;
|
||||
|
||||
public class ActionStationRequestItems extends ActionStationInputItems {
|
||||
|
||||
|
@ -42,6 +43,6 @@ public class ActionStationRequestItems extends ActionStationInputItems {
|
|||
|
||||
@Override
|
||||
public IStatementParameter createParameter(int index) {
|
||||
return new StatementParameterItemStack();
|
||||
return new StatementParameterItemStackExact();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue