use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class GuiProgrammer method generateRelativeOperators.
/**
*
* @param baseWidget
* @param simulate
* @return true if successful
*/
private boolean generateRelativeOperators(ProgWidgetCoordinateOperator baseWidget, List<String> tooltip, boolean simulate) {
ChunkPosition baseCoord = ProgWidgetCoordinateOperator.calculateCoordinate(baseWidget, 0, baseWidget.getOperator());
Map<ChunkPosition, String> offsetToVariableNames = new HashMap<ChunkPosition, String>();
for (IProgWidget widget : te.progWidgets) {
if (widget instanceof ProgWidgetArea) {
ProgWidgetArea area = (ProgWidgetArea) widget;
if (area.getCoord1Variable().equals("") && (area.x1 != 0 || area.y1 != 0 || area.z1 != 0)) {
ChunkPosition offset = new ChunkPosition(area.x1 - baseCoord.chunkPosX, area.y1 - baseCoord.chunkPosY, area.z1 - baseCoord.chunkPosZ);
String var = getOffsetVariable(offsetToVariableNames, baseWidget.getVariable(), offset);
if (!simulate)
area.setCoord1Variable(var);
}
if (area.getCoord2Variable().equals("") && (area.x2 != 0 || area.y2 != 0 || area.z2 != 0)) {
ChunkPosition offset = new ChunkPosition(area.x2 - baseCoord.chunkPosX, area.y2 - baseCoord.chunkPosY, area.z2 - baseCoord.chunkPosZ);
String var = getOffsetVariable(offsetToVariableNames, baseWidget.getVariable(), offset);
if (!simulate)
area.setCoord2Variable(var);
}
} else if (widget instanceof ProgWidgetCoordinate && baseWidget.getConnectedParameters()[0] != widget) {
ProgWidgetCoordinate coordinate = (ProgWidgetCoordinate) widget;
if (!coordinate.isUsingVariable()) {
ChunkPosition c = coordinate.getCoordinate();
String chunkString = "(" + c.chunkPosX + ", " + c.chunkPosY + ", " + c.chunkPosZ + ")";
if (PneumaticCraftUtils.distBetween(c, 0, 0, 0) < 64) {
//When the coordinate value is close to 0, there's a low chance it means a position, and rather an offset.
if (tooltip != null)
tooltip.add(I18n.format("gui.programmer.button.convertToRelative.coordIsNotChangedWarning", chunkString));
} else {
if (tooltip != null)
tooltip.add(I18n.format("gui.programmer.button.convertToRelative.coordIsChangedWarning", chunkString));
if (!simulate) {
ChunkPosition offset = new ChunkPosition(c.chunkPosX - baseCoord.chunkPosX, c.chunkPosY - baseCoord.chunkPosY, c.chunkPosZ - baseCoord.chunkPosZ);
String var = getOffsetVariable(offsetToVariableNames, baseWidget.getVariable(), offset);
if (!simulate) {
coordinate.setVariable(var);
coordinate.setUsingVariable(true);
}
}
}
}
}
}
if (offsetToVariableNames.size() > 0) {
ProgWidgetCoordinateOperator firstOperator = null;
ProgWidgetCoordinateOperator prevOperator = baseWidget;
int x = baseWidget.getX();
for (Map.Entry<ChunkPosition, String> entry : offsetToVariableNames.entrySet()) {
ProgWidgetCoordinateOperator operator = new ProgWidgetCoordinateOperator();
operator.setVariable(entry.getValue());
int y = prevOperator.getY() + prevOperator.getHeight() / 2;
operator.setX(x);
operator.setY(y);
if (!isValidPlaced(operator))
return false;
ProgWidgetCoordinate coordinatePiece1 = new ProgWidgetCoordinate();
coordinatePiece1.setX(x + prevOperator.getWidth() / 2);
coordinatePiece1.setY(y);
coordinatePiece1.setVariable(baseWidget.getVariable());
coordinatePiece1.setUsingVariable(true);
if (!isValidPlaced(coordinatePiece1))
return false;
ProgWidgetCoordinate coordinatePiece2 = new ProgWidgetCoordinate();
coordinatePiece2.setX(x + prevOperator.getWidth() / 2 + coordinatePiece1.getWidth() / 2);
coordinatePiece2.setY(y);
coordinatePiece2.setCoordinate(entry.getKey());
if (!isValidPlaced(coordinatePiece2))
return false;
if (!simulate) {
te.progWidgets.add(operator);
te.progWidgets.add(coordinatePiece1);
te.progWidgets.add(coordinatePiece2);
}
if (firstOperator == null)
firstOperator = operator;
prevOperator = operator;
}
if (!simulate) {
NetworkHandler.sendToServer(new PacketProgrammerUpdate(te));
TileEntityProgrammer.updatePuzzleConnections(te.progWidgets);
}
return true;
} else {
//When there's nothing to place there's always room.
return true;
}
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class GuiProgrammer method getOffsetVariable.
private String getOffsetVariable(Map<ChunkPosition, String> offsetToVariableNames, String baseVariable, ChunkPosition offset) {
if (offset.equals(new ChunkPosition(0, 0, 0)))
return baseVariable;
String var = offsetToVariableNames.get(offset);
if (var == null) {
var = "var" + (offsetToVariableNames.size() + 1);
offsetToVariableNames.put(offset, var);
}
return var;
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class GuiDroneDebuggerOptions method drawScreen.
@Override
public void drawScreen(int x, int y, float partialTicks) {
if (selectedDrone != null) {
Minecraft.getMinecraft().fontRenderer.drawString("Drone name: " + selectedDrone.getCommandSenderName(), 20, screenHeight - 15, 0xFFFFFFFF, true);
Minecraft.getMinecraft().fontRenderer.drawString("Routine: " + selectedDrone.getLabel(), screenWidth / 2, screenHeight - 15, 0xFFFFFFFF, true);
}
programmerUnit.render(x, y, true, true, true);
programmerUnit.renderForeground(x, y, null);
if (selectedDrone == null) {
drawCenteredString(Minecraft.getMinecraft().fontRenderer, "Press '" + Keyboard.getKeyName(KeyHandler.getInstance().keybindDebuggingDrone.getKeyCode()) + "' on a Drone when tracked by an Entity Tracker to debug the Drone.", screenWidth / 2, screenHeight / 2, 0xFFFF0000);
}
IProgWidget widget = programmerUnit.getHoveredWidget(x, y);
if (widget == null)
widget = areaShowingWidget;
upgradeHandler.getShowingPositions().clear();
if (widget != null) {
int widgetId = selectedDrone.getProgWidgets().indexOf(widget);
for (DebugEntry entry : selectedDrone.getDebugEntries()) {
if (entry.getProgWidgetId() == widgetId && !entry.getPos().equals(new ChunkPosition(0, 0, 0))) {
upgradeHandler.getShowingPositions().add(entry.getPos());
}
}
}
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class GuiProgWidgetCoordinate method initGui.
@Override
public void initGui() {
super.initGui();
if (invSearchGui != null) {
ChunkPosition pos = invSearchGui.getSearchStack() != null ? ItemGPSTool.getGPSLocation(invSearchGui.getSearchStack()) : null;
widget.setCoordinate(pos);
}
List<GuiRadioButton> radioButtons = new ArrayList<GuiRadioButton>();
GuiRadioButton radioButton = new GuiRadioButton(0, guiLeft + 7, guiTop + 51, 0xFF000000, I18n.format("gui.progWidget.coordinate.constant"));
if (!widget.isUsingVariable())
radioButton.checked = true;
radioButtons.add(radioButton);
radioButton.otherChoices = radioButtons;
addWidget(radioButton);
radioButton = new GuiRadioButton(1, guiLeft + 7, guiTop + 100, 0xFF000000, I18n.format("gui.progWidget.coordinate.variable"));
if (widget.isUsingVariable())
radioButton.checked = true;
radioButtons.add(radioButton);
radioButton.otherChoices = radioButtons;
addWidget(radioButton);
gpsButton = new GuiButtonSpecial(0, guiLeft + 100, guiTop + 20, 20, 20, "");
gpsButton.setRenderStacks(new ItemStack[] { new ItemStack(Itemss.GPSTool) });
gpsButton.setTooltipText(I18n.format("gui.progWidget.coordinate.selectFromGPS"));
gpsButton.enabled = !widget.isUsingVariable();
buttonList.add(gpsButton);
coordFields = new WidgetTextFieldNumber[3];
for (int i = 0; i < 3; i++) {
coordFields[i] = new WidgetTextFieldNumber(fontRendererObj, guiLeft + 100, guiTop + 50 + 13 * i, 40, fontRendererObj.FONT_HEIGHT + 1);
addWidget(coordFields[i]);
coordFields[i].setEnabled(gpsButton.enabled);
}
coordFields[0].setValue(widget.getRawCoordinate().chunkPosX);
coordFields[1].setValue(widget.getRawCoordinate().chunkPosY);
coordFields[2].setValue(widget.getRawCoordinate().chunkPosZ);
variableField = new WidgetComboBox(fontRendererObj, guiLeft + 90, guiTop + 112, 80, fontRendererObj.FONT_HEIGHT + 1);
variableField.setElements(guiProgrammer.te.getAllVariables());
addWidget(variableField);
variableField.setText(widget.getVariable());
variableField.setEnabled(widget.isUsingVariable());
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class GuiProgWidgetCoordinate method actionPerformed.
@Override
public void actionPerformed(GuiButton button) {
if (button.id == 0) {
invSearchGui = new GuiInventorySearcher(FMLClientHandler.instance().getClient().thePlayer);
ChunkPosition area = widget.getRawCoordinate();
ItemStack gps = new ItemStack(Itemss.GPSTool);
ItemGPSTool.setGPSLocation(gps, area.chunkPosX, area.chunkPosY, area.chunkPosZ);
invSearchGui.setSearchStack(ItemGPSTool.getGPSLocation(gps) != null ? gps : null);
FMLClientHandler.instance().showGuiScreen(invSearchGui);
}
super.actionPerformed(button);
}
Aggregations