Skip to content

Commit

Permalink
feat: add timer IC gate
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTJP committed Apr 3, 2024
1 parent 3d4e796 commit 8b1ff30
Show file tree
Hide file tree
Showing 14 changed files with 375 additions and 16 deletions.
13 changes: 9 additions & 4 deletions core/src/main/java/mrtjp/projectred/redui/RedUINode.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import mrtjp.projectred.lib.Point;
import mrtjp.projectred.lib.Rect;
import mrtjp.projectred.lib.Size;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.network.chat.Component;
import org.lwjgl.glfw.GLFW;
Expand Down Expand Up @@ -566,7 +567,8 @@ default boolean operateOnZOrderedSubtree(Point p, SubtreeOp op, boolean consumed
* </ul>
* @param stack The matrix stack that is translated to the parent
* @param mouse Current mouse position, relative to the parent
* @param partialFrame Partial frames between ticks
* @param partialFrame Progress between frames ({@link Minecraft#getDeltaFrameTime()}).
* This is *not* the same as {@link Minecraft#getPartialTick()}
*/
default void renderBackForSubtree(PoseStack stack, Point mouse, float partialFrame) {
drawBack(stack, mouse, partialFrame);
Expand Down Expand Up @@ -630,7 +632,8 @@ default void update() { }
* Called once per render call prior to rendering the background via {@link RedUINode#drawBack(PoseStack, Point, float)}
*
* @param mouse Mouse position in parent's coordinate space
* @param partialFrame Partial value representing the progress from one tick to the next
* @param partialFrame Progress between frames ({@link Minecraft#getDeltaFrameTime()}).
* This is *not* the same as {@link Minecraft#getPartialTick()}
*/
default void frameUpdate(Point mouse, float partialFrame) { }

Expand Down Expand Up @@ -748,7 +751,8 @@ default void onSubTreePostDrawFront() { }
*
* @param stack The matrix stack that is translated to the parent
* @param mouse Current mouse position, relative to the parent
* @param partialFrame Partial frames between ticks
* @param partialFrame Progress between frames ({@link Minecraft#getDeltaFrameTime()}).
* This is *not* the same as {@link Minecraft#getPartialTick()}
*/
default void drawBack(PoseStack stack, Point mouse, float partialFrame) { }

Expand All @@ -757,7 +761,8 @@ default void drawBack(PoseStack stack, Point mouse, float partialFrame) { }
*
* @param stack The matrix stack that is translated to the parent
* @param mouse Current mouse position, relative to the parent
* @param partialFrame Partial frames between ticks
* @param partialFrame Progress between frames ({@link Minecraft#getDeltaFrameTime()}).
* This is *not* the same as {@link Minecraft#getPartialTick()}
*/
default void drawFront(PoseStack stack, Point mouse, float partialFrame) { }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.19.2 2024-04-02T23:47:28.462179 ProjectRed-Fabrication Languages: en_us
6ef2e9d1acc882a99a3807c2b1eeb8b406d3dcdf assets/projectred_fabrication/lang/en_us.json
// 1.19.2 2024-04-03T14:34:15.996265 ProjectRed-Fabrication Languages: en_us
185f10b0a3ebb21bb94ee65a6e1180c345526012 assets/projectred_fabrication/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"projectred_fabrication.tilegroup.redwire": "Redwire",
"projectred_fabrication.tilegroup.timing": "Timing",
"projectred_fabrication.tiles.io_gate": "IO Gate",
"projectred_fabrication.tiles.timer.interval": "Interval",
"projectred_fabrication.tool.eraser": "Erase",
"projectred_fabrication.tool.gates": "Gates",
"projectred_fabrication.tool.interact": "Interact",
Expand Down Expand Up @@ -108,5 +109,6 @@
"projectred_fabrication.ui.yield_calculator": "Yield Calculator",
"projectred_fabrication.unit.errors": "%d errors",
"projectred_fabrication.unit.ticks": "%d ticks",
"projectred_fabrication.unit.warnings": "%d warnings"
"projectred_fabrication.unit.warnings": "%d warnings",
"projectred_fabrication.unit_only.ticks": "ticks"
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ protected void addTranslations() {
add(UL_FAB_ERR_GENERIC, "Cannot fabricate");

add(UL_IO_GATE_TILE, "IO Gate");
add(UL_TIMER_INTERVAL, "Interval");

add(UL_TILEGROUP_REDWIRE, "Redwire");
add(UL_TILEGROUP_BUNDLED, "Bundled");
Expand All @@ -148,5 +149,7 @@ protected void addTranslations() {
add(UL_DIMENSIONS_NM_TOTAL, "%d nm x %d nm (%d nm^2)");
add(UL_DIMENSIONS_TILES_TOTAL, "%d tiles x %d tiles (%d tiles^2)");
add(UL_DIMENSIONS_DIES_TOTAL, "%d dies x %d dies (%d dies^2)");

add(UL_UNIT_ONLY_TICKS, "ticks");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ public void onTick(long time) {
assembler = null; //TODO make assemblers clearable
lastCompiledFormat = PRFabricationEngine.COMPILE_FORMAT;
lastCompiledFlatMap = PRFabricationEngine.instance.serializeFlatMap(map);
simulationContainer.setSystemTime(0);
simulationContainer.setFlatMap(map);

if (compilerLog.getErrorCount() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import javax.annotation.Nullable;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
Expand All @@ -25,6 +26,7 @@ public class SimpleInteractionZone implements InteractionZone {
private final int highlightColor;
private final int boundingBoxColor;
private final double boundingBoxLineWidth;
@Nullable private final Component text;

private SimpleInteractionZone(Builder builder) {
this.boundsSupplier = builder.boundsSupplier;
Expand All @@ -34,6 +36,7 @@ private SimpleInteractionZone(Builder builder) {
this.highlightColor = builder.highlightColor;
this.boundingBoxColor = builder.boundingBoxColor;
this.boundingBoxLineWidth = builder.boundingBoxLineWidth;
this.text = builder.text;
}

@Override
Expand Down Expand Up @@ -65,16 +68,22 @@ public boolean onKeyPressed(int glfwKeyCode, int glfwFlags) {
@Override
@OnlyIn(Dist.CLIENT)
public void renderZone(CCRenderState ccrs, MultiBufferSource getter, PoseStack poseStack, boolean isSelected, boolean isMouseOver) {
Cuboid6 bounds = getBounds();

ccrs.reset();
ccrs.bind(ICRenderTypes.selectionRenderType, getter, poseStack);
ccrs.baseColour = highlightColor;
ccrs.alphaOverride = isSelected && isMouseOver ? 255 : isSelected ? 128 : isMouseOver ? 64 : 32;
BlockRenderer.renderCuboid(ccrs, getBounds(), 1);
BlockRenderer.renderCuboid(ccrs, bounds, 1);

ccrs.reset();
ccrs.bind(ICRenderTypes.interactionZoneLinesRenderType.apply(boundingBoxLineWidth), getter, poseStack);
ccrs.baseColour = boundingBoxColor;
RenderUtils.bufferCuboidOutline(ccrs.getConsumer(), getBounds(), 1, 1, 1, 1);
RenderUtils.bufferCuboidOutline(ccrs.getConsumer(), bounds, 1, 1, 1, 1);

if (text != null) {
ICRenderTypes.renderCenteredTextTopOfCuboid(text, bounds, poseStack, getter);
}
}

public static class Builder {
Expand All @@ -86,6 +95,7 @@ public static class Builder {
private int highlightColor = EnumColour.LIGHT_BLUE.rgba();
private int boundingBoxColor = EnumColour.WHITE.rgba();
private double boundingBoxLineWidth = 4.0;
@Nullable private Component text;

public Builder bounds(Supplier<Cuboid6> boundsSupplier) {
this.boundsSupplier = boundsSupplier;
Expand Down Expand Up @@ -137,6 +147,11 @@ public Builder boundingBoxLineWidth(double width) {
return this;
}

public Builder text(Component text) {
this.text = text;
return this;
}

public SimpleInteractionZone build() {
return new SimpleInteractionZone(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum ICTileType {
SR_LATCH_GATE (ID_OFFSET_GATE + 12, SR_LATCH, SRLatchGateTile::new),
TOGGLE_LATCH_GATE (ID_OFFSET_GATE + 13, TOGGLE_LATCH, ToggleLatchGateTile::new),
TRANSPARENT_LATCH_GATE(ID_OFFSET_GATE + 14, TRANSPARENT_LATCH, TransparentLatchGateTile::new),
TIMER_GATE (ID_OFFSET_GATE + 15, TIMER, TimerGateTile::new),

RED_ALLOY_WIRE (ID_OFFSET_WIRE_RED, RED_ALLOY, RedAlloyWireTile::new),
INSULATED_WHITE_WIRE (ID_OFFSET_WIRE_RED + 1, INSULATED_WHITE, () -> new InsulatedWireTile(0)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public Map<Class<? extends ICGate>, String> getGateSerializationMap() {
map.put(SRLatchGateTile.SRLatchGate.class, "pr_srlatch");
map.put(ToggleLatchGateTile.ToggleLatchGate.class, "pr_tglatch");
map.put(TransparentLatchGateTile.TransparentLatchGate.class, "pr_trlatch");
map.put(TimerGateTile.TimerGate.class, "pr_timer");

return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public enum ICGateTileType {
RANDOMIZER(ICTileType.RANDOMIZER_GATE, GateModelRenderer.getRenderIndex(GateType.RANDOMIZER)),
SR_LATCH(ICTileType.SR_LATCH_GATE, GateModelRenderer.getRenderIndex(GateType.SR_LATCH)),
TOGGLE_LATCH(ICTileType.TOGGLE_LATCH_GATE, GateModelRenderer.getRenderIndex(GateType.TOGGLE_LATCH)),
TRANSPARENT_LATCH(ICTileType.TRANSPARENT_LATCH_GATE, GateModelRenderer.getRenderIndex(GateType.TRANSPARENT_LATCH));
TRANSPARENT_LATCH(ICTileType.TRANSPARENT_LATCH_GATE, GateModelRenderer.getRenderIndex(GateType.TRANSPARENT_LATCH)),
TIMER(ICTileType.TIMER_GATE, GateModelRenderer.getRenderIndex(GateType.TIMER));

public final ICTileType tileType;
public final int renderIndex;
Expand Down
Loading

0 comments on commit 8b1ff30

Please sign in to comment.