| 1 | package net.minecraft.client.gui.screens.inventory;
|
| 2 |
|
| 3 | import com.google.common.collect.ImmutableList;
|
| 4 | import java.text.DecimalFormat;
|
| 5 | import java.text.DecimalFormatSymbols;
|
| 6 | import java.util.Locale;
|
| 7 | import net.fabricmc.api.EnvType;
|
| 8 | import net.fabricmc.api.Environment;
|
| 9 | import net.minecraft.client.gui.GuiGraphicsExtractor;
|
| 10 | import net.minecraft.client.gui.components.Button;
|
| 11 | import net.minecraft.client.gui.components.CycleButton;
|
| 12 | import net.minecraft.client.gui.components.EditBox;
|
| 13 | import net.minecraft.client.gui.screens.Screen;
|
| 14 | import net.minecraft.client.input.CharacterEvent;
|
| 15 | import net.minecraft.client.input.KeyEvent;
|
| 16 | import net.minecraft.core.BlockPos;
|
| 17 | import net.minecraft.core.Vec3i;
|
| 18 | import net.minecraft.network.chat.CommonComponents;
|
| 19 | import net.minecraft.network.chat.Component;
|
| 20 | import net.minecraft.network.protocol.game.ServerboundSetStructureBlockPacket;
|
| 21 | import net.minecraft.world.level.block.Blocks;
|
| 22 | import net.minecraft.world.level.block.Mirror;
|
| 23 | import net.minecraft.world.level.block.Rotation;
|
| 24 | import net.minecraft.world.level.block.entity.StructureBlockEntity;
|
| 25 | import net.minecraft.world.level.block.entity.StructureBlockEntity.UpdateType;
|
| 26 | import net.minecraft.world.level.block.state.properties.StructureMode;
|
| 27 |
|
| 28 | @Environment(EnvType.CLIENT)
|
| 29 | public class StructureBlockEditScreen extends Screen {
|
| 30 | private static final Component NAME_LABEL = Component.translatable("structure_block.structure_name");
|
| 31 | private static final Component POSITION_LABEL = Component.translatable("structure_block.position");
|
| 32 | private static final Component SIZE_LABEL = Component.translatable("structure_block.size");
|
| 33 | private static final Component INTEGRITY_LABEL = Component.translatable("structure_block.integrity");
|
| 34 | private static final Component CUSTOM_DATA_LABEL = Component.translatable("structure_block.custom_data");
|
| 35 | private static final Component INCLUDE_ENTITIES_LABEL = Component.translatable("structure_block.include_entities");
|
| 36 | private static final Component STRICT_LABEL = Component.translatable("structure_block.strict");
|
| 37 | private static final Component DETECT_SIZE_LABEL = Component.translatable("structure_block.detect_size");
|
| 38 | private static final Component SHOW_AIR_LABEL = Component.translatable("structure_block.show_air");
|
| 39 | private static final Component SHOW_BOUNDING_BOX_LABEL = Component.translatable("structure_block.show_boundingbox");
|
| 40 | private static final ImmutableList<StructureMode> ALL_MODES = ImmutableList.copyOf(StructureMode.values());
|
| 41 | private static final ImmutableList<StructureMode> DEFAULT_MODES = ALL_MODES.stream()
|
| 42 | .filter(m -> m != StructureMode.DATA)
|
| 43 | .collect(ImmutableList.toImmutableList());
|
| 44 | private final StructureBlockEntity structure;
|
| 45 | private Mirror initialMirror = Mirror.NONE;
|
| 46 | private Rotation initialRotation = Rotation.NONE;
|
| 47 | private StructureMode initialMode = StructureMode.DATA;
|
| 48 | private boolean initialEntityIgnoring;
|
| 49 | private boolean initialStrict;
|
| 50 | private boolean initialShowAir;
|
| 51 | private boolean initialShowBoundingBox;
|
| 52 | private EditBox nameEdit;
|
| 53 | private EditBox posXEdit;
|
| 54 | private EditBox posYEdit;
|
| 55 | private EditBox posZEdit;
|
| 56 | private EditBox sizeXEdit;
|
| 57 | private EditBox sizeYEdit;
|
| 58 | private EditBox sizeZEdit;
|
| 59 | private EditBox integrityEdit;
|
| 60 | private EditBox seedEdit;
|
| 61 | private EditBox dataEdit;
|
| 62 | private Button saveButton;
|
| 63 | private Button loadButton;
|
| 64 | private Button rot0Button;
|
| 65 | private Button rot90Button;
|
| 66 | private Button rot180Button;
|
| 67 | private Button rot270Button;
|
| 68 | private Button detectButton;
|
| 69 | private CycleButton<Boolean> includeEntitiesButton;
|
| 70 | private CycleButton<Boolean> strictButton;
|
| 71 | private CycleButton<Mirror> mirrorButton;
|
| 72 | private CycleButton<Boolean> toggleAirButton;
|
| 73 | private CycleButton<Boolean> toggleBoundingBox;
|
| 74 | private final DecimalFormat decimalFormat = new DecimalFormat("0.0###", DecimalFormatSymbols.getInstance(Locale.ROOT));
|
| 75 |
|
| 76 | public StructureBlockEditScreen(final StructureBlockEntity structure) {
|
| 77 | super(Component.translatable(Blocks.STRUCTURE_BLOCK.getDescriptionId()));
|
| 78 | this.structure = structure;
|
| 79 | }
|
| 80 |
|
| 81 | private void onDone() {
|
| 82 | if (this.sendToServer(UpdateType.UPDATE_DATA)) {
|
| 83 | this.minecraft.gui.setScreen(null);
|
| 84 | }
|
| 85 | }
|
| 86 |
|
| 87 | private void onCancel() {
|
| 88 | this.structure.setMirror(this.initialMirror);
|
| 89 | this.structure.setRotation(this.initialRotation);
|
| 90 | this.structure.setMode(this.initialMode);
|
| 91 | this.structure.setIgnoreEntities(this.initialEntityIgnoring);
|
| 92 | this.structure.setStrict(this.initialStrict);
|
| 93 | this.structure.setShowAir(this.initialShowAir);
|
| 94 | this.structure.setShowBoundingBox(this.initialShowBoundingBox);
|
| 95 | this.minecraft.gui.setScreen(null);
|
| 96 | }
|
| 97 |
|
| 98 | @Override
|
| 99 | protected void init() {
|
| 100 | this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, button -> this.onDone()).bounds(this.width / 2 - 4 - 150, 210, 150, 20).build());
|
| 101 | this.addRenderableWidget(Button.builder(CommonComponents.GUI_CANCEL, button -> this.onCancel()).bounds(this.width / 2 + 4, 210, 150, 20).build());
|
| 102 | this.initialMirror = this.structure.getMirror();
|
| 103 | this.initialRotation = this.structure.getRotation();
|
| 104 | this.initialMode = this.structure.getMode();
|
| 105 | this.initialEntityIgnoring = this.structure.isIgnoreEntities();
|
| 106 | this.initialStrict = this.structure.isStrict();
|
| 107 | this.initialShowAir = this.structure.getShowAir();
|
| 108 | this.initialShowBoundingBox = this.structure.getShowBoundingBox();
|
| 109 | this.saveButton = this.addRenderableWidget(Button.builder(Component.translatable("structure_block.button.save"), button -> {
|
| 110 | if (this.structure.getMode() == StructureMode.SAVE) {
|
| 111 | this.sendToServer(UpdateType.SAVE_AREA);
|
| 112 | this.minecraft.gui.setScreen(null);
|
| 113 | }
|
| 114 | }).bounds(this.width / 2 + 4 + 100, 185, 50, 20).build());
|
| 115 | this.loadButton = this.addRenderableWidget(Button.builder(Component.translatable("structure_block.button.load"), button -> {
|
| 116 | if (this.structure.getMode() == StructureMode.LOAD) {
|
| 117 | this.sendToServer(UpdateType.LOAD_AREA);
|
| 118 | this.minecraft.gui.setScreen(null);
|
| 119 | }
|
| 120 | }).bounds(this.width / 2 + 4 + 100, 185, 50, 20).build());
|
| 121 | this.addRenderableWidget(
|
| 122 | CycleButton.<StructureMode>builder(value -> Component.translatable("structure_block.mode." + value.getSerializedName()), this.initialMode)
|
| 123 | .withValues(DEFAULT_MODES, ALL_MODES)
|
| 124 | .displayOnlyValue()
|
| 125 | .create(this.width / 2 - 4 - 150, 185, 50, 20, Component.literal("MODE"), (button, value) -> {
|
| 126 | this.structure.setMode(value);
|
| 127 | this.updateMode(value);
|
| 128 | })
|
| 129 | );
|
| 130 | this.detectButton = this.addRenderableWidget(Button.builder(Component.translatable("structure_block.button.detect_size"), button -> {
|
| 131 | if (this.structure.getMode() == StructureMode.SAVE) {
|
| 132 | this.sendToServer(UpdateType.SCAN_AREA);
|
| 133 | this.minecraft.gui.setScreen(null);
|
| 134 | }
|
| 135 | }).bounds(this.width / 2 + 4 + 100, 120, 50, 20).build());
|
| 136 | this.includeEntitiesButton = this.addRenderableWidget(
|
| 137 | CycleButton.onOffBuilder(!this.structure.isIgnoreEntities())
|
| 138 | .displayOnlyValue()
|
| 139 | .create(this.width / 2 + 4 + 100, 160, 50, 20, INCLUDE_ENTITIES_LABEL, (button, value) -> this.structure.setIgnoreEntities(!value))
|
| 140 | );
|
| 141 | this.strictButton = this.addRenderableWidget(
|
| 142 | CycleButton.onOffBuilder(this.structure.isStrict())
|
| 143 | .displayOnlyValue()
|
| 144 | .create(this.width / 2 + 4 + 100, 120, 50, 20, STRICT_LABEL, (button, value) -> this.structure.setStrict(value))
|
| 145 | );
|
| 146 | this.mirrorButton = this.addRenderableWidget(
|
| 147 | CycleButton.builder(Mirror::symbol, this.initialMirror)
|
| 148 | .withValues(Mirror.values())
|
| 149 | .displayOnlyValue()
|
| 150 | .create(this.width / 2 - 20, 185, 40, 20, Component.literal("MIRROR"), (button, value) -> this.structure.setMirror(value))
|
| 151 | );
|
| 152 | this.toggleAirButton = this.addRenderableWidget(
|
| 153 | CycleButton.onOffBuilder(this.structure.getShowAir())
|
| 154 | .displayOnlyValue()
|
| 155 | .create(this.width / 2 + 4 + 100, 80, 50, 20, SHOW_AIR_LABEL, (button, value) -> this.structure.setShowAir(value))
|
| 156 | );
|
| 157 | this.toggleBoundingBox = this.addRenderableWidget(
|
| 158 | CycleButton.onOffBuilder(this.structure.getShowBoundingBox())
|
| 159 | .displayOnlyValue()
|
| 160 | .create(this.width / 2 + 4 + 100, 80, 50, 20, SHOW_BOUNDING_BOX_LABEL, (button, value) -> this.structure.setShowBoundingBox(value))
|
| 161 | );
|
| 162 | this.rot0Button = this.addRenderableWidget(Button.builder(Component.literal("0"), button -> {
|
| 163 | this.structure.setRotation(Rotation.NONE);
|
| 164 | this.updateDirectionButtons();
|
| 165 | }).bounds(this.width / 2 - 1 - 40 - 1 - 40 - 20, 185, 40, 20).build());
|
| 166 | this.rot90Button = this.addRenderableWidget(Button.builder(Component.literal("90"), button -> {
|
| 167 | this.structure.setRotation(Rotation.CLOCKWISE_90);
|
| 168 | this.updateDirectionButtons();
|
| 169 | }).bounds(this.width / 2 - 1 - 40 - 20, 185, 40, 20).build());
|
| 170 | this.rot180Button = this.addRenderableWidget(Button.builder(Component.literal("180"), button -> {
|
| 171 | this.structure.setRotation(Rotation.CLOCKWISE_180);
|
| 172 | this.updateDirectionButtons();
|
| 173 | }).bounds(this.width / 2 + 1 + 20, 185, 40, 20).build());
|
| 174 | this.rot270Button = this.addRenderableWidget(Button.builder(Component.literal("270"), button -> {
|
| 175 | this.structure.setRotation(Rotation.COUNTERCLOCKWISE_90);
|
| 176 | this.updateDirectionButtons();
|
| 177 | }).bounds(this.width / 2 + 1 + 40 + 1 + 20, 185, 40, 20).build());
|
| 178 | this.nameEdit = new EditBox(this.font, this.width / 2 - 152, 40, 300, 20, Component.translatable("structure_block.structure_name")) {
|
| 179 | @Override
|
| 180 | public boolean charTyped(final CharacterEvent event) {
|
| 181 | return !StructureBlockEditScreen.this.isValidCharacterForName(this.getValue(), event.codepoint(), this.getCursorPosition())
|
| 182 | ? false
|
| 183 | : super.charTyped(event);
|
| 184 | }
|
| 185 | };
|
| 186 | this.nameEdit.setMaxLength(128);
|
| 187 | this.nameEdit.setValue(this.structure.getStructureName());
|
| 188 | this.addWidget(this.nameEdit);
|
| 189 | BlockPos minPos = this.structure.getStructurePos();
|
| 190 | this.posXEdit = new EditBox(this.font, this.width / 2 - 152, 80, 80, 20, Component.translatable("structure_block.position.x"));
|
| 191 | this.posXEdit.setMaxLength(15);
|
| 192 | this.posXEdit.setValue(Integer.toString(minPos.getX()));
|
| 193 | this.addWidget(this.posXEdit);
|
| 194 | this.posYEdit = new EditBox(this.font, this.width / 2 - 72, 80, 80, 20, Component.translatable("structure_block.position.y"));
|
| 195 | this.posYEdit.setMaxLength(15);
|
| 196 | this.posYEdit.setValue(Integer.toString(minPos.getY()));
|
| 197 | this.addWidget(this.posYEdit);
|
| 198 | this.posZEdit = new EditBox(this.font, this.width / 2 + 8, 80, 80, 20, Component.translatable("structure_block.position.z"));
|
| 199 | this.posZEdit.setMaxLength(15);
|
| 200 | this.posZEdit.setValue(Integer.toString(minPos.getZ()));
|
| 201 | this.addWidget(this.posZEdit);
|
| 202 | Vec3i maxPos = this.structure.getStructureSize();
|
| 203 | this.sizeXEdit = new EditBox(this.font, this.width / 2 - 152, 120, 80, 20, Component.translatable("structure_block.size.x"));
|
| 204 | this.sizeXEdit.setMaxLength(15);
|
| 205 | this.sizeXEdit.setValue(Integer.toString(maxPos.getX()));
|
| 206 | this.addWidget(this.sizeXEdit);
|
| 207 | this.sizeYEdit = new EditBox(this.font, this.width / 2 - 72, 120, 80, 20, Component.translatable("structure_block.size.y"));
|
| 208 | this.sizeYEdit.setMaxLength(15);
|
| 209 | this.sizeYEdit.setValue(Integer.toString(maxPos.getY()));
|
| 210 | this.addWidget(this.sizeYEdit);
|
| 211 | this.sizeZEdit = new EditBox(this.font, this.width / 2 + 8, 120, 80, 20, Component.translatable("structure_block.size.z"));
|
| 212 | this.sizeZEdit.setMaxLength(15);
|
| 213 | this.sizeZEdit.setValue(Integer.toString(maxPos.getZ()));
|
| 214 | this.addWidget(this.sizeZEdit);
|
| 215 | this.integrityEdit = new EditBox(this.font, this.width / 2 - 152, 120, 80, 20, Component.translatable("structure_block.integrity.integrity"));
|
| 216 | this.integrityEdit.setMaxLength(15);
|
| 217 | this.integrityEdit.setValue(this.decimalFormat.format(this.structure.getIntegrity()));
|
| 218 | this.addWidget(this.integrityEdit);
|
| 219 | this.seedEdit = new EditBox(this.font, this.width / 2 - 72, 120, 80, 20, Component.translatable("structure_block.integrity.seed"));
|
| 220 | this.seedEdit.setMaxLength(31);
|
| 221 | this.seedEdit.setValue(Long.toString(this.structure.getSeed()));
|
| 222 | this.addWidget(this.seedEdit);
|
| 223 | this.dataEdit = new EditBox(this.font, this.width / 2 - 152, 120, 240, 20, Component.translatable("structure_block.custom_data"));
|
| 224 | this.dataEdit.setMaxLength(128);
|
| 225 | this.dataEdit.setValue(this.structure.getMetaData());
|
| 226 | this.addWidget(this.dataEdit);
|
| 227 | this.updateDirectionButtons();
|
| 228 | this.updateMode(this.initialMode);
|
| 229 | }
|
| 230 |
|
| 231 | @Override
|
| 232 | protected void setInitialFocus() {
|
| 233 | this.setInitialFocus(this.nameEdit);
|
| 234 | }
|
| 235 |
|
| 236 | @Override
|
| 237 | public void resize(final int width, final int height) {
|
| 238 | String oldNameEdit = this.nameEdit.getValue();
|
| 239 | String oldPosXEdit = this.posXEdit.getValue();
|
| 240 | String oldPosYEdit = this.posYEdit.getValue();
|
| 241 | String oldPosZEdit = this.posZEdit.getValue();
|
| 242 | String oldSizeXEdit = this.sizeXEdit.getValue();
|
| 243 | String oldSizeYEdit = this.sizeYEdit.getValue();
|
| 244 | String oldSizeZEdit = this.sizeZEdit.getValue();
|
| 245 | String oldIntegrityEdit = this.integrityEdit.getValue();
|
| 246 | String oldSeedEdit = this.seedEdit.getValue();
|
| 247 | String oldDataEdit = this.dataEdit.getValue();
|
| 248 | this.init(width, height);
|
| 249 | this.nameEdit.setValue(oldNameEdit);
|
| 250 | this.posXEdit.setValue(oldPosXEdit);
|
| 251 | this.posYEdit.setValue(oldPosYEdit);
|
| 252 | this.posZEdit.setValue(oldPosZEdit);
|
| 253 | this.sizeXEdit.setValue(oldSizeXEdit);
|
| 254 | this.sizeYEdit.setValue(oldSizeYEdit);
|
| 255 | this.sizeZEdit.setValue(oldSizeZEdit);
|
| 256 | this.integrityEdit.setValue(oldIntegrityEdit);
|
| 257 | this.seedEdit.setValue(oldSeedEdit);
|
| 258 | this.dataEdit.setValue(oldDataEdit);
|
| 259 | }
|
| 260 |
|
| 261 | private void updateDirectionButtons() {
|
| 262 | this.rot0Button.active = true;
|
| 263 | this.rot90Button.active = true;
|
| 264 | this.rot180Button.active = true;
|
| 265 | this.rot270Button.active = true;
|
| 266 | switch (this.structure.getRotation()) {
|
| 267 | case NONE:
|
| 268 | this.rot0Button.active = false;
|
| 269 | break;
|
| 270 | case CLOCKWISE_180:
|
| 271 | this.rot180Button.active = false;
|
| 272 | break;
|
| 273 | case COUNTERCLOCKWISE_90:
|
| 274 | this.rot270Button.active = false;
|
| 275 | break;
|
| 276 | case CLOCKWISE_90:
|
| 277 | this.rot90Button.active = false;
|
| 278 | }
|
| 279 | }
|
| 280 |
|
| 281 | private void updateMode(final StructureMode mode) {
|
| 282 | this.nameEdit.setVisible(false);
|
| 283 | this.posXEdit.setVisible(false);
|
| 284 | this.posYEdit.setVisible(false);
|
| 285 | this.posZEdit.setVisible(false);
|
| 286 | this.sizeXEdit.setVisible(false);
|
| 287 | this.sizeYEdit.setVisible(false);
|
| 288 | this.sizeZEdit.setVisible(false);
|
| 289 | this.integrityEdit.setVisible(false);
|
| 290 | this.seedEdit.setVisible(false);
|
| 291 | this.dataEdit.setVisible(false);
|
| 292 | this.saveButton.visible = false;
|
| 293 | this.loadButton.visible = false;
|
| 294 | this.detectButton.visible = false;
|
| 295 | this.includeEntitiesButton.visible = false;
|
| 296 | this.strictButton.visible = false;
|
| 297 | this.mirrorButton.visible = false;
|
| 298 | this.rot0Button.visible = false;
|
| 299 | this.rot90Button.visible = false;
|
| 300 | this.rot180Button.visible = false;
|
| 301 | this.rot270Button.visible = false;
|
| 302 | this.toggleAirButton.visible = false;
|
| 303 | this.toggleBoundingBox.visible = false;
|
| 304 | switch (mode) {
|
| 305 | case SAVE:
|
| 306 | this.nameEdit.setVisible(true);
|
| 307 | this.posXEdit.setVisible(true);
|
| 308 | this.posYEdit.setVisible(true);
|
| 309 | this.posZEdit.setVisible(true);
|
| 310 | this.sizeXEdit.setVisible(true);
|
| 311 | this.sizeYEdit.setVisible(true);
|
| 312 | this.sizeZEdit.setVisible(true);
|
| 313 | this.saveButton.visible = true;
|
| 314 | this.detectButton.visible = true;
|
| 315 | this.includeEntitiesButton.visible = true;
|
| 316 | this.strictButton.visible = false;
|
| 317 | this.toggleAirButton.visible = true;
|
| 318 | break;
|
| 319 | case LOAD:
|
| 320 | this.nameEdit.setVisible(true);
|
| 321 | this.posXEdit.setVisible(true);
|
| 322 | this.posYEdit.setVisible(true);
|
| 323 | this.posZEdit.setVisible(true);
|
| 324 | this.integrityEdit.setVisible(true);
|
| 325 | this.seedEdit.setVisible(true);
|
| 326 | this.loadButton.visible = true;
|
| 327 | this.includeEntitiesButton.visible = true;
|
| 328 | this.strictButton.visible = true;
|
| 329 | this.mirrorButton.visible = true;
|
| 330 | this.rot0Button.visible = true;
|
| 331 | this.rot90Button.visible = true;
|
| 332 | this.rot180Button.visible = true;
|
| 333 | this.rot270Button.visible = true;
|
| 334 | this.toggleBoundingBox.visible = true;
|
| 335 | this.updateDirectionButtons();
|
| 336 | break;
|
| 337 | case CORNER:
|
| 338 | this.nameEdit.setVisible(true);
|
| 339 | break;
|
| 340 | case DATA:
|
| 341 | this.dataEdit.setVisible(true);
|
| 342 | }
|
| 343 | }
|
| 344 |
|
| 345 | private boolean sendToServer(final UpdateType updateType) {
|
| 346 | BlockPos offset = new BlockPos(
|
| 347 | this.parseCoordinate(this.posXEdit.getValue()), this.parseCoordinate(this.posYEdit.getValue()), this.parseCoordinate(this.posZEdit.getValue())
|
| 348 | );
|
| 349 | Vec3i size = new Vec3i(
|
| 350 | this.parseCoordinate(this.sizeXEdit.getValue()), this.parseCoordinate(this.sizeYEdit.getValue()), this.parseCoordinate(this.sizeZEdit.getValue())
|
| 351 | );
|
| 352 | float integrity = this.parseIntegrity(this.integrityEdit.getValue());
|
| 353 | long seed = this.parseSeed(this.seedEdit.getValue());
|
| 354 | this.minecraft
|
| 355 | .getConnection()
|
| 356 | .send(
|
| 357 | new ServerboundSetStructureBlockPacket(
|
| 358 | this.structure.getBlockPos(),
|
| 359 | updateType,
|
| 360 | this.structure.getMode(),
|
| 361 | this.nameEdit.getValue(),
|
| 362 | offset,
|
| 363 | size,
|
| 364 | this.structure.getMirror(),
|
| 365 | this.structure.getRotation(),
|
| 366 | this.dataEdit.getValue(),
|
| 367 | this.structure.isIgnoreEntities(),
|
| 368 | this.structure.isStrict(),
|
| 369 | this.structure.getShowAir(),
|
| 370 | this.structure.getShowBoundingBox(),
|
| 371 | integrity,
|
| 372 | seed
|
| 373 | )
|
| 374 | );
|
| 375 | return true;
|
| 376 | }
|
| 377 |
|
| 378 | private long parseSeed(final String value) {
|
| 379 | try {
|
| 380 | return Long.valueOf(value);
|
| 381 | } catch (NumberFormatException ignored) {
|
| 382 | return 0L;
|
| 383 | }
|
| 384 | }
|
| 385 |
|
| 386 | private float parseIntegrity(final String value) {
|
| 387 | try {
|
| 388 | return Float.valueOf(value);
|
| 389 | } catch (NumberFormatException ignored) {
|
| 390 | return 1.0F;
|
| 391 | }
|
| 392 | }
|
| 393 |
|
| 394 | private int parseCoordinate(final String value) {
|
| 395 | try {
|
| 396 | return Integer.parseInt(value);
|
| 397 | } catch (NumberFormatException ignored) {
|
| 398 | return 0;
|
| 399 | }
|
| 400 | }
|
| 401 |
|
| 402 | @Override
|
| 403 | public void onClose() {
|
| 404 | this.onCancel();
|
| 405 | }
|
| 406 |
|
| 407 | @Override
|
| 408 | public boolean keyPressed(final KeyEvent event) {
|
| 409 | if (super.keyPressed(event)) {
|
| 410 | return true;
|
| 411 | } else if (event.isConfirmation()) {
|
| 412 | this.onDone();
|
| 413 | return true;
|
| 414 | } else {
|
| 415 | return false;
|
| 416 | }
|
| 417 | }
|
| 418 |
|
| 419 | @Override
|
| 420 | public void extractRenderState(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a) {
|
| 421 | super.extractRenderState(graphics, mouseX, mouseY, a);
|
| 422 | StructureMode mode = this.structure.getMode();
|
| 423 | graphics.centeredText(this.font, this.title, this.width / 2, 10, -1);
|
| 424 | if (mode != StructureMode.DATA) {
|
| 425 | graphics.text(this.font, NAME_LABEL, this.width / 2 - 153, 30, -6250336);
|
| 426 | this.nameEdit.extractRenderState(graphics, mouseX, mouseY, a);
|
| 427 | }
|
| 428 |
|
| 429 | if (mode == StructureMode.LOAD || mode == StructureMode.SAVE) {
|
| 430 | graphics.text(this.font, POSITION_LABEL, this.width / 2 - 153, 70, -6250336);
|
| 431 | this.posXEdit.extractRenderState(graphics, mouseX, mouseY, a);
|
| 432 | this.posYEdit.extractRenderState(graphics, mouseX, mouseY, a);
|
| 433 | this.posZEdit.extractRenderState(graphics, mouseX, mouseY, a);
|
| 434 | graphics.text(this.font, INCLUDE_ENTITIES_LABEL, this.width / 2 + 154 - this.font.width(INCLUDE_ENTITIES_LABEL), 150, -6250336);
|
| 435 | }
|
| 436 |
|
| 437 | if (mode == StructureMode.SAVE) {
|
| 438 | graphics.text(this.font, SIZE_LABEL, this.width / 2 - 153, 110, -6250336);
|
| 439 | this.sizeXEdit.extractRenderState(graphics, mouseX, mouseY, a);
|
| 440 | this.sizeYEdit.extractRenderState(graphics, mouseX, mouseY, a);
|
| 441 | this.sizeZEdit.extractRenderState(graphics, mouseX, mouseY, a);
|
| 442 | graphics.text(this.font, DETECT_SIZE_LABEL, this.width / 2 + 154 - this.font.width(DETECT_SIZE_LABEL), 110, -6250336);
|
| 443 | graphics.text(this.font, SHOW_AIR_LABEL, this.width / 2 + 154 - this.font.width(SHOW_AIR_LABEL), 70, -6250336);
|
| 444 | }
|
| 445 |
|
| 446 | if (mode == StructureMode.LOAD) {
|
| 447 | graphics.text(this.font, INTEGRITY_LABEL, this.width / 2 - 153, 110, -6250336);
|
| 448 | this.integrityEdit.extractRenderState(graphics, mouseX, mouseY, a);
|
| 449 | this.seedEdit.extractRenderState(graphics, mouseX, mouseY, a);
|
| 450 | graphics.text(this.font, STRICT_LABEL, this.width / 2 + 154 - this.font.width(STRICT_LABEL), 110, -6250336);
|
| 451 | graphics.text(this.font, SHOW_BOUNDING_BOX_LABEL, this.width / 2 + 154 - this.font.width(SHOW_BOUNDING_BOX_LABEL), 70, -6250336);
|
| 452 | }
|
| 453 |
|
| 454 | if (mode == StructureMode.DATA) {
|
| 455 | graphics.text(this.font, CUSTOM_DATA_LABEL, this.width / 2 - 153, 110, -6250336);
|
| 456 | this.dataEdit.extractRenderState(graphics, mouseX, mouseY, a);
|
| 457 | }
|
| 458 |
|
| 459 | graphics.text(this.font, mode.getDisplayName(), this.width / 2 - 153, 174, -6250336);
|
| 460 | }
|
| 461 |
|
| 462 | @Override
|
| 463 | public boolean isInGameUi() {
|
| 464 | return true;
|
| 465 | }
|
| 466 | }
|
| 467 |
|