From 26e0abd46c4873ae2bd3f1b8c07396eadef53279 Mon Sep 17 00:00:00 2001 From: Alex Nijjar Date: Sat, 3 Feb 2024 02:30:27 -0600 Subject: [PATCH] Clean up GUI --- changelog.md | 12 +--------- .../chipped/client/screens/FakeLevel.java | 18 ++++++++++++-- .../client/screens/RenderWindowWidget.java | 24 +++++++++++++++---- .../client/screens/WorkbenchScreen.java | 11 +++++---- .../chipped/common/menus/WorkbenchMenu.java | 12 +++------- gradle.properties | 2 +- 6 files changed, 47 insertions(+), 32 deletions(-) diff --git a/changelog.md b/changelog.md index 7b2882ed9..2927d4a0c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,11 +1 @@ -- 1.20.4 Port. -- All workbenches can now be used to craft all blocks. Specific recipes are no longer bound to specific workbenches. -- Fixed tinted blocks like leaves having no light in the preview window. -- Added item tag translations. -- The following concrete blocks are now rotatable: - - Bolted Concrete - - Hazard Concrete - - Railed Concrete - - Reinforced Concrete - - Rusted Concrete - - Warning Concrete \ No newline at end of file +- Cleaned up GUI. \ No newline at end of file diff --git a/common/src/main/java/earth/terrarium/chipped/client/screens/FakeLevel.java b/common/src/main/java/earth/terrarium/chipped/client/screens/FakeLevel.java index deb4b4ac8..60b4da0dd 100644 --- a/common/src/main/java/earth/terrarium/chipped/client/screens/FakeLevel.java +++ b/common/src/main/java/earth/terrarium/chipped/client/screens/FakeLevel.java @@ -28,7 +28,12 @@ import java.util.Objects; import java.util.Set; -public record FakeLevel(BlockState state, Set positions) implements BlockAndTintGetter { +public class FakeLevel implements BlockAndTintGetter { + @Nullable + private BlockState state; + @Nullable + private Set positions; + public static final Vector3f SCENE_LIGHT_1 = new Vector3f(1, 0, 1); public static final Vector3f SCENE_LIGHT_2 = new Vector3f(-1, 1, -1); @@ -66,7 +71,7 @@ public BlockEntity getBlockEntity(BlockPos pos) { @Override public BlockState getBlockState(BlockPos pos) { - return positions.contains(pos) ? state : Blocks.AIR.defaultBlockState(); + return (state != null && positions != null && positions.contains(pos)) ? state : Blocks.AIR.defaultBlockState(); } @Override @@ -84,7 +89,16 @@ public int getMinBuildHeight() { return 0; } + public void setState(BlockState state) { + this.state = state; + } + + public void setPositions(Set positions) { + this.positions = positions; + } + public void renderBlock(PoseStack poseStack) { + if (state == null || positions == null) return; Minecraft mc = Minecraft.getInstance(); BlockRenderDispatcher dispatcher = mc.getBlockRenderer(); MultiBufferSource.BufferSource bufferSource = mc.renderBuffers().bufferSource(); diff --git a/common/src/main/java/earth/terrarium/chipped/client/screens/RenderWindowWidget.java b/common/src/main/java/earth/terrarium/chipped/client/screens/RenderWindowWidget.java index ee655e6fa..0c1393773 100644 --- a/common/src/main/java/earth/terrarium/chipped/client/screens/RenderWindowWidget.java +++ b/common/src/main/java/earth/terrarium/chipped/client/screens/RenderWindowWidget.java @@ -2,6 +2,8 @@ import com.mojang.math.Axis; import com.teamresourceful.resourcefullib.client.CloseablePoseStack; +import com.teamresourceful.resourcefullib.client.components.CursorWidget; +import com.teamresourceful.resourcefullib.client.screens.CursorScreen; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.narration.NarrationElementOutput; @@ -15,16 +17,19 @@ import java.util.Set; import java.util.function.Supplier; -public class RenderWindowWidget extends AbstractWidget { +public class RenderWindowWidget extends AbstractWidget implements CursorWidget { public static final BlockPos ORIGIN = BlockPos.ZERO; public static final BlockPos NORTH = BlockPos.ZERO.north(); public static final BlockPos NORTH_UP = BlockPos.ZERO.north().above(); public static final BlockPos SOUTH = BlockPos.ZERO.south(); public static final BlockPos UP = BlockPos.ZERO.above(); public static final BlockPos DOWN = BlockPos.ZERO.below(); + private static final Set DOOR_POSITIONS_BOTTOM = Set.of(ORIGIN); + private static final Set DOOR_POSITIONS_TOP = Set.of(UP); private final Supplier mode; private final Supplier<@Nullable BlockState> state; + private final FakeLevel fakeLevel = new FakeLevel(); public RenderWindowWidget(int x, int y, int width, int height, Supplier mode, Supplier state) { super(x, y, width, height, CommonComponents.EMPTY); @@ -54,12 +59,16 @@ protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float pose.mulPose(Axis.YP.rotationDegrees(45)); pose.translate(-0.5, -0.5, -0.5); + fakeLevel.setState(state); if (isDoor) { - new FakeLevel(state, Set.of(ORIGIN)).renderBlock(pose); - new FakeLevel(state.setValue(DoorBlock.HALF, DoubleBlockHalf.UPPER), Set.of(UP)).renderBlock(pose); + fakeLevel.setPositions(DOOR_POSITIONS_BOTTOM); + fakeLevel.renderBlock(pose); + fakeLevel.setState(state.setValue(DoorBlock.HALF, DoubleBlockHalf.UPPER)); + fakeLevel.setPositions(DOOR_POSITIONS_TOP); + fakeLevel.renderBlock(pose); } else { - FakeLevel level = new FakeLevel(state, mode.positions); - level.renderBlock(pose); + fakeLevel.setPositions(mode.positions); + fakeLevel.renderBlock(pose); } } } @@ -72,6 +81,11 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { @Override protected void updateWidgetNarration(NarrationElementOutput narrationElementOutput) {} + @Override + public CursorScreen.Cursor getCursor() { + return CursorScreen.Cursor.DEFAULT; + } + public enum Mode { SINGLE_BLOCK(0, 0, ORIGIN), HORIZONTAL_BLOCK(0, 0, ORIGIN, NORTH, SOUTH), diff --git a/common/src/main/java/earth/terrarium/chipped/client/screens/WorkbenchScreen.java b/common/src/main/java/earth/terrarium/chipped/client/screens/WorkbenchScreen.java index 567d1a3b4..95cbb2937 100644 --- a/common/src/main/java/earth/terrarium/chipped/client/screens/WorkbenchScreen.java +++ b/common/src/main/java/earth/terrarium/chipped/client/screens/WorkbenchScreen.java @@ -60,6 +60,7 @@ public class WorkbenchScreen extends AbstractContainerCursorScreen { + .getRecipeFor(ModRecipeTypes.WORKBENCH.get(), container, level).ifPresentOrElse(recipe -> { results.clear(); recipe.value().getResults(container.getItem(0)).forEach(result -> { if (filter == null @@ -98,7 +96,7 @@ public void updateResults(@Nullable String filter) { results.add(result); } }); - }); + }, this::reset); } public void craft(ItemStack stack, boolean replaceAll) { @@ -148,10 +146,6 @@ public List results() { return results; } - public Player player() { - return player; - } - public Level level() { return level; } diff --git a/gradle.properties b/gradle.properties index 0705e4d55..74846a42e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx2G enabledPlatforms=fabric,neoforge -version=3.1.0 +version=3.1.1 group=earth.terrarium.chipped minecraftVersion=1.20.4