use of buildcraft.api.statements.IStatement in project BuildCraft by BuildCraft.
the class GuiElementStatement method onMouseClicked.
// IInteractionElement
@Override
public void onMouseClicked(int button) {
if (!contains(gui.mouse)) {
return;
}
if (ref.canInteract && button == 0) {
if (GuiScreen.isShiftKeyDown()) {
set(null);
return;
}
S s = get();
if (s == null) {
return;
}
List<IStatement> possible = new ArrayList<>();
Collections.addAll(possible, s.getPossible());
if (!s.isPossibleOrdered()) {
List<IStatement> list = new ArrayList<>();
list.add(null);
for (IStatement p2 : possible) {
if (p2 != null) {
list.add(p2);
}
}
possible = list;
}
if (ctx != null) {
possible.removeIf(f -> {
for (StatementGroup<?> group : ctx.getAllPossible()) {
if (group.getValues().contains(f)) {
return false;
}
}
return true;
});
}
gui.currentMenu = GuiElementStatementVariant.create(gui, this, this, possible.toArray(new IStatement[0]));
}
}
use of buildcraft.api.statements.IStatement in project BuildCraft by BuildCraft.
the class GuiElementStatementParam method drawBackground.
// IGuiElement
@Override
public void drawBackground(float partialTicks) {
if (draw) {
IStatement slot = ref.get();
int max = slot == null ? 0 : slot.maxParameters();
double x = getX();
double y = getY();
if (paramIndex >= max) {
GuiElementStatement.SLOT_COLOUR.drawAt(x, y);
GuiElementStatement.ICON_SLOT_BLOCKED.drawAt(x, y);
return;
}
IStatementParameter statementParameter = get();
GuiElementStatementSource.drawGuiSlot(statementParameter, x, y);
}
}
use of buildcraft.api.statements.IStatement in project BuildCraft by BuildCraft.
the class ActionType method readFromBuffer.
@Override
public ActionWrapper readFromBuffer(PacketBufferBC buffer) throws IOException {
if (buffer.readBoolean()) {
String name = buffer.readString();
EnumPipePart part = buffer.readEnumValue(EnumPipePart.class);
IStatement statement = StatementManager.statements.get(name);
if (statement instanceof IAction) {
return ActionWrapper.wrap(statement, part.face);
} else {
throw new InvalidInputDataException("Unknown action '" + name + "'");
}
} else {
return null;
}
}
use of buildcraft.api.statements.IStatement in project BuildCraft by BuildCraft.
the class TriggerType method readFromBuffer.
@Override
public TriggerWrapper readFromBuffer(PacketBufferBC buffer) throws IOException {
if (buffer.readBoolean()) {
String name = buffer.readString();
EnumPipePart part = buffer.readEnumValue(EnumPipePart.class);
IStatement statement = StatementManager.statements.get(name);
if (statement instanceof ITrigger) {
return TriggerWrapper.wrap(statement, part.face);
} else {
throw new InvalidInputDataException("Unknown trigger '" + name + "'");
}
} else {
return null;
}
}
use of buildcraft.api.statements.IStatement in project BuildCraft by BuildCraft.
the class ContainerGateInterface method receiveCommand.
@Override
public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
if (side.isServer()) {
EntityPlayer player = (EntityPlayer) sender;
if ("initRequest".equals(command)) {
final String[] triggerStrings = statementsToStrings(potentialTriggers);
final String[] actionStrings = statementsToStrings(potentialActions);
BuildCraftCore.instance.sendToPlayer(player, new PacketCommand(this, "init", new CommandWriter() {
@Override
public void write(ByteBuf data) {
data.writeByte(gate.getDirection().ordinal());
data.writeShort(triggerStrings.length);
data.writeShort(actionStrings.length);
for (String trigger : triggerStrings) {
NetworkUtils.writeUTF(data, trigger);
}
for (String action : actionStrings) {
NetworkUtils.writeUTF(data, action);
}
}
}));
} else if ("selectionRequest".equals(command)) {
for (int position = 0; position < gate.material.numSlots; position++) {
IStatement action = gate.getAction(position);
IStatement trigger = gate.getTrigger(position);
BuildCraftCore.instance.sendToPlayer(player, getStatementPacket("setAction", position, action));
BuildCraftCore.instance.sendToPlayer(player, getStatementPacket("setTrigger", position, trigger));
for (int p = 0; p < gate.material.numActionParameters; ++p) {
BuildCraftCore.instance.sendToPlayer(player, getStatementParameterPacket("setActionParameter", position, p, gate.getActionParameter(position, p)));
}
for (int q = 0; q < gate.material.numTriggerParameters; ++q) {
BuildCraftCore.instance.sendToPlayer(player, getStatementParameterPacket("setTriggerParameter", position, q, gate.getTriggerParameter(position, q)));
}
}
}
} else if (side.isClient()) {
if ("init".equals(command)) {
setGate(stream.readByte());
String[] triggerStrings = new String[stream.readShort()];
String[] actionStrings = new String[stream.readShort()];
for (int i = 0; i < triggerStrings.length; i++) {
triggerStrings[i] = NetworkUtils.readUTF(stream);
}
for (int i = 0; i < actionStrings.length; i++) {
actionStrings[i] = NetworkUtils.readUTF(stream);
}
stringsToStatements(this.potentialTriggers, triggerStrings);
stringsToStatements(this.potentialActions, actionStrings);
}
}
if ("setAction".equals(command)) {
setAction(stream.readUnsignedByte(), NetworkUtils.readUTF(stream), false);
} else if ("setTrigger".equals(command)) {
setTrigger(stream.readUnsignedByte(), NetworkUtils.readUTF(stream), false);
} else if ("setActionParameter".equals(command) || "setTriggerParameter".equals(command)) {
int slot = stream.readUnsignedByte();
int param = stream.readUnsignedByte();
String parameterName = NetworkUtils.readUTF(stream);
NBTTagCompound parameterData = NetworkUtils.readNBT(stream);
IStatementParameter parameter = null;
if (parameterName != null && parameterName.length() > 0) {
parameter = StatementManager.createParameter(parameterName);
}
if (parameter != null) {
parameter.readFromNBT(parameterData);
if ("setActionParameter".equals(command)) {
setActionParameter(slot, param, parameter, false);
} else {
setTriggerParameter(slot, param, parameter, false);
}
}
}
}
Aggregations