From 01a6d321401327c03473f2cb4cd56bb35f6230c3 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Mon, 15 Jul 2019 13:45:13 +0200 Subject: [PATCH] Blueprint Manual Coordinates - Added a Screen to input coordinates in order to bypass the placement tools --- .../create/gui/AbstractSimiScreen.java | 2 + .../create/gui/BlueprintEditScreen.java | 158 ++++++++++++++++++ .../com/simibubi/create/gui/GuiResources.java | 1 + .../simibubi/create/item/ItemBlueprint.java | 27 ++- .../create/schematic/BlueprintHandler.java | 25 ++- .../assets/create/textures/gui/schematic.png | Bin 0 -> 1809 bytes 6 files changed, 202 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/simibubi/create/gui/BlueprintEditScreen.java create mode 100644 src/main/resources/assets/create/textures/gui/schematic.png diff --git a/src/main/java/com/simibubi/create/gui/AbstractSimiScreen.java b/src/main/java/com/simibubi/create/gui/AbstractSimiScreen.java index 31ea5eb2b..56afd28f4 100644 --- a/src/main/java/com/simibubi/create/gui/AbstractSimiScreen.java +++ b/src/main/java/com/simibubi/create/gui/AbstractSimiScreen.java @@ -66,6 +66,8 @@ public abstract class AbstractSimiScreen extends Screen { if (widget.charTyped(character, code)) return true; } + if (character == 'e') + onClose(); return super.charTyped(character, code); } diff --git a/src/main/java/com/simibubi/create/gui/BlueprintEditScreen.java b/src/main/java/com/simibubi/create/gui/BlueprintEditScreen.java new file mode 100644 index 000000000..f735e28c3 --- /dev/null +++ b/src/main/java/com/simibubi/create/gui/BlueprintEditScreen.java @@ -0,0 +1,158 @@ +package com.simibubi.create.gui; + +import java.util.Collections; +import java.util.List; + +import com.google.common.collect.ImmutableList; +import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.AllItems; +import com.simibubi.create.gui.widgets.DynamicLabel; +import com.simibubi.create.gui.widgets.OptionScrollArea; +import com.simibubi.create.gui.widgets.ScrollArea; +import com.simibubi.create.schematic.BlueprintHandler; + +import net.minecraft.client.gui.widget.TextFieldWidget; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Mirror; +import net.minecraft.util.Rotation; +import net.minecraft.util.math.BlockPos; + +public class BlueprintEditScreen extends AbstractSimiScreen { + + private TextFieldWidget xInput; + private TextFieldWidget yInput; + private TextFieldWidget zInput; + + private static final List rotationOptions = ImmutableList.of("None", "Clockwise 90", "Clockwise 180", + "Clockwise 270"); + private static final List mirrorOptions = ImmutableList.of("None", "Left-Right", "Front-Back"); + + private ScrollArea rotationArea; + private ScrollArea mirrorArea; + + @Override + protected void init() { + setWindowSize(GuiResources.SCHEMATIC.width + 50, GuiResources.SCHEMATIC.height); + int x = topLeftX; + int y = topLeftY; + BlueprintHandler bh = BlueprintHandler.instance; + + xInput = new TextFieldWidget(font, x + 75, y + 32, 32, 10, ""); + yInput = new TextFieldWidget(font, x + 115, y + 32, 32, 10, ""); + zInput = new TextFieldWidget(font, x + 155, y + 32, 32, 10, ""); + + if (bh.deployed) { + xInput.setText("" + bh.anchor.getX()); + yInput.setText("" + bh.anchor.getY()); + zInput.setText("" + bh.anchor.getZ()); + } else { + BlockPos alt = minecraft.player.getPosition(); + xInput.setText("" + alt.getX()); + yInput.setText("" + alt.getY()); + zInput.setText("" + alt.getZ()); + } + + for (TextFieldWidget widget : new TextFieldWidget[] { xInput, yInput, zInput }) { + widget.setMaxStringLength(6); + widget.setEnableBackgroundDrawing(false); + widget.setTextColor(0xFFFFFF); + widget.changeFocus(false); + widget.mouseClicked(0, 0, 0); + widget.setValidator(s -> { + if (s.isEmpty() || s.equals("-")) + return true; + try { + Integer.parseInt(s); + return true; + } catch (NumberFormatException e) { + return false; + } + }); + } + + DynamicLabel labelR = new DynamicLabel(x + 99, y + 52, "").withShadow(); + rotationArea = new OptionScrollArea(x + 96, y + 49, 94, 14).forOptions(rotationOptions).titled("Rotation") + .setState(bh.cachedSettings.getRotation().ordinal()).writingTo(labelR); + + DynamicLabel labelM = new DynamicLabel(x + 99, y + 72, "").withShadow(); + mirrorArea = new OptionScrollArea(x + 96, y + 69, 94, 14).forOptions(mirrorOptions).titled("Mirror") + .setState(bh.cachedSettings.getMirror().ordinal()).writingTo(labelM); + + Collections.addAll(widgets, xInput, yInput, zInput); + Collections.addAll(widgets, labelR, labelM, rotationArea, mirrorArea); + + super.init(); + } + + @Override + public boolean keyPressed(int code, int p_keyPressed_2_, int p_keyPressed_3_) { + + if (isPaste(code)) { + String coords = minecraft.keyboardListener.getClipboardString(); + if (coords != null && !coords.isEmpty()) { + coords.replaceAll(" ", ""); + String[] split = coords.split(","); + if (split.length == 3) { + boolean valid = true; + for (String s : split) { + try { + Integer.parseInt(s); + } catch (NumberFormatException e) { + valid = false; + } + } + if (valid) { + xInput.setText(split[0]); + yInput.setText(split[1]); + zInput.setText(split[2]); + return true; + } + } + } + } + + return super.keyPressed(code, p_keyPressed_2_, p_keyPressed_3_); + } + + @Override + protected void renderWindow(int mouseX, int mouseY, float partialTicks) { + int x = topLeftX; + int y = topLeftY; + GuiResources.SCHEMATIC.draw(this, x, y); + BlueprintHandler bh = BlueprintHandler.instance; + + font.drawStringWithShadow(bh.cachedSchematicName, x + 103 - font.getStringWidth(bh.cachedSchematicName) / 2, + y + 10, 0xDDEEFF); + + font.drawString("Position", x + 10, y + 32, GuiResources.FONT_COLOR); + font.drawString("Rotation", x + 10, y + 52, GuiResources.FONT_COLOR); + font.drawString("Mirror", x + 10, y + 72, GuiResources.FONT_COLOR); + + GlStateManager.pushMatrix(); + GlStateManager.translated(topLeftX + 220, topLeftY + 20, 0); + GlStateManager.scaled(3, 3, 3); + itemRenderer.renderItemIntoGUI(new ItemStack(AllItems.BLUEPRINT.get()), 0, 0); + GlStateManager.popMatrix(); + } + + @Override + public void removed() { + // notify Blueprinthandler + BlueprintHandler bh = BlueprintHandler.instance; + + boolean validCoords = true; + BlockPos newLocation = null; + try { + newLocation = new BlockPos(Integer.parseInt(xInput.getText()), Integer.parseInt(yInput.getText()), + Integer.parseInt(zInput.getText())); + } catch (NumberFormatException e) { + validCoords = false; + } + + if (validCoords) + bh.moveTo(newLocation); + bh.setRotation(Rotation.values()[rotationArea.getState()]); + bh.setMirror(Mirror.values()[mirrorArea.getState()]); + } + +} diff --git a/src/main/java/com/simibubi/create/gui/GuiResources.java b/src/main/java/com/simibubi/create/gui/GuiResources.java index 4025376a1..42ee6f7a3 100644 --- a/src/main/java/com/simibubi/create/gui/GuiResources.java +++ b/src/main/java/com/simibubi/create/gui/GuiResources.java @@ -13,6 +13,7 @@ public enum GuiResources { WAND_SYMMETRY("wand_symmetry.png", 207, 58), SCHEMATIC_TABLE("schematic_table.png", 207, 89), SCHEMATIC_TABLE_PROGRESS("schematic_table.png", 209, 0, 24, 17), + SCHEMATIC("schematic.png", 207, 95), // Widgets PALETTE_BUTTON("palette_picker.png", 0, 236, 20, 20), diff --git a/src/main/java/com/simibubi/create/item/ItemBlueprint.java b/src/main/java/com/simibubi/create/item/ItemBlueprint.java index 7698a1d86..c5fcd2aab 100644 --- a/src/main/java/com/simibubi/create/item/ItemBlueprint.java +++ b/src/main/java/com/simibubi/create/item/ItemBlueprint.java @@ -11,6 +11,8 @@ import org.apache.commons.io.IOUtils; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; import com.simibubi.create.block.SchematicannonTileEntity; +import com.simibubi.create.gui.BlueprintEditScreen; +import com.simibubi.create.gui.GuiOpener; import com.simibubi.create.schematic.SchematicHologram; import net.minecraft.block.BlockState; @@ -33,6 +35,8 @@ import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; import net.minecraft.world.gen.feature.template.PlacementSettings; import net.minecraft.world.gen.feature.template.Template; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.common.thread.SidedThreadGroups; public class ItemBlueprint extends Item { @@ -108,8 +112,14 @@ public class ItemBlueprint extends Item { @Override public ActionResultType onItemUse(ItemUseContext context) { + if (context.isPlacerSneaking() && context.getHand() == Hand.MAIN_HAND) { + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { + GuiOpener.open(new BlueprintEditScreen()); + }); + return ActionResultType.SUCCESS; + } + World world = context.getWorld(); - CompoundNBT tag = context.getItem().getTag(); if (tag.contains("File")) { @@ -129,13 +139,6 @@ public class ItemBlueprint extends Item { context.getPlayer().setItemStackToSlot(EquipmentSlotType.MAINHAND, ItemStack.EMPTY); return ActionResultType.SUCCESS; } - - tag.put("Anchor", NBTUtil.writeBlockPos(pos.offset(context.getFace()))); - - if (!world.isRemote) { - return ActionResultType.SUCCESS; - } - } context.getPlayer().getCooldownTracker().setCooldown(this, 10); @@ -144,6 +147,14 @@ public class ItemBlueprint extends Item { @Override public ActionResult onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { + if (playerIn.isSneaking() && handIn == Hand.MAIN_HAND) { + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { + GuiOpener.open(new BlueprintEditScreen()); + }); + return new ActionResult(ActionResultType.SUCCESS, playerIn.getHeldItem(handIn)); + } + + return super.onItemRightClick(worldIn, playerIn, handIn); } diff --git a/src/main/java/com/simibubi/create/schematic/BlueprintHandler.java b/src/main/java/com/simibubi/create/schematic/BlueprintHandler.java index d591bf545..fcc381289 100644 --- a/src/main/java/com/simibubi/create/schematic/BlueprintHandler.java +++ b/src/main/java/com/simibubi/create/schematic/BlueprintHandler.java @@ -80,8 +80,8 @@ public class BlueprintHandler { if (stack == null) { instance.active = false; instance.syncCooldown = 0; - instance.slot = 0; if (instance.item != null && itemLost(player)) { + instance.slot = 0; instance.item = null; SchematicHologram.reset(); } @@ -99,7 +99,7 @@ public class BlueprintHandler { if (toolBefore != null) { instance.selectionScreen.setSelectedElement(toolBefore); instance.equip(toolBefore); - } + } } else instance.selectionScreen = new ToolSelectionScreen(ImmutableList.of(Tools.Deploy), instance::equip); @@ -122,6 +122,8 @@ public class BlueprintHandler { public static void onRenderWorld(RenderWorldLastEvent event) { if (!instance.active) return; + if (Minecraft.getInstance().player.isSneaking()) + return; TessellatorHelper.prepareForDrawing(); instance.currentTool.getTool().renderTool(); @@ -130,10 +132,11 @@ public class BlueprintHandler { @SubscribeEvent public static void onRenderOverlay(RenderGameOverlayEvent event) { + if (instance.item != null) + instance.overlay.renderOn(instance.slot); if (!instance.active) return; - instance.overlay.renderOn(instance.slot); instance.currentTool.getTool().renderOverlay(); instance.selectionScreen.renderPassive(event.getPartialTicks()); } @@ -148,6 +151,8 @@ public class BlueprintHandler { return; if (!instance.active) return; + if (Minecraft.getInstance().player.isSneaking()) + return; instance.currentTool.getTool().handleRightClick(); } @@ -176,6 +181,8 @@ public class BlueprintHandler { public boolean onScroll(double delta) { if (!active) return false; + if (Minecraft.getInstance().player.isSneaking()) + return false; if (selectionScreen.focused) { selectionScreen.cycle((int) delta); return true; @@ -303,6 +310,18 @@ public class BlueprintHandler { markDirty(); } + + public void setMirror(Mirror mirror) { + cachedSettings.setMirror(mirror); + item.getTag().putString("Mirror", cachedSettings.getMirror().name()); + markDirty(); + } + + public void setRotation(Rotation rotation) { + cachedSettings.setRotation(rotation); + item.getTag().putString("Rotation", cachedSettings.getRotation().name()); + markDirty(); + } public void moveTo(BlockPos anchor) { if (!deployed) diff --git a/src/main/resources/assets/create/textures/gui/schematic.png b/src/main/resources/assets/create/textures/gui/schematic.png new file mode 100644 index 0000000000000000000000000000000000000000..a46e2686bb2c49a4bb6a7660d4802b5785104d8a GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911MRQ8&P5Fo{p?&#~tz_78O`%fY(0|PTd zfKP}kP~6%vC^R%Qt8zv6%p;rk-Z*yb*#H0kf#RcJGz5ly2;8zd`~{RzN`m}?fysU( z1BT%5?5e;B=PdAuEM{QfI|Ravq8eTeKtYKT*NBqf{Irtt#G+J&g2c?c61}|C5(N`I zLp`&+PvnwdHdC0)ZJ(O@cI+$2JQ!T&ejZSou6~wecNLzXD|N#b@q=xj4T2U42&!X zUdL=>VB%-O3wpS2p+IWWkiSI0Io>|$apVZEnc?3bPY>%{ZWaD|3`HjDjm=liio{QhC} zs#5%bI`f*nZ