Blueprint Manual Coordinates

- Added a Screen to input coordinates in order to bypass the placement tools
This commit is contained in:
simibubi 2019-07-15 13:45:13 +02:00
parent 56139aab20
commit 01a6d32140
6 changed files with 202 additions and 11 deletions

View file

@ -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);
}

View file

@ -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<String> rotationOptions = ImmutableList.of("None", "Clockwise 90", "Clockwise 180",
"Clockwise 270");
private static final List<String> 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()]);
}
}

View file

@ -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),

View file

@ -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<ItemStack> 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<ItemStack>(ActionResultType.SUCCESS, playerIn.getHeldItem(handIn));
}
return super.onItemRightClick(worldIn, playerIn, handIn);
}

View file

@ -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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB