Skip to content

Commit

Permalink
Clean up GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNijjar committed Feb 3, 2024
1 parent df3f6ba commit 26e0abd
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 32 deletions.
12 changes: 1 addition & 11 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
- Cleaned up GUI.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
import java.util.Objects;
import java.util.Set;

public record FakeLevel(BlockState state, Set<BlockPos> positions) implements BlockAndTintGetter {
public class FakeLevel implements BlockAndTintGetter {
@Nullable
private BlockState state;
@Nullable
private Set<BlockPos> 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);

Expand Down Expand Up @@ -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
Expand All @@ -84,7 +89,16 @@ public int getMinBuildHeight() {
return 0;
}

public void setState(BlockState state) {
this.state = state;
}

public void setPositions(Set<BlockPos> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<BlockPos> DOOR_POSITIONS_BOTTOM = Set.of(ORIGIN);
private static final Set<BlockPos> DOOR_POSITIONS_TOP = Set.of(UP);

private final Supplier<Mode> 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> mode, Supplier<BlockState> state) {
super(x, y, width, height, CommonComponents.EMPTY);
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class WorkbenchScreen extends AbstractContainerCursorScreen<WorkbenchMenu

public static final int YELLOW = 0x70FFFF00;
public static final int BLUE = 0x700000FF;
public static final int DARK_GRAY = 0x70000000;

private static final Component PREVIEW_TEXT = Component.translatable("text.chipped.preview");
private static final Component CRAFT_TEXT = Component.translatable("text.chipped.craft");
Expand Down Expand Up @@ -91,7 +92,7 @@ public WorkbenchScreen(WorkbenchMenu container, Inventory inventory, Component t
protected void init() {
super.init();

searchBox = addRenderableWidget(new EditBox(font, leftPos + 104, topPos + 27, 115, 11, Component.empty()));
searchBox = addRenderableWidget(new EditBox(font, leftPos + 105, topPos + 27, 115, 11, Component.empty()));
searchBox.setCanLoseFocus(false);
searchBox.setTextColor(-1);
searchBox.setTextColorUneditable(-1);
Expand Down Expand Up @@ -193,9 +194,11 @@ protected void renderBg(GuiGraphics graphics, float partialTick, int mouseX, int
if (selectedStack.isEmpty()) return;
for (var slot : menu.slots) {
if (selectedStack.equals(slot.getItem()) || (ItemStack.isSameItem(selectedStack, slot.getItem()) && hasShiftDown())) {
graphics.fill(slot.x + left - 1, slot.y + 6, slot.x + left + 17, slot.y + 24, YELLOW);
graphics.fill(slot.x + left - 1, slot.y + top - 1, slot.x + left + 17, slot.y + top + 17, YELLOW);
} else if (ItemStack.isSameItem(selectedStack, slot.getItem())) {
graphics.fill(slot.x + left - 1, slot.y + 6, slot.x + left + 17, slot.y + 24, BLUE);
graphics.fill(slot.x + left - 1, slot.y + top - 1, slot.x + left + 17, slot.y + top + 17, BLUE);
} else {
graphics.fill(slot.x + left - 1, slot.y + top - 1, slot.x + left + 17, slot.y + top + 17, DARK_GRAY);
}
}
}
Expand All @@ -218,7 +221,7 @@ protected void slotClicked(Slot slot, int slotId, int mouseButton, ClickType typ
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == GLFW.GLFW_KEY_ESCAPE) {
menu.player().closeContainer();
onClose();
}

setFocused(searchBox);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

public class WorkbenchMenu extends AbstractContainerMenu {
protected final Inventory inventory;
protected final Player player;
protected final Level level;

private int selectedStackId;
Expand All @@ -34,8 +33,7 @@ public class WorkbenchMenu extends AbstractContainerMenu {
public WorkbenchMenu(int containerId, Inventory inventory) {
super(ModMenuTypes.WORKBENCH.get(), containerId);
this.inventory = inventory;
this.player = inventory.player;
this.level = player.level();
this.level = inventory.player.level();
addPlayerInvSlots();
}

Expand Down Expand Up @@ -89,7 +87,7 @@ public void updateResults(@Nullable String filter) {
this.filter = filter;
SimpleContainer container = new SimpleContainer(selectedStack);
level.getRecipeManager()
.getRecipeFor(ModRecipeTypes.WORKBENCH.get(), container, level).ifPresent(recipe -> {
.getRecipeFor(ModRecipeTypes.WORKBENCH.get(), container, level).ifPresentOrElse(recipe -> {
results.clear();
recipe.value().getResults(container.getItem(0)).forEach(result -> {
if (filter == null
Expand All @@ -98,7 +96,7 @@ public void updateResults(@Nullable String filter) {
results.add(result);
}
});
});
}, this::reset);
}

public void craft(ItemStack stack, boolean replaceAll) {
Expand Down Expand Up @@ -148,10 +146,6 @@ public List<ItemStack> results() {
return results;
}

public Player player() {
return player;
}

public Level level() {
return level;
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 26e0abd

Please sign in to comment.