make the request items action able to request more than one item at a time

This commit is contained in:
Hea3veN 2015-07-23 20:01:26 -03:00
parent c25af49829
commit 9a36844a6b
6 changed files with 124 additions and 8 deletions

View file

@ -27,7 +27,7 @@ Improvements:
* Rewritten robots request system (hea3ven)
* Changed the IRequestProvider api to be independent of robots.
* Delivery robots can now carry more than an item at a time.
* Builders and requesters now request more than one item at a time.
* Builders, requesters and docking stations can now request more than one item at a time.
* Zone Planners now have a dynamic texture (asie)
* Requesters now support the Comparator (asie)
* Add events for robot interaction and removal (asie)

View file

@ -156,6 +156,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;
@ -412,6 +413,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());

View file

@ -55,6 +55,7 @@ import buildcraft.core.config.ConfigManager;
import buildcraft.core.list.ListMatchHandlerClass;
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;

View file

@ -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;
}
}

View file

@ -54,13 +54,7 @@ public class AIRobotSearchStackRequest extends AIRobot {
if (!ai.success()) {
terminate();
} else {
// request =
// getOrderFromRequestingAction(((AIRobotSearchStation)
// ai).targetStation);
//
// if (request == null) {
request = getOrderFromRequestingStation(((AIRobotSearchStation) ai).targetStation, true);
// }
terminate();
}

View file

@ -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();
}
}