diff --git a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleConfigScreen.java b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleConfigScreen.java index 63166fd4e..80d3c99a6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleConfigScreen.java +++ b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleConfigScreen.java @@ -10,7 +10,6 @@ import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.GuiGameElement; import com.simibubi.create.foundation.utility.Lang; -import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; import net.minecraft.util.math.MathHelper; import net.minecraft.util.text.ITextComponent; @@ -53,10 +52,9 @@ public class GoggleConfigScreen extends AbstractSimiScreen { @Override protected void init() { - Minecraft mc = Minecraft.getInstance(); - this.width = mc.getWindow() + this.width = client.getWindow() .getScaledWidth(); - this.height = mc.getWindow() + this.height = client.getWindow() .getScaledHeight(); offsetX = AllConfigs.CLIENT.overlayOffsetX.get(); @@ -91,7 +89,7 @@ public class GoggleConfigScreen extends AbstractSimiScreen { int titleLinesCount = 1; int tooltipTextWidth = 0; for (ITextProperties textLine : tooltip) { - int textLineWidth = getMinecraft().fontRenderer.getWidth(textLine); + int textLineWidth = client.fontRenderer.getWidth(textLine); if (textLineWidth > tooltipTextWidth) tooltipTextWidth = textLineWidth; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/sequencer/SequencedGearshiftScreen.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/sequencer/SequencedGearshiftScreen.java index fb073cbc2..5ba9d46bd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/sequencer/SequencedGearshiftScreen.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/sequencer/SequencedGearshiftScreen.java @@ -14,7 +14,6 @@ import com.simibubi.create.foundation.gui.widgets.SelectionScrollInput; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.utility.Lang; -import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; import net.minecraft.nbt.ListNBT; import net.minecraft.util.math.BlockPos; @@ -27,7 +26,6 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { private final AllGuiTextures background = AllGuiTextures.SEQUENCER; private IconButton confirmButton; - private final ITextComponent title = Lang.translate("gui.sequenced_gearshift.title"); private ListNBT compareTag; private Vector instructions; private BlockPos pos; @@ -35,6 +33,7 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { private Vector> inputs; public SequencedGearshiftScreen(SequencedGearshiftTileEntity te) { + super(Lang.translate("gui.sequenced_gearshift.title")); this.instructions = te.instructions; this.pos = te.getPos(); compareTag = Instruction.serializeAll(instructions); @@ -42,21 +41,29 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { @Override protected void init() { - setWindowSize(background.width + 50, background.height); + setWindowSize(background.width, background.height); + setWindowOffset(-20, 0); super.init(); widgets.clear(); + int x = guiLeft; + int y = guiTop; + inputs = new Vector<>(5); for (int row = 0; row < inputs.capacity(); row++) inputs.add(new Vector<>(3)); for (int row = 0; row < instructions.size(); row++) - initInputsOfRow(row); + initInputsOfRow(row, x, y); + + confirmButton = + new IconButton(x + background.width - 33, y + background.height - 24, AllIcons.I_CONFIRM); + widgets.add(confirmButton); } - public void initInputsOfRow(int row) { - int x = guiLeft + 30; - int y = guiTop + 18; + public void initInputsOfRow(int row, int backgroundX, int backgroundY) { + int x = backgroundX + 30; + int y = backgroundY + 18; int rowHeight = 22; Vector rowInputs = inputs.get(row); @@ -83,10 +90,6 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { widgets.addAll(rowInputs); updateParamsOfRow(row); - - confirmButton = - new IconButton(guiLeft + background.width - 33, guiTop + background.height - 24, AllIcons.I_CONFIRM); - widgets.add(confirmButton); } public void updateParamsOfRow(int row) { @@ -123,43 +126,44 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { } @Override - protected void renderWindow(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { - int hFontColor = 0xD3CBBE; - background.draw(matrixStack, this, guiLeft, guiTop); + protected void renderWindow(MatrixStack ms, int mouseX, int mouseY, float partialTicks) { + int x = guiLeft; + int y = guiTop; + + background.draw(ms, this, x, y); for (int row = 0; row < instructions.capacity(); row++) { AllGuiTextures toDraw = AllGuiTextures.SEQUENCER_EMPTY; int yOffset = toDraw.height * row; if (row >= instructions.size()) { - toDraw.draw(matrixStack, guiLeft, guiTop + 14 + yOffset); + toDraw.draw(ms, x, y + 14 + yOffset); continue; } Instruction instruction = instructions.get(row); SequencerInstructions def = instruction.instruction; - def.background.draw(matrixStack, guiLeft, guiTop + 14 + yOffset); + def.background.draw(ms, x, y + 14 + yOffset); - label(matrixStack, 36, yOffset - 3, Lang.translate(def.translationKey)); + label(ms, 36, yOffset - 3, Lang.translate(def.translationKey)); if (def.hasValueParameter) { String text = def.formatValue(instruction.value); int stringWidth = textRenderer.getStringWidth(text); - label(matrixStack, 90 + (12 - stringWidth / 2), yOffset - 3, new StringTextComponent(text)); + label(ms, 90 + (12 - stringWidth / 2), yOffset - 3, new StringTextComponent(text)); } if (def.hasSpeedParameter) - label(matrixStack, 127, yOffset - 3, instruction.speedModifier.label); + label(ms, 127, yOffset - 3, instruction.speedModifier.label); } - textRenderer.drawWithShadow(matrixStack, title, guiLeft - 3 + (background.width - textRenderer.getWidth(title)) / 2, guiTop + 3, - 0xffffff); + drawCenteredText(ms, textRenderer, title, x + (background.width - 8) / 2, y + 3, 0xFFFFFF); GuiGameElement.of(renderedItem) - .at(guiLeft + background.width + 10, guiTop + 100, -150) + .at(x + background.width + 6, y + background.height - 56, -200) .scale(5) - .render(matrixStack); + .render(ms); } - private void label(MatrixStack matrixStack, int x, int y, ITextComponent text) { - textRenderer.drawWithShadow(matrixStack, text, guiLeft + x, guiTop + 26 + y, 0xFFFFEE); + private void label(MatrixStack ms, int x, int y, ITextComponent text) { + textRenderer.drawWithShadow(ms, text, guiLeft + x, guiTop + 26 + y, 0xFFFFEE); } public void sendPacket() { @@ -189,7 +193,7 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { } else { if (index + 1 < instructions.capacity() && index + 1 == instructions.size()) { instructions.add(new Instruction(SequencerInstructions.END)); - initInputsOfRow(index + 1); + initInputsOfRow(index + 1, guiLeft, guiTop); } } } @@ -197,7 +201,7 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { @Override public boolean mouseClicked(double x, double y, int button) { if (confirmButton.isHovered()) { - Minecraft.getInstance().player.closeScreen(); + client.player.closeScreen(); return true; } diff --git a/src/main/java/com/simibubi/create/content/curiosities/projector/ChromaticProjectorScreen.java b/src/main/java/com/simibubi/create/content/curiosities/projector/ChromaticProjectorScreen.java index 88761bc35..1e46fa747 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/projector/ChromaticProjectorScreen.java +++ b/src/main/java/com/simibubi/create/content/curiosities/projector/ChromaticProjectorScreen.java @@ -4,7 +4,6 @@ import java.util.Collections; import java.util.Vector; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllIcons; @@ -16,25 +15,20 @@ import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueBehaviour; import com.simibubi.create.foundation.utility.Lang; -import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; public class ChromaticProjectorScreen extends AbstractSimiScreen { - private final ItemStack renderedItem = ItemStack.EMPTY;//AllBlocks.CHROMATIC_PROJECTOR.asStack(); - private final AllGuiTextures background = AllGuiTextures.PROJECTOR; - private final int guiBottom = guiTop + background.height; - private final int guiRight = guiLeft + background.width; - private IconButton confirmButton; - - private final ITextComponent title = Lang.translate("gui.chromatic_projector.title"); - private final Vector stages; + private AllGuiTextures background; + private ChromaticProjectorTileEntity tile; + private Vector stages; + private ItemStack renderedItem = ItemStack.EMPTY;//AllBlocks.CHROMATIC_PROJECTOR.asStack(); private Vector> inputs; - ChromaticProjectorTileEntity tile; + private IconButton confirmButton; private ScrollInput radius; private ScrollInput density; @@ -51,71 +45,86 @@ public class ChromaticProjectorScreen extends AbstractSimiScreen { private IconButton bChannel; public ChromaticProjectorScreen(ChromaticProjectorTileEntity te) { - this.tile = te; - this.stages = te.stages; - } - - private static Integer step(ScrollValueBehaviour.StepContext ctx, int base) { - if (ctx.control) return 1; - return base * (ctx.shift ? 5 : 1) - ctx.currentValue % base; + super(Lang.translate("gui.chromatic_projector.title")); + background = AllGuiTextures.PROJECTOR; + tile = te; + stages = te.stages; } @Override protected void init() { - setWindowSize(background.width + 50, background.height); + setWindowSize(background.width, background.height); + setWindowOffset(-25, 0); super.init(); widgets.clear(); + int x = guiLeft; + int y = guiTop; + inputs = new Vector<>(FilterStep.MAX_STEPS); for (int row = 0; row < inputs.capacity(); row++) inputs.add(new Vector<>(2)); for (int row = 0; row < stages.size(); row++) - initInputsOfRow(row); + initInputsOfRow(row, x, y); - int guiBottom = guiTop + background.height; - int guiRight = guiLeft + background.width; confirmButton = - new IconButton(guiRight - 33, guiBottom - 26, AllIcons.I_CONFIRM); + new IconButton(x + background.width - 33, y + background.height - 26, AllIcons.I_CONFIRM); widgets.add(confirmButton); - initEffectSettings(); - initMetaSettings(); + initEffectSettings(x, y); + initMetaSettings(x, y); } - private void initMetaSettings() { - int guiBottom = guiTop + background.height; - int y = guiBottom - 23; + public void initInputsOfRow(int x, int y, int row) { + x += 30; + y += 18; + int rowHeight = 22; - blend = new IconButton(guiLeft + 16, y, AllIcons.I_FX_BLEND); - blend.setToolTip(Lang.translate("gui.chromatic_projector.blend")); + Vector rowInputs = inputs.get(row); + rowInputs.forEach(widgets::remove); + rowInputs.clear(); + FilterStep filter = stages.get(row); - int channelX = guiLeft + 39; - rChannel = new IconButton(channelX, y, AllIcons.I_FX_BLEND); - rChannel.setToolTip(new StringTextComponent("R")); - channelX += 18; - gChannel = new IconButton(channelX, y, AllIcons.I_FX_BLEND); - gChannel.setToolTip(new StringTextComponent("G")); - channelX += 18; - bChannel = new IconButton(channelX, y, AllIcons.I_FX_BLEND); - bChannel.setToolTip(new StringTextComponent("B")); + final int x1 = x; + final int y1 = y; + ScrollInput type = + new SelectionScrollInput(x, y + rowHeight * row, 86, 18) + .forOptions(ColorEffect.getOptions()) + .calling(state -> stageUpdated(x1, y1, row, state)) + .setState(filter.filter.id) + .titled(Lang.translate("gui.chromatic_projector.filter")); + ScrollInput value = + new ScrollInput(x + 86 + 2, y + rowHeight * row, 28, 18) + .calling(state -> filter.value = state); - fieldEffect = new IconButton(guiLeft + 135, y, tile.field ? AllIcons.I_FX_FIELD_ON : AllIcons.I_FX_FIELD_OFF); - fieldEffect.setToolTip(Lang.translate("gui.chromatic_projector.field")); + rowInputs.add(type); + rowInputs.add(value); - strength = new ScrollInput(guiLeft + 159, y, 25, 18) - .titled(Lang.translate("gui.chromatic_projector.strength")) - .withStepFunction(ctx -> step(ctx, 5)) - .calling(tile::setStrength) - .withRange(-100, 101) - .setState((int) (tile.strength * 100)); - - Collections.addAll(widgets, blend, rChannel, gChannel, bChannel, fieldEffect, strength); + widgets.addAll(rowInputs); + updateParamsOfRow(row); } - private void initEffectSettings() { - int x = guiLeft + 188; - int y = guiTop + 40; + public void updateParamsOfRow(int row) { + FilterStep instruction = stages.get(row); + Vector rowInputs = inputs.get(row); + ColorEffect def = instruction.filter; + boolean hasValue = def.hasParameter; + + ScrollInput value = rowInputs.get(1); + value.active = value.visible = hasValue; + if (hasValue) + value.withRange(def.minValue, def.maxValue + 1) + //.titled(Lang.translate(def.parameterKey)) + .setState(instruction.value) + .onChanged(); + + value.withStepFunction(def.step()); + } + + private void initEffectSettings(int x, int y) { + x += 188; + y += 40; radius = new ScrollInput(x, y, 28, 18) .titled(Lang.translate("gui.chromatic_projector.radius")) @@ -148,97 +157,82 @@ public class ChromaticProjectorScreen extends AbstractSimiScreen { Collections.addAll(widgets, radius, density, feather, fade); } - public void initInputsOfRow(int row) { - int x = guiLeft + 30; - int y = guiTop + 18; - int rowHeight = 22; + private void initMetaSettings(int x, int y) { + y += background.height - 23; - Vector rowInputs = inputs.get(row); - rowInputs.forEach(widgets::remove); - rowInputs.clear(); - FilterStep filter = stages.get(row); + blend = new IconButton(x + 16, y, AllIcons.I_FX_BLEND); + blend.setToolTip(Lang.translate("gui.chromatic_projector.blend")); - ScrollInput type = - new SelectionScrollInput(x, y + rowHeight * row, 86, 18) - .forOptions(ColorEffect.getOptions()) - .calling(state -> stageUpdated(row, state)) - .setState(filter.filter.id) - .titled(Lang.translate("gui.chromatic_projector.filter")); - ScrollInput value = - new ScrollInput(x + 86 + 2, y + rowHeight * row, 28, 18) - .calling(state -> filter.value = state); + int channelX = x + 39; + rChannel = new IconButton(channelX, y, AllIcons.I_FX_BLEND); + rChannel.setToolTip(new StringTextComponent("R")); + channelX += 18; + gChannel = new IconButton(channelX, y, AllIcons.I_FX_BLEND); + gChannel.setToolTip(new StringTextComponent("G")); + channelX += 18; + bChannel = new IconButton(channelX, y, AllIcons.I_FX_BLEND); + bChannel.setToolTip(new StringTextComponent("B")); - rowInputs.add(type); - rowInputs.add(value); + fieldEffect = new IconButton(x + 135, y, tile.field ? AllIcons.I_FX_FIELD_ON : AllIcons.I_FX_FIELD_OFF); + fieldEffect.setToolTip(Lang.translate("gui.chromatic_projector.field")); - widgets.addAll(rowInputs); - updateParamsOfRow(row); - } + strength = new ScrollInput(x + 159, y, 25, 18) + .titled(Lang.translate("gui.chromatic_projector.strength")) + .withStepFunction(ctx -> step(ctx, 5)) + .calling(tile::setStrength) + .withRange(-100, 101) + .setState((int) (tile.strength * 100)); - public void updateParamsOfRow(int row) { - FilterStep instruction = stages.get(row); - Vector rowInputs = inputs.get(row); - ColorEffect def = instruction.filter; - boolean hasValue = def.hasParameter; - - ScrollInput value = rowInputs.get(1); - value.active = value.visible = hasValue; - if (hasValue) - value.withRange(def.minValue, def.maxValue + 1) - //.titled(Lang.translate(def.parameterKey)) - .setState(instruction.value) - .onChanged(); - - value.withStepFunction(def.step()); + Collections.addAll(widgets, blend, rChannel, gChannel, bChannel, fieldEffect, strength); } @Override - protected void renderWindow(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { - int hFontColor = 0xD3CBBE; - background.draw(matrixStack, this, guiLeft, guiTop); + protected void renderWindow(MatrixStack ms, int mouseX, int mouseY, float partialTicks) { + int x = guiLeft; + int y = guiTop; + + background.draw(ms, this, x, y); for (int row = 0; row < stages.capacity(); row++) { AllGuiTextures toDraw = AllGuiTextures.PROJECTOR_EMPTY; int yOffset = toDraw.height * row; if (row >= stages.size()) { - toDraw.draw(matrixStack, guiLeft, guiTop + 14 + yOffset); + toDraw.draw(ms, x, y + 14 + yOffset); continue; } FilterStep step = stages.get(row); ColorEffect def = step.filter; - def.background.draw(matrixStack, guiLeft, guiTop + 14 + yOffset); + def.background.draw(ms, x, y + 14 + yOffset); if (def != ColorEffect.END) - label(matrixStack, 36, yOffset - 3, Lang.translate(def.translationKey)); + label(ms, 36, yOffset - 3, Lang.translate(def.translationKey)); if (def.hasParameter) { String text = step.filter.formatValue(step.value); int stringWidth = textRenderer.getStringWidth(text); - label(matrixStack, 118 + (12 - stringWidth / 2), yOffset - 3, new StringTextComponent(text)); + label(ms, 118 + (12 - stringWidth / 2), yOffset - 3, new StringTextComponent(text)); } } - renderScroll(matrixStack, radius, 2f); - renderScroll(matrixStack, density, 100f); - renderScroll(matrixStack, feather, 10f); - renderScroll(matrixStack, fade, 10f); + renderScroll(ms, radius, 2f); + renderScroll(ms, density, 100f); + renderScroll(ms, feather, 10f); + renderScroll(ms, fade, 10f); - renderScroll(matrixStack, strength, 100f); + renderScroll(ms, strength, 100f); - textRenderer.drawWithShadow(matrixStack, title, guiLeft - 3 + (background.width - textRenderer.getWidth(title)) / 2, guiTop + 3, - 0xffffff); + drawCenteredText(ms, textRenderer, title, x + (background.width - 8) / 2, y + 3, 0xFFFFFF); GuiGameElement.of(renderedItem) .scale(5) - .at(guiLeft + background.width + 10, guiTop + 140, -150) - .render(matrixStack); + .at(x + background.width + 6, y + background.height - 56, -200) + .render(ms); } private void renderScroll(MatrixStack matrixStack, ScrollInput input, float divisor) { - String text = String.valueOf(input.getState() / divisor); - int stringWidth = textRenderer.getStringWidth(text); +// int stringWidth = textRenderer.getStringWidth(text); textRenderer.drawWithShadow(matrixStack, text, input.x + 2, input.y + 5, 0xFFFFEE); } @@ -246,6 +240,11 @@ public class ChromaticProjectorScreen extends AbstractSimiScreen { textRenderer.drawWithShadow(matrixStack, text, guiLeft + x, guiTop + 26 + y, 0xFFFFEE); } + private static Integer step(ScrollValueBehaviour.StepContext ctx, int base) { + if (ctx.control) return 1; + return base * (ctx.shift ? 5 : 1) - ctx.currentValue % base; + } + public void sendPacket() { AllPackets.channel.sendToServer(new ConfigureProjectorPacket(tile)); } @@ -255,7 +254,7 @@ public class ChromaticProjectorScreen extends AbstractSimiScreen { sendPacket(); } - private void stageUpdated(int index, int state) { + private void stageUpdated(int x, int y, int index, int state) { ColorEffect newValue = ColorEffect.all.get(state); stages.get(index).filter = newValue; stages.get(index).value = newValue.defaultValue; @@ -270,7 +269,7 @@ public class ChromaticProjectorScreen extends AbstractSimiScreen { } else { if (index + 1 < stages.capacity() && index + 1 == stages.size()) { stages.add(new FilterStep(ColorEffect.END)); - initInputsOfRow(index + 1); + initInputsOfRow(x, y, index + 1); } } } @@ -278,7 +277,7 @@ public class ChromaticProjectorScreen extends AbstractSimiScreen { @Override public boolean mouseClicked(double x, double y, int button) { if (confirmButton.isHovered()) { - Minecraft.getInstance().player.closeScreen(); + client.player.closeScreen(); return true; } diff --git a/src/main/java/com/simibubi/create/content/curiosities/symmetry/SymmetryWandScreen.java b/src/main/java/com/simibubi/create/content/curiosities/symmetry/SymmetryWandScreen.java index bc2ebd9ef..dd9a4d638 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/symmetry/SymmetryWandScreen.java +++ b/src/main/java/com/simibubi/create/content/curiosities/symmetry/SymmetryWandScreen.java @@ -18,7 +18,6 @@ import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.networking.NbtPacket; import com.simibubi.create.foundation.utility.Lang; -import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Hand; @@ -30,6 +29,8 @@ import net.minecraftforge.fml.network.PacketDistributor; public class SymmetryWandScreen extends AbstractSimiScreen { + private AllGuiTextures background; + private ScrollInput areaType; private Label labelType; private ScrollInput areaAlign; @@ -46,6 +47,8 @@ public class SymmetryWandScreen extends AbstractSimiScreen { public SymmetryWandScreen(ItemStack wand, Hand hand) { super(); + background = AllGuiTextures.WAND_OF_SYMMETRY; + currentElement = SymmetryWandItem.getMirror(wand); if (currentElement instanceof EmptyMirror) { currentElement = new PlaneMirror(Vector3d.ZERO); @@ -56,18 +59,22 @@ public class SymmetryWandScreen extends AbstractSimiScreen { @Override public void init() { + setWindowSize(background.width, background.height); + setWindowOffset(-20, 0); super.init(); - AllGuiTextures background = AllGuiTextures.WAND_OF_SYMMETRY; - this.setWindowSize(background.width + 50, background.height + 50); + widgets.clear(); - labelType = new Label(guiLeft + 49, guiTop + 28, StringTextComponent.EMPTY).colored(0xFFFFFFFF) + int x = guiLeft; + int y = guiTop; + + labelType = new Label(x + 49, y + 28, StringTextComponent.EMPTY).colored(0xFFFFFFFF) .withShadow(); - labelAlign = new Label(guiLeft + 49, guiTop + 50, StringTextComponent.EMPTY).colored(0xFFFFFFFF) + labelAlign = new Label(x + 49, y + 50, StringTextComponent.EMPTY).colored(0xFFFFFFFF) .withShadow(); int state = currentElement instanceof TriplePlaneMirror ? 2 : currentElement instanceof CrossPlaneMirror ? 1 : 0; - areaType = new SelectionScrollInput(guiLeft + 45, guiTop + 21, 109, 18).forOptions(SymmetryMirror.getMirrors()) + areaType = new SelectionScrollInput(x + 45, y + 21, 109, 18).forOptions(SymmetryMirror.getMirrors()) .titled(mirrorType.copy()) .writingTo(labelType) .setState(state); @@ -86,27 +93,24 @@ public class SymmetryWandScreen extends AbstractSimiScreen { default: break; } - initAlign(currentElement); + initAlign(currentElement, x, y); }); - widgets.clear(); - - initAlign(currentElement); + initAlign(currentElement, x, y); widgets.add(labelAlign); widgets.add(areaType); widgets.add(labelType); - confirmButton = new IconButton(guiLeft + background.width - 33, guiTop + background.height - 24, AllIcons.I_CONFIRM); + confirmButton = new IconButton(x + background.width - 33, y + background.height - 24, AllIcons.I_CONFIRM); widgets.add(confirmButton); - } - private void initAlign(SymmetryMirror element) { + private void initAlign(SymmetryMirror element, int x, int y) { if (areaAlign != null) widgets.remove(areaAlign); - areaAlign = new SelectionScrollInput(guiLeft + 45, guiTop + 43, 109, 18).forOptions(element.getAlignToolTips()) + areaAlign = new SelectionScrollInput(x + 45, y + 43, 109, 18).forOptions(element.getAlignToolTips()) .titled(orientation.copy()) .writingTo(labelAlign) .setState(element.getOrientationIndex()) @@ -116,20 +120,24 @@ public class SymmetryWandScreen extends AbstractSimiScreen { } @Override - protected void renderWindow(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { - AllGuiTextures.WAND_OF_SYMMETRY.draw(matrixStack, this, guiLeft, guiTop); - textRenderer.draw(matrixStack, wand.getDisplayName(), guiLeft + 11, guiTop + 4, 0x6B3802); - renderBlock(matrixStack); + protected void renderWindow(MatrixStack ms, int mouseX, int mouseY, float partialTicks) { + int x = guiLeft; + int y = guiTop; + + background.draw(ms, this, x, y); + textRenderer.draw(ms, wand.getDisplayName(), x + 11, y + 4, 0x6B3802); + + renderBlock(ms, x, y); GuiGameElement.of(wand) .scale(4) .rotate(-70, 20, 20) - .at(guiLeft + 170, guiTop + 490, -150) - .render(matrixStack); + .at(x + 178, y + 448, -150) + .render(ms); } - protected void renderBlock(MatrixStack ms) { + protected void renderBlock(MatrixStack ms, int x, int y) { ms.push(); - ms.translate(guiLeft + 26f, guiTop + 39, 20); + ms.translate(x + 26, y + 39, 20); ms.scale(16, 16, 16); ms.multiply(new Vector3f(.3f, 1f, 0f).getDegreesQuaternion(-22.5f)); currentElement.applyModelTransform(ms); @@ -154,7 +162,7 @@ public class SymmetryWandScreen extends AbstractSimiScreen { @Override public boolean mouseClicked(double x, double y, int button) { if (confirmButton.isHovered()) { - Minecraft.getInstance().player.closeScreen(); + client.player.closeScreen(); return true; } diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintContainer.java b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintContainer.java index 5d1e5b1bc..eb71d907a 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintContainer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintContainer.java @@ -5,10 +5,10 @@ import java.util.Optional; import com.simibubi.create.AllContainerTypes; import com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintSection; import com.simibubi.create.foundation.gui.GhostItemContainer; -import com.simibubi.create.foundation.gui.IClearableContainer; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.CraftingInventory; @@ -25,7 +25,7 @@ import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.SlotItemHandler; -public class BlueprintContainer extends GhostItemContainer implements IClearableContainer { +public class BlueprintContainer extends GhostItemContainer { public BlueprintContainer(ContainerType type, int id, PlayerInventory inv, PacketBuffer extraData) { super(type, id, inv, extraData); @@ -46,7 +46,7 @@ public class BlueprintContainer extends GhostItemContainer imp @Override protected void addSlots() { - addPlayerSlots(9, 131); + addPlayerSlots(8, 131); int x = 29; int y = 21; @@ -133,6 +133,11 @@ public class BlueprintContainer extends GhostItemContainer imp return blueprintSection; } + @Override + public boolean canInteractWith(PlayerEntity player) { + return contentHolder != null && contentHolder.canPlayerUse(player); + } + static class BlueprintCraftingInventory extends CraftingInventory { public BlueprintCraftingInventory(Container container, ItemStackHandler items) { diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintEntity.java b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintEntity.java index 344bd3405..fad37fd64 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintEntity.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintEntity.java @@ -16,6 +16,7 @@ import com.simibubi.create.content.logistics.item.filter.FilterItem; import com.simibubi.create.content.schematics.ISpecialEntityItemRequirement; import com.simibubi.create.content.schematics.ItemRequirement; import com.simibubi.create.content.schematics.ItemRequirement.ItemUseType; +import com.simibubi.create.foundation.gui.IInteractionChecker; import com.simibubi.create.foundation.networking.ISyncPersistentData; import com.simibubi.create.foundation.utility.Couple; import com.simibubi.create.foundation.utility.VecHelper; @@ -69,7 +70,7 @@ import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.wrapper.InvWrapper; public class BlueprintEntity extends HangingEntity - implements IEntityAdditionalSpawnData, ISpecialEntityItemRequirement, ISyncPersistentData { + implements IEntityAdditionalSpawnData, ISpecialEntityItemRequirement, ISyncPersistentData, IInteractionChecker { protected int size; protected Direction verticalOrientation; @@ -485,7 +486,7 @@ public class BlueprintEntity extends HangingEntity return sectionCache.computeIfAbsent(index, i -> new BlueprintSection(i)); } - class BlueprintSection implements INamedContainerProvider { + class BlueprintSection implements INamedContainerProvider, IInteractionChecker { int index; Couple cachedDisplayItems; public boolean inferredIcon = false; @@ -539,6 +540,11 @@ public class BlueprintEntity extends HangingEntity .getTranslationKey()); } + @Override + public boolean canPlayerUse(PlayerEntity player) { + return BlueprintEntity.this.canPlayerUse(player); + } + } @Override @@ -546,4 +552,32 @@ public class BlueprintEntity extends HangingEntity sectionCache.clear(); } -} \ No newline at end of file + @Override + public boolean canPlayerUse(PlayerEntity player) { + AxisAlignedBB box = getBoundingBox(); + + double dx = 0; + if (box.minX > player.getX()) { + dx = box.minX - player.getX(); + } else if (player.getX() > box.maxX) { + dx = player.getX() - box.maxX; + } + + double dy = 0; + if (box.minY > player.getY()) { + dy = box.minY - player.getY(); + } else if (player.getY() > box.maxY) { + dy = player.getY() - box.maxY; + } + + double dz = 0; + if (box.minZ > player.getZ()) { + dz = box.minZ - player.getZ(); + } else if (player.getZ() > box.maxZ) { + dz = player.getZ() - box.maxZ; + } + + return (dx * dx + dy * dy + dz * dz) <= 64.0D; + } + +} diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintScreen.java b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintScreen.java index a587a6b86..5c7150818 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintScreen.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintScreen.java @@ -41,6 +41,7 @@ public class BlueprintScreen extends AbstractSimiContainerScreenat(x + background.width + 20, guiTop + background.height - 32, 0) + .at(x + background.width + 20, y + background.height - 32, 0) .rotate(45, -45, 22.5f) .scale(40) .render(ms); diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperScreen.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperScreen.java index b62d2039d..58b43fe45 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperScreen.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperScreen.java @@ -14,7 +14,6 @@ import com.simibubi.create.foundation.utility.Lang; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; -import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.NBTUtil; @@ -44,23 +43,26 @@ public class ZapperScreen extends AbstractSimiScreen { this.zapper = zapper; this.offhand = offhand; title = StringTextComponent.EMPTY; - brightColor = 0xfefefe; + brightColor = 0xFEFEFE; fontColor = AllGuiTextures.FONT_COLOR; } @Override protected void init() { - animationProgress = 0; setWindowSize(background.width, background.height); + setWindowOffset(-10, 0); super.init(); widgets.clear(); + animationProgress = 0; + + int x = guiLeft; + int y = guiTop; + confirmButton = - new IconButton(guiLeft + background.width - 43, guiTop + background.height - 24, AllIcons.I_CONFIRM); + new IconButton(x + background.width - 33, y + background.height - 24, AllIcons.I_CONFIRM); widgets.add(confirmButton); - int i = guiLeft - 10; - int j = guiTop; CompoundNBT nbt = zapper.getOrCreateTag(); patternButtons = new Vector<>(6); @@ -69,7 +71,7 @@ public class ZapperScreen extends AbstractSimiScreen { int id = patternButtons.size(); PlacementPatterns pattern = PlacementPatterns.values()[id]; patternButtons - .add(new IconButton(i + background.width - 76 + col * 18, j + 21 + row * 18, pattern.icon)); + .add(new IconButton(x + background.width - 76 + col * 18, y + 21 + row * 18, pattern.icon)); patternButtons.get(id) .setToolTip(Lang.translate("gui.terrainzapper.pattern." + pattern.translationKey)); } @@ -83,19 +85,19 @@ public class ZapperScreen extends AbstractSimiScreen { } @Override - protected void renderWindow(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { - int i = guiLeft - 10; - int j = guiTop; + protected void renderWindow(MatrixStack ms, int mouseX, int mouseY, float partialTicks) { + int x = guiLeft; + int y = guiTop; - background.draw(matrixStack, this, i, j); - drawOnBackground(matrixStack, i, j); + background.draw(ms, this, x, y); + drawOnBackground(ms, x, y); - renderBlock(matrixStack); - renderZapper(matrixStack); + renderBlock(ms, x, y); + renderZapper(ms, x, y); } - protected void drawOnBackground(MatrixStack matrixStack, int i, int j) { - textRenderer.draw(matrixStack, title, i + 11, j + 4, 0x54214F); + protected void drawOnBackground(MatrixStack ms, int x, int y) { + textRenderer.draw(ms, title, x + 11, y + 4, 0x54214F); } @Override @@ -119,8 +121,7 @@ public class ZapperScreen extends AbstractSimiScreen { if (patternButton.isHovered()) { patternButtons.forEach(b -> b.active = true); patternButton.active = false; - patternButton.playDownSound(Minecraft.getInstance() - .getSoundHandler()); + patternButton.playDownSound(client.getSoundHandler()); nbt.putString("Pattern", PlacementPatterns.values()[patternButtons.indexOf(patternButton)].name()); } } @@ -133,19 +134,19 @@ public class ZapperScreen extends AbstractSimiScreen { return super.mouseClicked(x, y, button); } - protected void renderZapper(MatrixStack matrixStack) { + protected void renderZapper(MatrixStack ms, int x, int y) { GuiGameElement.of(zapper) .scale(4) - .at((this.width - this.sWidth) / 2 + 220, this.height / 2 - this.sHeight / 4 + 27, -150) - .render(matrixStack); + .at(x + background.width, y + background.height - 48, -200) + .render(ms); } - protected void renderBlock(MatrixStack matrixStack) { - matrixStack.push(); - matrixStack.translate(guiLeft + 22f, guiTop + 42f, 120); - matrixStack.multiply(new Vector3f(1f, 0, 0).getDegreesQuaternion(-25f)); - matrixStack.multiply(new Vector3f(0, 1f, 0).getDegreesQuaternion(-45f)); - matrixStack.scale(20, 20, 20); + protected void renderBlock(MatrixStack ms, int x, int y) { + ms.push(); + ms.translate(x + 32, y + 42, 120); + ms.multiply(new Vector3f(1f, 0, 0).getDegreesQuaternion(-25f)); + ms.multiply(new Vector3f(0, 1f, 0).getDegreesQuaternion(-45f)); + ms.scale(20, 20, 20); BlockState state = Blocks.AIR.getDefaultState(); if (zapper.hasTag() && zapper.getTag() @@ -154,8 +155,8 @@ public class ZapperScreen extends AbstractSimiScreen { .getCompound("BlockUsed")); GuiGameElement.of(state) - .render(matrixStack); - matrixStack.pop(); + .render(ms); + ms.pop(); } protected void writeAdditionalOptions(CompoundNBT nbt) {} diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/WorldshaperScreen.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/WorldshaperScreen.java index 6937f719d..d578b551a 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/WorldshaperScreen.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/WorldshaperScreen.java @@ -43,8 +43,6 @@ public class WorldshaperScreen extends ZapperScreen { protected Indicator followDiagonalsIndicator; protected Indicator acrossMaterialsIndicator; - private int i; - private int j; private CompoundNBT nbt; public WorldshaperScreen(ItemStack zapper, boolean offhand) { @@ -58,24 +56,24 @@ public class WorldshaperScreen extends ZapperScreen { protected void init() { super.init(); - i = guiLeft - 10; - j = guiTop + 2; + int x = guiLeft; + int y = guiTop; - brushLabel = new Label(i + 61, j + 23, StringTextComponent.EMPTY).withShadow(); - brushInput = new SelectionScrollInput(i + 56, j + 18, 77, 18).forOptions(brushOptions) + brushLabel = new Label(x + 61, y + 25, StringTextComponent.EMPTY).withShadow(); + brushInput = new SelectionScrollInput(x + 56, y + 20, 77, 18).forOptions(brushOptions) .titled(Lang.translate("gui.terrainzapper.brush")) .writingTo(brushLabel) - .calling(this::brushChanged); + .calling(brushIndex -> initBrushParams(x, y)); if (nbt.contains("Brush")) brushInput.setState(NBTHelper.readEnum(nbt, "Brush", TerrainBrushes.class) .ordinal()); widgets.add(brushLabel); widgets.add(brushInput); - initBrushParams(); + initBrushParams(x, y); } - public void initBrushParams() { + public void initBrushParams(int x, int y) { if (brushParams != null) { nbt.put("BrushParams", NBTUtil.writeBlockPos(new BlockPos(brushParams.get(0) .getState(), @@ -95,16 +93,16 @@ public class WorldshaperScreen extends ZapperScreen { Brush currentBrush = TerrainBrushes.values()[brushInput.getState()].get(); for (int index = 0; index < 3; index++) { - Label label = new Label(i + 65 + 20 * index, j + 43, StringTextComponent.EMPTY).withShadow(); + Label label = new Label(x + 65 + 20 * index, y + 45, StringTextComponent.EMPTY).withShadow(); brushParamLabels.add(label); int indexFinal = index; - ScrollInput input = new ScrollInput(i + 56 + 20 * index, j + 38, 18, 18) + ScrollInput input = new ScrollInput(x + 56 + 20 * index, y + 40, 18, 18) .withRange(currentBrush.getMin(index), currentBrush.getMax(index) + 1) .writingTo(label) .titled(currentBrush.getParamLabel(index) .copy()) .calling(state -> { - label.x = i + 65 + 20 * indexFinal - textRenderer.getWidth(label.text) / 2; + label.x = x + 65 + 20 * indexFinal - textRenderer.getWidth(label.text) / 2; }); input.setState(params[index]); input.onChanged(); @@ -132,13 +130,13 @@ public class WorldshaperScreen extends ZapperScreen { } if (currentBrush.hasConnectivityOptions()) { - int x = i + 7 + 4 * 18; - int y = j + 77; - followDiagonalsIndicator = new Indicator(x, y - 6, StringTextComponent.EMPTY); - followDiagonals = new IconButton(x, y, AllIcons.I_FOLLOW_DIAGONAL); - x += 18; - acrossMaterialsIndicator = new Indicator(x, y - 6, StringTextComponent.EMPTY); - acrossMaterials = new IconButton(x, y, AllIcons.I_FOLLOW_MATERIAL); + int x1 = x + 7 + 4 * 18; + int y1 = y + 79; + followDiagonalsIndicator = new Indicator(x1, y1 - 6, StringTextComponent.EMPTY); + followDiagonals = new IconButton(x1, y1, AllIcons.I_FOLLOW_DIAGONAL); + x1 += 18; + acrossMaterialsIndicator = new Indicator(x1, y1 - 6, StringTextComponent.EMPTY); + acrossMaterials = new IconButton(x1, y1, AllIcons.I_FOLLOW_MATERIAL); followDiagonals.setToolTip(Lang.translate("gui.terrainzapper.searchDiagonal")); acrossMaterials.setToolTip(Lang.translate("gui.terrainzapper.searchFuzzy")); @@ -161,7 +159,7 @@ public class WorldshaperScreen extends ZapperScreen { toolButtons = new Vector<>(toolValues.length); for (int id = 0; id < toolValues.length; id++) { TerrainTools tool = toolValues[id]; - toolButtons.add(new IconButton(i + 7 + id * 18, j + 77, tool.icon)); + toolButtons.add(new IconButton(x + 7 + id * 18, y + 79, tool.icon)); toolButtons.get(id) .setToolTip(Lang.translate("gui.terrainzapper.tool." + tool.translationKey)); } @@ -190,7 +188,7 @@ public class WorldshaperScreen extends ZapperScreen { placementButtons = new Vector<>(placementValues.length); for (int id = 0; id < placementValues.length; id++) { PlacementOptions option = placementValues[id]; - placementButtons.add(new IconButton(i + 136 + id * 18, j + 77, option.icon)); + placementButtons.add(new IconButton(x + 136 + id * 18, y + 79, option.icon)); placementButtons.get(id) .setToolTip(Lang.translate("gui.terrainzapper.placement." + option.translationKey)); } @@ -205,11 +203,6 @@ public class WorldshaperScreen extends ZapperScreen { } placementButtons.get(optionIndex).active = false; widgets.addAll(placementButtons); - - } - - private void brushChanged(int brushIndex) { - initBrushParams(); } @Override @@ -251,16 +244,16 @@ public class WorldshaperScreen extends ZapperScreen { } @Override - protected void drawOnBackground(MatrixStack matrixStack, int i, int j) { - super.drawOnBackground(matrixStack, i, j); + protected void drawOnBackground(MatrixStack matrixStack, int x, int y) { + super.drawOnBackground(matrixStack, x, y); Brush currentBrush = TerrainBrushes.values()[brushInput.getState()].get(); for (int index = 2; index >= currentBrush.amtParams; index--) - AllGuiTextures.TERRAINZAPPER_INACTIVE_PARAM.draw(matrixStack, i + 56 + 20 * index, j + 40); + AllGuiTextures.TERRAINZAPPER_INACTIVE_PARAM.draw(matrixStack, x + 56 + 20 * index, y + 40); - textRenderer.draw(matrixStack, toolSection, i + 7, j + 69, fontColor); + textRenderer.draw(matrixStack, toolSection, x + 7, y + 69, fontColor); if (currentBrush.hasPlacementOptions()) - textRenderer.draw(matrixStack, placementSection, i + 136, j + 69, fontColor); + textRenderer.draw(matrixStack, placementSection, x + 136, y + 69, fontColor); } @Override diff --git a/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateContainer.java b/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateContainer.java index eeb7cc22b..20139c8d8 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateContainer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateContainer.java @@ -87,8 +87,8 @@ public class AdjustableCrateContainer extends Container { } @Override - public boolean canInteractWith(PlayerEntity playerIn) { - return true; + public boolean canInteractWith(PlayerEntity player) { + return te != null && te.canPlayerUse(player); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateScreen.java b/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateScreen.java index 6004c3c5e..f977b7b61 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateScreen.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateScreen.java @@ -60,12 +60,12 @@ public class AdjustableCrateScreen extends AbstractSimiContainerScreen slot * 64) continue; int slotsPerRow = (container.doubleCrate ? 8 : 4); - int x = crateLeft + 22 + (slot % slotsPerRow) * 18; - int y = crateTop + 19 + (slot / slotsPerRow) * 18; - AllGuiTextures.ADJUSTABLE_CRATE_LOCKED_SLOT.draw(ms, this, x, y); + int slotX = x + 22 + (slot % slotsPerRow) * 18; + int slotY = y + 19 + (slot / slotsPerRow) * 18; + AllGuiTextures.ADJUSTABLE_CRATE_LOCKED_SLOT.draw(ms, this, slotX, slotY); } GuiGameElement.of(renderedItem) - .at(crateLeft + background.width, crateTop + background.height - 56 + itemYShift, -200) + .at(x + background.width, y + background.height - 56 + itemYShift, -200) .scale(5) .render(ms); } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateTileEntity.java index e2a0a4860..0840fe8a4 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateTileEntity.java @@ -16,7 +16,6 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.StringTextComponent; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.CapabilityItemHandler; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchScreen.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchScreen.java index acca08977..613364cf1 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchScreen.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchScreen.java @@ -1,7 +1,5 @@ package com.simibubi.create.content.logistics.block.redstone; -import static com.simibubi.create.foundation.gui.AllGuiTextures.STOCKSWITCH; - import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.logistics.packet.ConfigureStockswitchPacket; @@ -16,7 +14,6 @@ import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.animation.LerpedFloat; import com.simibubi.create.foundation.utility.animation.LerpedFloat.Chaser; -import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; @@ -28,34 +25,39 @@ public class StockpileSwitchScreen extends AbstractSimiScreen { private IconButton confirmButton; private IconButton flipSignals; - private final ITextComponent title = Lang.translate("gui.stockpile_switch.title"); private final ITextComponent invertSignal = Lang.translate("gui.stockpile_switch.invert_signal"); private final ItemStack renderedItem = new ItemStack(AllBlocks.STOCKPILE_SWITCH.get()); - private int lastModification; + private AllGuiTextures background; private StockpileSwitchTileEntity te; + private int lastModification; private LerpedFloat cursor; private LerpedFloat cursorLane; public StockpileSwitchScreen(StockpileSwitchTileEntity te) { + super(Lang.translate("gui.stockpile_switch.title")); + background = AllGuiTextures.STOCKSWITCH; this.te = te; lastModification = -1; } @Override protected void init() { - AllGuiTextures background = STOCKSWITCH; - setWindowSize(background.width + 50, background.height); + setWindowSize(background.width, background.height); + setWindowOffset(-20, 0); super.init(); widgets.clear(); + int x = guiLeft; + int y = guiTop; + cursor = LerpedFloat.linear() .startWithValue(te.getLevelForDisplay()); cursorLane = LerpedFloat.linear() .startWithValue(te.getState() ? 1 : 0); - offBelow = new ScrollInput(guiLeft + 36, guiTop + 40, 102, 18).withRange(0, 100) + offBelow = new ScrollInput(x + 36, y + 40, 102, 18).withRange(0, 100) .titled(StringTextComponent.EMPTY.copy()) .calling(state -> { lastModification = 0; @@ -67,7 +69,7 @@ public class StockpileSwitchScreen extends AbstractSimiScreen { }) .setState((int) (te.offWhenBelow * 100)); - onAbove = new ScrollInput(guiLeft + 36, guiTop + 18, 102, 18).withRange(1, 101) + onAbove = new ScrollInput(x + 36, y + 18, 102, 18).withRange(1, 101) .titled(StringTextComponent.EMPTY.copy()) .calling(state -> { lastModification = 0; @@ -86,50 +88,50 @@ public class StockpileSwitchScreen extends AbstractSimiScreen { widgets.add(offBelow); confirmButton = - new IconButton(guiLeft + background.width - 33, guiTop + background.height - 24, AllIcons.I_CONFIRM); + new IconButton(x + background.width - 33, y + background.height - 24, AllIcons.I_CONFIRM); widgets.add(confirmButton); - flipSignals = new IconButton(guiLeft + 14, guiTop + 40, AllIcons.I_FLIP); + flipSignals = new IconButton(x + 14, y + 40, AllIcons.I_FLIP); flipSignals.setToolTip(invertSignal); widgets.add(flipSignals); } @Override - protected void renderWindow(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { - STOCKSWITCH.draw(matrixStack, this, guiLeft, guiTop); + protected void renderWindow(MatrixStack ms, int mouseX, int mouseY, float partialTicks) { + int x = guiLeft; + int y = guiTop; - AllGuiTextures.STOCKSWITCH_POWERED_LANE.draw(matrixStack, this, guiLeft + 36, guiTop + (te.isInverted() ? 18 : 40)); - AllGuiTextures.STOCKSWITCH_UNPOWERED_LANE.draw(matrixStack, this, guiLeft + 36, guiTop + (te.isInverted() ? 40 : 18)); - textRenderer.drawWithShadow(matrixStack, title, guiLeft - 3 + (STOCKSWITCH.width - textRenderer.getWidth(title)) / 2, guiTop + 3, - 0xffffff); + background.draw(ms, this, x, y); + + AllGuiTextures.STOCKSWITCH_POWERED_LANE.draw(ms, this, x + 36, y + (te.isInverted() ? 18 : 40)); + AllGuiTextures.STOCKSWITCH_UNPOWERED_LANE.draw(ms, this, x + 36, y + (te.isInverted() ? 40 : 18)); + drawCenteredText(ms, textRenderer, title, x + (background.width - 8) / 2, y + 3, 0xFFFFFF); AllGuiTextures sprite = AllGuiTextures.STOCKSWITCH_INTERVAL; float lowerBound = offBelow.getState(); float upperBound = onAbove.getState(); sprite.bind(); - drawTexture(matrixStack, (int) (guiLeft + upperBound) + 37, guiTop + 18, (int) (sprite.startX + upperBound), sprite.startY, + drawTexture(ms, (int) (x + upperBound) + 37, y + 18, (int) (sprite.startX + upperBound), sprite.startY, (int) (sprite.width - upperBound), sprite.height); - drawTexture(matrixStack, guiLeft + 37, guiTop + 40, sprite.startX, sprite.startY, (int) (lowerBound), sprite.height); + drawTexture(ms, x + 37, y + 40, sprite.startX, sprite.startY, (int) (lowerBound), sprite.height); - AllGuiTextures.STOCKSWITCH_ARROW_UP.draw(matrixStack, this, (int) (guiLeft + lowerBound + 36) - 2, guiTop + 35); - AllGuiTextures.STOCKSWITCH_ARROW_DOWN.draw(matrixStack, this, (int) (guiLeft + upperBound + 36) - 3, guiTop + 17); + AllGuiTextures.STOCKSWITCH_ARROW_UP.draw(ms, this, (int) (x + lowerBound + 36) - 2, y + 35); + AllGuiTextures.STOCKSWITCH_ARROW_DOWN.draw(ms, this, (int) (x + upperBound + 36) - 3, y + 17); if (te.currentLevel != -1) { AllGuiTextures cursor = AllGuiTextures.STOCKSWITCH_CURSOR; - matrixStack.push(); - matrixStack.translate(Math.min(99, this.cursor.getValue(partialTicks) * sprite.width), + ms.push(); + ms.translate(Math.min(99, this.cursor.getValue(partialTicks) * sprite.width), cursorLane.getValue(partialTicks) * 22, 0); - cursor.draw(matrixStack, this, guiLeft + 34, guiTop + 19); - matrixStack.pop(); + cursor.draw(ms, this, x + 34, y + 19); + ms.pop(); } - matrixStack.push(); GuiGameElement.of(renderedItem) - .at(guiLeft + STOCKSWITCH.width + 15, guiTop + 40, -250) + .at(x + background.width + 6, y + background.height - 56, -200) .scale(5) - .render(matrixStack); - matrixStack.pop(); + .render(ms); } @Override @@ -165,7 +167,7 @@ public class StockpileSwitchScreen extends AbstractSimiScreen { if (flipSignals.isHovered()) send(!te.isInverted()); if (confirmButton.isHovered()) { - Minecraft.getInstance().player.closeScreen(); + client.player.closeScreen(); return true; } return super.mouseClicked(x, y, button); diff --git a/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerContainer.java b/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerContainer.java index 5d0a54190..d2770f269 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerContainer.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerContainer.java @@ -46,7 +46,7 @@ public class LinkedControllerContainer extends Container implements IClearableCo } protected void addPlayerSlots() { - int x = 9; + int x = 8; int y = 131; for (int hotbarSlot = 0; hotbarSlot < 9; ++hotbarSlot) @@ -88,7 +88,7 @@ public class LinkedControllerContainer extends Container implements IClearableCo @Override public boolean canInteractWith(PlayerEntity playerIn) { - return true; + return playerInventory.getCurrentItem() == mainItem; } @Override diff --git a/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerScreen.java b/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerScreen.java index caef8889d..bfbfbbbde 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerScreen.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerScreen.java @@ -37,6 +37,7 @@ public class LinkedControllerScreen extends AbstractSimiContainerScreen ex @Override protected void renderWindow(MatrixStack ms, int mouseX, int mouseY, float partialTicks) { - int invLeft = guiLeft - windowXOffset + (xSize - PLAYER_INVENTORY.width) / 2; - int invTop = guiTop + background.height + 4; - - PLAYER_INVENTORY.draw(ms, this, invLeft, invTop); - textRenderer.draw(ms, playerInventory.getDisplayName(), invLeft + 8, invTop + 6, 0x404040); + int invX = getLeftOfCentered(PLAYER_INVENTORY.width); + int invY = guiTop + background.height + 4; + renderPlayerInventory(ms, invX, invY); int x = guiLeft; int y = guiTop; diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableContainer.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableContainer.java index 2d0ba889c..a6022d362 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableContainer.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableContainer.java @@ -83,8 +83,8 @@ public class SchematicTableContainer extends Container { } @Override - public boolean canInteractWith(PlayerEntity playerIn) { - return true; + public boolean canInteractWith(PlayerEntity player) { + return te != null && te.canPlayerUse(player); } @Override diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableScreen.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableScreen.java index 2cd8049db..658c99f78 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableScreen.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableScreen.java @@ -1,5 +1,6 @@ package com.simibubi.create.content.schematics.block; +import static com.simibubi.create.foundation.gui.AllGuiTextures.PLAYER_INVENTORY; import static com.simibubi.create.foundation.gui.AllGuiTextures.SCHEMATIC_TABLE_PROGRESS; import java.nio.file.Paths; @@ -69,22 +70,25 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen availableSchematics = CreateClient.SCHEMATIC_SENDER.getAvailableSchematics(); - schematicsLabel = new Label(guiLeft + 49, guiTop + 26, StringTextComponent.EMPTY).withShadow(); + int x = guiLeft; + int y = guiTop; + + schematicsLabel = new Label(x + 49, y + 26, StringTextComponent.EMPTY).withShadow(); schematicsLabel.text = StringTextComponent.EMPTY; if (!availableSchematics.isEmpty()) { schematicsArea = - new SelectionScrollInput(guiLeft + 45, guiTop + 21, 139, 18).forOptions(availableSchematics) + new SelectionScrollInput(x + 45, y + 21, 139, 18).forOptions(availableSchematics) .titled(availableSchematicsTitle.copy()) .writingTo(schematicsLabel); widgets.add(schematicsArea); widgets.add(schematicsLabel); } - confirmButton = new IconButton(guiLeft + 44, guiTop + 56, AllIcons.I_CONFIRM); + confirmButton = new IconButton(x + 44, y + 56, AllIcons.I_CONFIRM); - folderButton = new IconButton(guiLeft + 21, guiTop + 21, AllIcons.I_OPEN_FOLDER); + folderButton = new IconButton(x + 21, y + 21, AllIcons.I_OPEN_FOLDER); folderButton.setToolTip(folder); - refreshButton = new IconButton(guiLeft + 207, guiTop + 21, AllIcons.I_REFRESH); + refreshButton = new IconButton(x + 207, y + 21, AllIcons.I_REFRESH); refreshButton.setToolTip(refresh); widgets.add(confirmButton); @@ -92,20 +96,21 @@ public class SchematicTableScreen extends AbstractSimiContainerScreenat(guiLeft + background.width, guiTop + background.height - 40, -200) + .at(x + background.width, y + background.height - 40, -200) .scale(3) .render(ms); - client.getTextureManager() - .bindTexture(SCHEMATIC_TABLE_PROGRESS.location); + SCHEMATIC_TABLE_PROGRESS.bind(); int width = (int) (SCHEMATIC_TABLE_PROGRESS.width * MathHelper.lerp(partialTicks, lastChasingProgress, chasingProgress)); int height = SCHEMATIC_TABLE_PROGRESS.height; RenderSystem.disableLighting(); - drawTexture(ms, guiLeft + 70, guiTop + 57, SCHEMATIC_TABLE_PROGRESS.startX, + drawTexture(ms, x + 70, y + 57, SCHEMATIC_TABLE_PROGRESS.startX, SCHEMATIC_TABLE_PROGRESS.startY, width, height); } @@ -198,7 +202,7 @@ public class SchematicTableScreen extends AbstractSimiContainerScreenat(guiLeft + BG_TOP.width, guiTop + BG_TOP.height + BG_BOTTOM.height - 48, -200) + .at(x + BG_TOP.width, y + BG_TOP.height + BG_BOTTOM.height - 48, -200) .scale(5) .render(ms); - drawCenteredText(ms, textRenderer, title, guiLeft + (BG_TOP.width - 8) / 2, guiTop + 3, 0xFFFFFF); + drawCenteredText(ms, textRenderer, title, x + (BG_TOP.width - 8) / 2, y + 3, 0xFFFFFF); ITextComponent msg = Lang.translate("schematicannon.status." + te.statusMsg); int stringWidth = textRenderer.getWidth(msg); @@ -278,44 +279,41 @@ public class SchematicannonScreen extends AbstractSimiContainerScreenat(guiLeft + 128, guiTop + 49, 100) + .at(x + 128, y + 49, 100) .scale(1) .render(ms); } - textRenderer.drawWithShadow(ms, msg, guiLeft + 103 - stringWidth / 2, guiTop + 53, 0xCCDDFF); + textRenderer.drawWithShadow(ms, msg, x + 103 - stringWidth / 2, y + 53, 0xCCDDFF); } - protected void renderBlueprintHighlight(MatrixStack matrixStack) { - AllGuiTextures.SCHEMATICANNON_HIGHLIGHT.draw(matrixStack, this, guiLeft + 10, guiTop + 60); + protected void renderBlueprintHighlight(MatrixStack matrixStack, int x, int y) { + AllGuiTextures.SCHEMATICANNON_HIGHLIGHT.draw(matrixStack, this, x + 10, y + 60); } - protected void renderPrintingProgress(MatrixStack matrixStack, float progress) { + protected void renderPrintingProgress(MatrixStack matrixStack, int x, int y, float progress) { progress = Math.min(progress, 1); AllGuiTextures sprite = AllGuiTextures.SCHEMATICANNON_PROGRESS; - client.getTextureManager() - .bindTexture(sprite.location); - drawTexture(matrixStack, guiLeft + 44, guiTop + 64, sprite.startX, sprite.startY, (int) (sprite.width * progress), + sprite.bind(); + drawTexture(matrixStack, x + 44, y + 64, sprite.startX, sprite.startY, (int) (sprite.width * progress), sprite.height); } - protected void renderChecklistPrinterProgress(MatrixStack matrixStack, float progress) { + protected void renderChecklistPrinterProgress(MatrixStack matrixStack, int x, int y, float progress) { AllGuiTextures sprite = AllGuiTextures.SCHEMATICANNON_CHECKLIST_PROGRESS; - client.getTextureManager() - .bindTexture(sprite.location); - drawTexture(matrixStack, guiLeft + 154, guiTop + 20, sprite.startX, sprite.startY, (int) (sprite.width * progress), + sprite.bind(); + drawTexture(matrixStack, x + 154, y + 20, sprite.startX, sprite.startY, (int) (sprite.width * progress), sprite.height); } - protected void renderFuelBar(MatrixStack matrixStack, float amount) { + protected void renderFuelBar(MatrixStack matrixStack, int x, int y, float amount) { AllGuiTextures sprite = AllGuiTextures.SCHEMATICANNON_FUEL; if (container.getTileEntity().hasCreativeCrate) { - AllGuiTextures.SCHEMATICANNON_FUEL_CREATIVE.draw(matrixStack, this, guiLeft + 36, guiTop + 19); + AllGuiTextures.SCHEMATICANNON_FUEL_CREATIVE.draw(matrixStack, this, x + 36, y + 19); return; } - client.getTextureManager() - .bindTexture(sprite.location); - drawTexture(matrixStack, guiLeft + 36, guiTop + 19, sprite.startX, sprite.startY, (int) (sprite.width * amount), + sprite.bind(); + drawTexture(matrixStack, x + 36, y + 19, sprite.startX, sprite.startY, (int) (sprite.width * amount), sprite.height); } @@ -323,7 +321,10 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen= fuelX && mouseY >= fuelY && mouseX <= fuelX + AllGuiTextures.SCHEMATICANNON_FUEL.width && mouseY <= fuelY + AllGuiTextures.SCHEMATICANNON_FUEL.height) { List tooltip = getFuelLevelTooltip(te); @@ -346,14 +347,14 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen= missingBlockX && mouseY >= missingBlockY && mouseX <= missingBlockX + 16 && mouseY <= missingBlockY + 16) { renderTooltip(matrixStack, te.missingItem, mouseX, mouseY); } } - int paperX = guiLeft + 112, paperY = guiTop + 19; + int paperX = x + 112, paperY = y + 19; if (mouseX >= paperX && mouseY >= paperY && mouseX <= paperX + 16 && mouseY <= paperY + 16) renderTooltip(matrixStack, listPrinter, mouseX, mouseY); diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicEditScreen.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicEditScreen.java index 818327e76..5f29331d4 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicEditScreen.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicEditScreen.java @@ -28,6 +28,8 @@ import net.minecraft.world.gen.feature.template.PlacementSettings; public class SchematicEditScreen extends AbstractSimiScreen { + private AllGuiTextures background; + private TextFieldWidget xInput; private TextFieldWidget yInput; private TextFieldWidget zInput; @@ -44,13 +46,21 @@ public class SchematicEditScreen extends AbstractSimiScreen { private ScrollInput mirrorArea; private SchematicHandler handler; + public SchematicEditScreen() { + super(); + background = AllGuiTextures.SCHEMATIC; + handler = CreateClient.SCHEMATIC_HANDLER; + } + @Override protected void init() { - AllGuiTextures background = AllGuiTextures.SCHEMATIC; - setWindowSize(background.width + 50, background.height); + setWindowSize(background.width, background.height); + setWindowOffset(-6, 0); + super.init(); + widgets.clear(); + int x = guiLeft; int y = guiTop; - handler = CreateClient.SCHEMATIC_HANDLER; xInput = new TextFieldWidget(textRenderer, x + 50, y + 26, 34, 10, StringTextComponent.EMPTY); yInput = new TextFieldWidget(textRenderer, x + 90, y + 26, 34, 10, StringTextComponent.EMPTY); @@ -107,15 +117,12 @@ public class SchematicEditScreen extends AbstractSimiScreen { Collections.addAll(widgets, labelR, labelM, rotationArea, mirrorArea); confirmButton = - new IconButton(guiLeft + background.width - 33, guiTop + background.height - 24, AllIcons.I_CONFIRM); + new IconButton(x + background.width - 33, y + background.height - 24, AllIcons.I_CONFIRM); widgets.add(confirmButton); - - super.init(); } @Override public boolean keyPressed(int code, int p_keyPressed_2_, int p_keyPressed_3_) { - if (isPaste(code)) { String coords = client.keyboardListener.getClipboardString(); if (coords != null && !coords.isEmpty()) { @@ -144,17 +151,18 @@ public class SchematicEditScreen extends AbstractSimiScreen { } @Override - protected void renderWindow(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { + protected void renderWindow(MatrixStack ms, int mouseX, int mouseY, float partialTicks) { int x = guiLeft; int y = guiTop; - AllGuiTextures.SCHEMATIC.draw(matrixStack, this, x, y); - textRenderer.drawWithShadow(matrixStack, handler.getCurrentSchematicName(), - x + 93 - textRenderer.getStringWidth(handler.getCurrentSchematicName()) / 2, y + 3, 0xffffff); + + background.draw(ms, this, x, y); + String title = handler.getCurrentSchematicName(); + drawCenteredString(ms, textRenderer, title, x + (background.width - 8) / 2, y + 3, 0xFFFFFF); GuiGameElement.of(AllItems.SCHEMATIC.asStack()) - .at(guiLeft + 200, guiTop + 82, 0) + .at(x + background.width + 6, y + background.height - 40, -200) .scale(3) - .render(matrixStack); + .render(ms); } @Override diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicPromptScreen.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicPromptScreen.java index ce7cd33df..c635d4bb9 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicPromptScreen.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicPromptScreen.java @@ -12,14 +12,14 @@ import com.simibubi.create.foundation.gui.GuiGameElement; import com.simibubi.create.foundation.gui.widgets.IconButton; import com.simibubi.create.foundation.utility.Lang; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; public class SchematicPromptScreen extends AbstractSimiScreen { - private final ITextComponent title = Lang.translate("schematicAndQuill.title"); + private AllGuiTextures background; + private final ITextComponent convertLabel = Lang.translate("schematicAndQuill.convert"); private final ITextComponent abortLabel = Lang.translate("action.discard"); private final ITextComponent confirmLabel = Lang.translate("action.saveToFile"); @@ -29,28 +29,36 @@ public class SchematicPromptScreen extends AbstractSimiScreen { private IconButton abort; private IconButton convert; + public SchematicPromptScreen() { + super(Lang.translate("schematicAndQuill.title")); + background = AllGuiTextures.SCHEMATIC_PROMPT; + } + @Override public void init() { + setWindowSize(background.width, background.height); super.init(); - AllGuiTextures background = AllGuiTextures.SCHEMATIC_PROMPT; - setWindowSize(background.width, background.height + 30); + widgets.clear(); - nameField = new TextFieldWidget(textRenderer, guiLeft + 49, guiTop + 26, 131, 10, StringTextComponent.EMPTY); + int x = guiLeft; + int y = guiTop; + + nameField = new TextFieldWidget(textRenderer, x + 49, y + 26, 131, 10, StringTextComponent.EMPTY); nameField.setTextColor(-1); nameField.setDisabledTextColour(-1); nameField.setEnableBackgroundDrawing(false); nameField.setMaxStringLength(35); nameField.changeFocus(true); - abort = new IconButton(guiLeft + 7, guiTop + 53, AllIcons.I_TRASH); + abort = new IconButton(x + 7, y + 53, AllIcons.I_TRASH); abort.setToolTip(abortLabel); widgets.add(abort); - confirm = new IconButton(guiLeft + 158, guiTop + 53, AllIcons.I_CONFIRM); + confirm = new IconButton(x + 158, y + 53, AllIcons.I_CONFIRM); confirm.setToolTip(confirmLabel); widgets.add(confirm); - convert = new IconButton(guiLeft + 180, guiTop + 53, AllIcons.I_SCHEMATIC); + convert = new IconButton(x + 180, y + 53, AllIcons.I_SCHEMATIC); convert.setToolTip(convertLabel); widgets.add(convert); @@ -62,11 +70,18 @@ public class SchematicPromptScreen extends AbstractSimiScreen { @Override protected void renderWindow(MatrixStack ms, int mouseX, int mouseY, float partialTicks) { - AllGuiTextures.SCHEMATIC_PROMPT.draw(ms, this, guiLeft, guiTop); - textRenderer.drawWithShadow(ms, title, guiLeft + (sWidth / 2) - (textRenderer.getWidth(title) / 2), guiTop + 3, - 0xffffff); + int x = guiLeft; + int y = guiTop; + + background.draw(ms, this, x, y); + drawCenteredText(ms, textRenderer, title, x + (background.width - 8) / 2, y + 3, 0xFFFFFF); GuiGameElement.of(AllItems.SCHEMATIC.asStack()) - .at(guiLeft + 22, guiTop + 23, 0) + .at(x + 22, y + 23, 0) + .render(ms); + + GuiGameElement.of(AllItems.SCHEMATIC_AND_QUILL.asStack()) + .scale(3) + .at(x + background.width + 6, y + background.height - 40, -200) .render(ms); } @@ -91,7 +106,7 @@ public class SchematicPromptScreen extends AbstractSimiScreen { } if (abort.isHovered()) { CreateClient.SCHEMATIC_AND_QUILL_HANDLER.discard(); - Minecraft.getInstance().player.closeScreen(); + client.player.closeScreen(); return true; } if (convert.isHovered()) { @@ -103,7 +118,7 @@ public class SchematicPromptScreen extends AbstractSimiScreen { private void confirm(boolean convertImmediately) { CreateClient.SCHEMATIC_AND_QUILL_HANDLER.saveSchematic(nameField.getText(), convertImmediately); - Minecraft.getInstance().player.closeScreen(); + client.player.closeScreen(); } } diff --git a/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java b/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java index 06300938c..89ddbf92a 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java +++ b/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java @@ -1,5 +1,7 @@ package com.simibubi.create.foundation.gui; +import static com.simibubi.create.foundation.gui.AllGuiTextures.PLAYER_INVENTORY; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -7,6 +9,8 @@ import java.util.List; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; +import org.lwjgl.opengl.GL11; + import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.foundation.gui.widgets.AbstractSimiWidget; @@ -174,6 +178,51 @@ public abstract class AbstractSimiContainerScreen extends C } } + public double getItemCountTextScale() { + int guiScaleFactor = (int) client.getWindow() + .getGuiScaleFactor(); + double scale = 1; + switch (guiScaleFactor) { + case 1: + scale = 2060 / 2048d; + break; + case 2: + scale = .5; + break; + case 3: + scale = .675; + break; + case 4: + scale = .75; + break; + default: + scale = ((float) guiScaleFactor - 1) / guiScaleFactor; + } + return scale; + } + + public int getLeftOfCentered(int textureWidth) { + return (width - textureWidth) / 2; + } + + public void renderPlayerInventory(MatrixStack ms, int x, int y) { + PLAYER_INVENTORY.draw(ms, this, x, y); + textRenderer.draw(ms, playerInventory.getDisplayName(), x + 8, y + 6, 0x404040); + } + + /** + * Used for moving JEI out of the way of extra things like Flexcrate renders. + * + *

This screen class must be bound to a SlotMover instance for this method to work. + * + * @return the space that the gui takes up besides the normal rectangle defined by {@link ContainerScreen}. + */ + public List getExtraAreas() { + return Collections.emptyList(); + } + + // Not up to date with ItemRenderer + @Deprecated protected void renderItemOverlayIntoGUI(MatrixStack matrixStack, FontRenderer fr, ItemStack stack, int xPosition, int yPosition, @Nullable String text, int textColor) { if (!stack.isEmpty()) { @@ -227,32 +276,10 @@ public abstract class AbstractSimiContainerScreen extends C } } - public double getItemCountTextScale() { - int guiScaleFactor = (int) client.getWindow() - .getGuiScaleFactor(); - double scale = 1; - switch (guiScaleFactor) { - case 1: - scale = 2060 / 2048d; - break; - case 2: - scale = .5; - break; - case 3: - scale = .675; - break; - case 4: - scale = .75; - break; - default: - scale = ((float) guiScaleFactor - 1) / guiScaleFactor; - } - return scale; - } - + @Deprecated private void draw(BufferBuilder renderer, int x, int y, int width, int height, int red, int green, int blue, int alpha) { - renderer.begin(7, DefaultVertexFormats.POSITION_COLOR); + renderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); renderer.vertex((double) (x + 0), (double) (y + 0), 0.0D) .color(red, green, blue, alpha) .endVertex(); @@ -269,18 +296,9 @@ public abstract class AbstractSimiContainerScreen extends C .draw(); } - /** - * Used for moving JEI out of the way of extra things like Flexcrate renders - * - * @return the space that the gui takes up besides the normal rectangle defined by {@link ContainerScreen}. - */ - public List getExtraAreas() { - return Collections.emptyList(); - } - @Deprecated protected void debugWindowArea(MatrixStack matrixStack) { - fill(matrixStack, guiLeft + xSize, guiTop + ySize, guiLeft, guiTop, 0xd3d3d3d3); + fill(matrixStack, guiLeft + xSize, guiTop + ySize, guiLeft, guiTop, 0xD3D3D3D3); } @Deprecated @@ -289,4 +307,5 @@ public abstract class AbstractSimiContainerScreen extends C fill(matrixStack, area.getX() + area.getWidth(), area.getY() + area.getHeight(), area.getX(), area.getY(), 0xd3d3d3d3); } } + } diff --git a/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiScreen.java b/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiScreen.java index 4a78dc36e..a9d07e4ec 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiScreen.java +++ b/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiScreen.java @@ -10,6 +10,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.util.InputMappings; +import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -17,20 +18,37 @@ import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) public abstract class AbstractSimiScreen extends Screen { - protected int sWidth, sHeight; + protected int windowWidth, windowHeight; + protected int windowXOffset, windowYOffset; protected int guiLeft, guiTop; protected List widgets; - protected AbstractSimiScreen() { - super(new StringTextComponent("")); + protected AbstractSimiScreen(ITextComponent title) { + super(title); widgets = new ArrayList<>(); } + protected AbstractSimiScreen() { + this(new StringTextComponent("")); + } + protected void setWindowSize(int width, int height) { - sWidth = width; - sHeight = height; - guiLeft = (this.width - sWidth) / 2; - guiTop = (this.height - sHeight) / 2; + windowWidth = width; + windowHeight = height; + } + + protected void setWindowOffset(int xOffset, int yOffset) { + windowXOffset = xOffset; + windowYOffset = yOffset; + } + + @Override + protected void init() { + super.init(); + guiLeft = (width - windowWidth) / 2; + guiTop = (height - windowHeight) / 2; + guiLeft += windowXOffset; + guiTop += windowYOffset; } @Override @@ -156,4 +174,9 @@ public abstract class AbstractSimiScreen extends Screen { } } + @Deprecated + protected void debugWindowArea(MatrixStack matrixStack) { + fill(matrixStack, guiLeft + windowWidth, guiTop + windowHeight, guiLeft, guiTop, 0xD3D3D3D3); + } + } diff --git a/src/main/java/com/simibubi/create/foundation/gui/AllGuiTextures.java b/src/main/java/com/simibubi/create/foundation/gui/AllGuiTextures.java index 84197e65f..a063943d3 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/AllGuiTextures.java +++ b/src/main/java/com/simibubi/create/foundation/gui/AllGuiTextures.java @@ -60,8 +60,8 @@ public enum AllGuiTextures implements IScreenRenderable { SEQUENCER_EMPTY("sequencer.png", 0, 102, 162, 22), SEQUENCER_AWAIT("sequencer.png", 0, 160, 162, 22), - LINKED_CONTROLLER("curiosities2.png", 179, 109), - BLUEPRINT("curiosities2.png", 0, 109, 179, 109), + LINKED_CONTROLLER("curiosities_2.png", 179, 109), + BLUEPRINT("curiosities_2.png", 0, 109, 179, 109), PROJECTOR("projector.png", 235, 185), PROJECTOR_FILTER_STRENGTH("projector.png", 0, 14, 162, 22), @@ -146,4 +146,5 @@ public enum AllGuiTextures implements IScreenRenderable { bind(); UIRenderHelper.drawColoredTexture(ms, c, x, y, startX, startY, width, height); } + } diff --git a/src/main/java/com/simibubi/create/foundation/gui/GhostItemContainer.java b/src/main/java/com/simibubi/create/foundation/gui/GhostItemContainer.java index 34b710559..5c553ebce 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/GhostItemContainer.java +++ b/src/main/java/com/simibubi/create/foundation/gui/GhostItemContainer.java @@ -79,11 +79,6 @@ public abstract class GhostItemContainer extends Container implements ICleara return slotIn.inventory == playerInventory; } - @Override - public boolean canInteractWith(PlayerEntity playerIn) { - return true; - } - @Override public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, PlayerEntity player) { ItemStack held = playerInventory.getItemStack(); diff --git a/src/main/java/com/simibubi/create/foundation/gui/IInteractionChecker.java b/src/main/java/com/simibubi/create/foundation/gui/IInteractionChecker.java new file mode 100644 index 000000000..9aca72ac4 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/gui/IInteractionChecker.java @@ -0,0 +1,7 @@ +package com.simibubi.create.foundation.gui; + +import net.minecraft.entity.player.PlayerEntity; + +public interface IInteractionChecker { + boolean canPlayerUse(PlayerEntity player); +} diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagIndexScreen.java b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagIndexScreen.java index 7da30d021..ff6ae2a10 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagIndexScreen.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagIndexScreen.java @@ -181,14 +181,14 @@ public class PonderTagIndexScreen extends NavigatableSimiScreen { // stringWidth + 10, 10, false); new BoxElement().withBackground(Theme.c(Theme.Key.PONDER_BACKGROUND_FLAT)) .gradientBorder(Theme.p(Theme.Key.PONDER_IDLE)) - .at((sWidth - stringWidth) / 2f - 5, itemArea.getY() - 21, 100) + .at((windowWidth - stringWidth) / 2f - 5, itemArea.getY() - 21, 100) .withBounds(stringWidth + 10, 10) .render(ms); ms.translate(0, 0, 200); // UIRenderHelper.streak(0, itemArea.getX() - 10, itemArea.getY() - 20, 20, 180, 0x101010); - drawCenteredString(ms, textRenderer, relatedTitle, sWidth / 2, itemArea.getY() - 20, Theme.i(Theme.Key.TEXT)); + drawCenteredString(ms, textRenderer, relatedTitle, windowWidth / 2, itemArea.getY() - 20, Theme.i(Theme.Key.TEXT)); ms.translate(0, 0, -200); diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagScreen.java b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagScreen.java index 1e430d63f..3d37bd86a 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagScreen.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagScreen.java @@ -256,14 +256,14 @@ public class PonderTagScreen extends NavigatableSimiScreen { new BoxElement() .withBackground(Theme.c(Theme.Key.PONDER_BACKGROUND_FLAT)) .gradientBorder(Theme.p(Theme.Key.PONDER_IDLE)) - .at((sWidth - stringWidth) / 2f - 5, itemArea.getY() - 21, 100) + .at((windowWidth - stringWidth) / 2f - 5, itemArea.getY() - 21, 100) .withBounds(stringWidth + 10, 10) .render(ms); ms.translate(0, 0, 200); // UIRenderHelper.streak(0, itemArea.getX() - 10, itemArea.getY() - 20, 20, 180, 0x101010); - drawCenteredString(ms, textRenderer, relatedTitle, sWidth / 2, itemArea.getY() - 20, Theme.i(Theme.Key.TEXT)); + drawCenteredString(ms, textRenderer, relatedTitle, windowWidth / 2, itemArea.getY() - 20, Theme.i(Theme.Key.TEXT)); ms.translate(0,0, -200); diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java b/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java index f3dfc18f0..b25a42e2a 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java @@ -7,10 +7,12 @@ import java.util.Map; import java.util.function.Consumer; import com.simibubi.create.content.schematics.ItemRequirement; +import com.simibubi.create.foundation.gui.IInteractionChecker; import com.simibubi.create.foundation.tileEntity.behaviour.BehaviourType; import com.simibubi.create.foundation.utility.IPartialSafeNBT; import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntityType; @@ -18,7 +20,7 @@ import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.items.CapabilityItemHandler; -public abstract class SmartTileEntity extends SyncedTileEntity implements ITickableTileEntity, IPartialSafeNBT { +public abstract class SmartTileEntity extends SyncedTileEntity implements ITickableTileEntity, IPartialSafeNBT, IInteractionChecker { private final Map, TileEntityBehaviour> behaviours; // Internally maintained to be identical to behaviorMap.values() in order to improve iteration performance. @@ -201,4 +203,12 @@ public abstract class SmartTileEntity extends SyncedTileEntity implements ITicka return virtualMode; } + @Override + public boolean canPlayerUse(PlayerEntity player) { + if (world == null || world.getTileEntity(pos) != this) { + return false; + } + return player.getDistanceSq(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D) <= 64.0D; + } + } diff --git a/src/main/resources/assets/create/textures/gui/curiosities2.png b/src/main/resources/assets/create/textures/gui/curiosities_2.png similarity index 100% rename from src/main/resources/assets/create/textures/gui/curiosities2.png rename to src/main/resources/assets/create/textures/gui/curiosities_2.png