use of buildcraft.api.statements.IStatement in project BuildCraft by BuildCraft.
the class ContainerGateInterface method setTrigger.
public void setTrigger(int trigger, String tag, boolean notifyServer) {
if (gate == null) {
return;
}
IStatement statement = null;
if (tag != null && tag.length() > 0) {
statement = StatementManager.statements.get(tag);
}
gate.setTrigger(trigger, statement);
if (pipe.getTile().getWorldBC().isRemote && notifyServer) {
BuildCraftCore.instance.sendToServer(getStatementPacket("setTrigger", trigger, statement));
}
}
use of buildcraft.api.statements.IStatement in project BuildCraft by BuildCraft.
the class ContainerGateInterface method init.
public void init() {
if (gate == null) {
return;
}
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 9; x++) {
getSlot(x + y * 9).yDisplayPosition = gate.material.guiHeight - 84 + y * 18;
}
}
for (int x = 0; x < 9; x++) {
getSlot(x + 27).yDisplayPosition = gate.material.guiHeight - 26;
}
// the client.
if (!pipe.getTile().getWorldBC().isRemote) {
potentialTriggers.addAll(gate.getAllValidTriggers());
potentialActions.addAll(gate.getAllValidActions());
Iterator<IStatement> it = potentialTriggers.iterator();
while (it.hasNext()) {
IStatement trigger = it.next();
if (trigger.minParameters() > gate.material.numTriggerParameters) {
it.remove();
}
}
it = potentialActions.iterator();
while (it.hasNext()) {
IStatement action = it.next();
if (action.minParameters() > gate.material.numActionParameters) {
it.remove();
}
}
}
if (gateCallback != null) {
gateCallback.setGate(gate);
}
}
use of buildcraft.api.statements.IStatement in project BuildCraft by BuildCraft.
the class ContainerGateInterface method setAction.
public void setAction(int action, String tag, boolean notifyServer) {
if (gate == null) {
return;
}
IStatement statement = null;
if (tag != null && tag.length() > 0) {
statement = StatementManager.statements.get(tag);
}
gate.setAction(action, statement);
if (pipe.getTile().getWorldBC().isRemote && notifyServer) {
BuildCraftCore.instance.sendToServer(getStatementPacket("setAction", action, statement));
}
}
use of buildcraft.api.statements.IStatement 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.IStatement in project BuildCraft by BuildCraft.
the class GuiGateInterface method drawGuiContainerBackgroundLayer.
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
container.synchronize();
if (gate == null) {
return;
}
ResourceLocation texture = container.getGateGuiFile();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(texture);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
for (AdvancedSlot slot : slots) {
if (slot instanceof TriggerSlot) {
boolean halfWidth = container.actionsState[((TriggerSlot) slot).slot] == ActionActiveState.Partial;
if (container.actionsState[((TriggerSlot) slot).slot] != ActionActiveState.Deactivated) {
mc.renderEngine.bindTexture(texture);
drawTexturedModalRect(guiLeft + slot.x + 17 + 18 * gate.material.numTriggerParameters, guiTop + slot.y + 6, 176, 18, halfWidth ? 9 : 18, 4);
}
} else if (slot instanceof StatementParameterSlot) {
StatementParameterSlot paramSlot = (StatementParameterSlot) slot;
StatementSlot statement = paramSlot.statementSlot;
mc.renderEngine.bindTexture(texture);
if (statement.isDefined()) {
if (!paramSlot.isAllowed()) {
drawTexturedModalRect(guiLeft + slot.x - 1, guiTop + slot.y - 1, 176, 0, 18, 18);
} else if (paramSlot.isRequired() && paramSlot.getParameter() == null) {
drawTexturedModalRect(guiLeft + slot.x - 1, guiTop + slot.y - 1, 176, 22, 18, 18);
}
} else {
drawTexturedModalRect(guiLeft + slot.x - 1, guiTop + slot.y - 1, 176, 0, 18, 18);
}
}
}
drawBackgroundSlots(x, y);
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
// Make sure that render states are reset, an ItemStack can derp them up.
GL11.glDisable(GL11.GL_LIGHTING);
GlStateManager.disableLighting();
GL11.glEnable(GL11.GL_ALPHA_TEST);
GlStateManager.enableAlpha();
GL11.glEnable(GL11.GL_BLEND);
GlStateManager.enableBlend();
tooltip = null;
int sX = 18;
int sY = OPTION_TRIGGERS_Y.getAsInt();
int width = OPTION_TRIGGERS_WIDE.getAsInt() * 18;
triggerRows = 1;
for (IStatement statement : container.getTriggerCollection(false)) {
int pX = this.guiLeft - sX;
int pY = this.guiTop + sY;
if (x > pX & x < pX + 16 && y > pY && y < pY + 16) {
String desc = statement.getDescription();
tooltip = I18n.format(desc);
}
drawStatement(pX, pY, statement);
if (sX >= width) {
sX = 18;
sY += 18;
triggerRows++;
} else {
sX += 18;
lastTriggerRowSize = sX;
}
}
width = OPTION_ACTIONS_WIDE.getAsInt() * 18;
sX = 0;
sY = OPTION_ACTIONS_Y.getAsInt();
actionRows = 1;
for (IStatement statement : container.getActionCollection(false)) {
int pX = this.guiLeft + this.xSize() + sX;
int pY = this.guiTop + sY;
drawStatement(pX, pY, statement);
if (x > pX & x < pX + 16 && y > pY && y < pY + 16) {
String desc = statement.getDescription();
tooltip = I18n.format(desc);
}
if (sX >= width - 18) {
sX = 0;
sY += 18;
actionRows++;
} else {
sX += 18;
lastActionRowSize = sX;
}
}
if (index != -1) {
Collection<IStatement> collect;
if (trigger)
collect = container.getTriggerCollection(false);
else
collect = container.getActionCollection(false);
IStatement state = null;
int i = index;
Iterator<IStatement> it = collect.iterator();
while (i >= 0) {
state = it.next();
i--;
}
AdvancedSlot hoverSlot = getSlotAtLocation(x, y);
boolean isValid = (trigger && hoverSlot instanceof TriggerSlot) || (!trigger && hoverSlot instanceof ActionSlot);
if (!isValid) {
GlStateManager.color(0.95f, 0.6f, 0.6f);
}
drawStatement(x - 8, y - 8, state);
GlStateManager.color(1.0f, 1.0f, 1.0f);
}
GlStateManager.enableLighting();
GlStateManager.disableAlpha();
GlStateManager.disableBlend();
}
Aggregations