use of buildcraft.api.statements.StatementMouseClick in project BuildCraft by BuildCraft.
the class GuiElementStatementParam method onMouseClicked.
// IInteractionElement
@Override
public void onMouseClicked(int button) {
if (ref.canInteract && contains(gui.mouse) && button == 0) {
IStatementParameter param = get();
if (param == null) {
return;
}
StatementMouseClick clickEvent = new StatementMouseClick(0, false);
final ItemStack heldStack;
EntityPlayer currentPlayer = Minecraft.getMinecraft().player;
if (currentPlayer == null) {
heldStack = ItemStack.EMPTY;
} else {
heldStack = currentPlayer.inventory.getItemStack();
}
IStatementParameter pNew = param.onClick(container, ref.get(), heldStack, clickEvent);
if (pNew != null) {
set(pNew);
} else {
IStatementParameter[] possible = param.getPossible(container);
if (!param.isPossibleOrdered()) {
List<IStatementParameter> list = new ArrayList<>();
for (IStatementParameter p2 : possible) {
if (p2 != null) {
list.add(p2);
}
}
possible = list.toArray(new IStatementParameter[0]);
}
gui.currentMenu = GuiElementStatementVariant.create(gui, this, this, possible);
}
}
}
use of buildcraft.api.statements.StatementMouseClick in project BuildCraft by BuildCraft.
the class GuiGateInterface method doSlotClick.
private void doSlotClick(AdvancedSlot slot, int k) {
if (slot instanceof TriggerSlot && container.hasTriggers()) {
TriggerSlot triggerSlot = (TriggerSlot) slot;
IStatement changed = null;
if (!isShiftKeyDown()) {
if (triggerSlot.getStatement() == null) {
if (k == 0) {
changed = container.getFirstTrigger();
} else {
changed = container.getLastTrigger();
}
} else {
Iterator<IStatement> it = container.getTriggerIterator(k != 0);
for (; it.hasNext(); ) {
IStatement trigger = it.next();
if (!it.hasNext()) {
break;
}
if (trigger == triggerSlot.getStatement()) {
changed = it.next();
break;
}
}
}
}
if (changed == null) {
container.setTrigger(triggerSlot.slot, null, true);
} else {
container.setTrigger(triggerSlot.slot, changed.getUniqueTag(), true);
}
for (StatementParameterSlot p : triggerSlot.parameters) {
IStatementParameter parameter = null;
if (changed != null && p.slot < changed.minParameters()) {
parameter = changed.createParameter(p.slot);
}
container.setTriggerParameter(triggerSlot.slot, p.slot, parameter, true);
}
} else if (slot instanceof ActionSlot) {
ActionSlot actionSlot = (ActionSlot) slot;
IStatement changed = null;
if (!isShiftKeyDown()) {
if (actionSlot.getStatement() == null) {
if (k == 0) {
changed = container.getFirstAction();
} else {
changed = container.getLastAction();
}
} else {
Iterator<IStatement> it = container.getActionIterator(k != 0);
for (; it.hasNext(); ) {
IStatement action = it.next();
if (!it.hasNext()) {
break;
}
if (action == actionSlot.getStatement()) {
changed = it.next();
break;
}
}
}
}
if (changed == null) {
container.setAction(actionSlot.slot, null, true);
} else {
container.setAction(actionSlot.slot, changed.getUniqueTag(), true);
}
for (StatementParameterSlot p : actionSlot.parameters) {
IStatementParameter parameter = null;
if (changed != null && p.slot < changed.minParameters()) {
parameter = changed.createParameter(p.slot);
}
container.setActionParameter(actionSlot.slot, p.slot, parameter, true);
}
} else if (slot instanceof StatementParameterSlot) {
StatementParameterSlot paramSlot = (StatementParameterSlot) slot;
StatementSlot statement = paramSlot.statementSlot;
if (statement.isDefined() && statement.getStatement().maxParameters() > paramSlot.slot) {
IStatementParameter param = paramSlot.getParameter();
if (param == null) {
param = statement.getStatement().createParameter(paramSlot.slot);
}
if (param != null) {
param.onClick(gate, statement.getStatement(), mc.thePlayer.inventory.getItemStack(), new StatementMouseClick(k, isShiftKeyDown()));
paramSlot.setParameter(param, true);
}
}
}
container.markDirty();
}
use of buildcraft.api.statements.StatementMouseClick in project BuildCraft by BuildCraft.
the class GuiFiller method mouseClicked.
@Override
protected void mouseClicked(int x, int y, int k) throws IOException {
super.mouseClicked(x, y, k);
AdvancedSlot slot = getSlotAtLocation(x, y);
if (slot != null && !filler.isPatternLocked()) {
int i = ((FillerParameterSlot) slot).slot;
if (i < filler.patternParameters.length) {
if (filler.patternParameters[i] != null) {
filler.patternParameters[i].onClick(filler, filler.currentPattern, mc.thePlayer.inventory.getItemStack(), new StatementMouseClick(k, isShiftKeyDown()));
} else {
filler.patternParameters[i] = filler.currentPattern.createParameter(i);
}
filler.rpcSetParameter(i, filler.patternParameters[i]);
}
}
}
Aggregations