-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
286 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# Changelog | ||
|
||
## [1.4.0] | ||
- Add custom render elements | ||
|
||
## [1.3.1] | ||
- Fix crash with new kubejs version | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/com/almostreliable/ponderjs/api/CustomPonderOverlayElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.almostreliable.ponderjs.api; | ||
|
||
import com.simibubi.create.foundation.ponder.PonderScene; | ||
import com.simibubi.create.foundation.ponder.element.AnimatedOverlayElement; | ||
import com.simibubi.create.foundation.ponder.ui.PonderUI; | ||
import dev.latvian.mods.rhino.util.HideFromJS; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
|
||
public class CustomPonderOverlayElement extends AnimatedOverlayElement { | ||
protected OnRenderOverlay onRender = (ctx) -> {}; | ||
protected OnElementAction onWhileSkipping = (ctx) -> {}; | ||
protected OnElementAction onTick = (ctx) -> {}; | ||
protected OnElementAction onReset = (ctx) -> {}; | ||
private int currentTick = 0; | ||
|
||
public int getCurrentTick() { | ||
return currentTick; | ||
} | ||
|
||
public CustomPonderOverlayElement onSkipping(OnElementAction onWhileSkipping) { | ||
this.onWhileSkipping = onWhileSkipping; | ||
return this; | ||
} | ||
|
||
public CustomPonderOverlayElement onTick(OnElementAction onTick) { | ||
this.onTick = onTick; | ||
return this; | ||
} | ||
|
||
public CustomPonderOverlayElement onReset(OnElementAction onReset) { | ||
this.onReset = onReset; | ||
return this; | ||
} | ||
|
||
public CustomPonderOverlayElement onRender(OnRenderOverlay onRender) { | ||
this.onRender = onRender; | ||
return this; | ||
} | ||
|
||
@Override | ||
public void whileSkipping(PonderScene scene) { | ||
super.whileSkipping(scene); | ||
onWhileSkipping.accept(new OnElementAction.Context(this, scene)); | ||
} | ||
|
||
@Override | ||
public void tick(PonderScene scene) { | ||
super.tick(scene); | ||
currentTick++; | ||
onTick.accept(new OnElementAction.Context(this, scene)); | ||
} | ||
|
||
@Override | ||
public void reset(PonderScene scene) { | ||
super.reset(scene); | ||
currentTick = 0; | ||
onReset.accept(new OnElementAction.Context(this, scene)); | ||
} | ||
|
||
@HideFromJS | ||
@Override | ||
protected void render(PonderScene scene, PonderUI screen, GuiGraphics graphics, float partialTicks, float fade) { | ||
var ctx = new OnRenderOverlay.RenderContext(this, scene, screen, graphics, partialTicks, fade); | ||
onRender.render(ctx); | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/main/java/com/almostreliable/ponderjs/api/CustomPonderSceneElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.almostreliable.ponderjs.api; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.simibubi.create.foundation.ponder.PonderScene; | ||
import com.simibubi.create.foundation.ponder.PonderWorld; | ||
import com.simibubi.create.foundation.ponder.element.AnimatedSceneElement; | ||
import dev.latvian.mods.rhino.util.HideFromJS; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.client.renderer.RenderType; | ||
|
||
public class CustomPonderSceneElement extends AnimatedSceneElement { | ||
protected OnRenderWorld onRenderFirst = (ctx) -> {}; | ||
protected OnRenderWorld.Layer onRenderWorldLayer = (ctx) -> {}; | ||
protected OnRenderWorld onRenderLast = (ctx) -> {}; | ||
protected OnElementAction onWhileSkipping = (ctx) -> {}; | ||
protected OnElementAction onTick = (ctx) -> {}; | ||
protected OnElementAction onReset = (ctx) -> {}; | ||
private int currentTick = 0; | ||
|
||
public int getCurrentTick() { | ||
return currentTick; | ||
} | ||
|
||
public CustomPonderSceneElement onSkipping(OnElementAction onWhileSkipping) { | ||
this.onWhileSkipping = onWhileSkipping; | ||
return this; | ||
} | ||
|
||
public CustomPonderSceneElement onTick(OnElementAction onTick) { | ||
this.onTick = onTick; | ||
return this; | ||
} | ||
|
||
public CustomPonderSceneElement onReset(OnElementAction onReset) { | ||
this.onReset = onReset; | ||
return this; | ||
} | ||
|
||
public CustomPonderSceneElement onRenderFirst(OnRenderWorld onRenderWorld) { | ||
this.onRenderFirst = onRenderWorld; | ||
return this; | ||
} | ||
|
||
public CustomPonderSceneElement onRender(OnRenderWorld.Layer onRenderWorldLayer) { | ||
this.onRenderWorldLayer = onRenderWorldLayer; | ||
return this; | ||
} | ||
|
||
public CustomPonderSceneElement onRenderLast(OnRenderWorld onRenderWorld) { | ||
this.onRenderLast = onRenderWorld; | ||
return this; | ||
} | ||
|
||
@Override | ||
public void whileSkipping(PonderScene scene) { | ||
super.whileSkipping(scene); | ||
onWhileSkipping.accept(new OnElementAction.Context(this, scene)); | ||
} | ||
|
||
@Override | ||
public void tick(PonderScene scene) { | ||
super.tick(scene); | ||
currentTick++; | ||
onTick.accept(new OnElementAction.Context(this, scene)); | ||
} | ||
|
||
@Override | ||
public void reset(PonderScene scene) { | ||
super.reset(scene); | ||
currentTick = 0; | ||
onReset.accept(new OnElementAction.Context(this, scene)); | ||
} | ||
|
||
@HideFromJS | ||
@Override | ||
public void renderFirst(PonderWorld world, MultiBufferSource buffer, PoseStack ms, float fade, float pt) { | ||
super.renderFirst(world, buffer, ms, fade, pt); | ||
var ctx = new OnRenderWorld.RenderContext(this, world, buffer, ms, pt, fade); | ||
onRenderFirst.renderWorld(ctx); | ||
} | ||
|
||
@HideFromJS | ||
@Override | ||
public void renderLayer(PonderWorld world, MultiBufferSource buffer, RenderType type, PoseStack ms, float fade, float pt) { | ||
super.renderLayer(world, buffer, type, ms, fade, pt); | ||
var ctx = new OnRenderWorld.Layer.RenderContext(this, world, buffer, type, ms, pt, fade); | ||
onRenderWorldLayer.renderLayer(ctx); | ||
} | ||
|
||
@HideFromJS | ||
@Override | ||
public void renderLast(PonderWorld world, MultiBufferSource buffer, PoseStack ms, float fade, float pt) { | ||
super.renderLast(world, buffer, ms, fade, pt); | ||
var ctx = new OnRenderWorld.RenderContext(this, world, buffer, ms, pt, fade); | ||
onRenderLast.renderWorld(ctx); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/almostreliable/ponderjs/api/OnElementAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.almostreliable.ponderjs.api; | ||
|
||
import com.simibubi.create.foundation.ponder.PonderScene; | ||
import com.simibubi.create.foundation.ponder.element.PonderElement; | ||
|
||
@FunctionalInterface | ||
public interface OnElementAction { | ||
|
||
void accept(Context context); | ||
|
||
record Context(PonderElement getElement, PonderScene getScene) {} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/almostreliable/ponderjs/api/OnRenderOverlay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.almostreliable.ponderjs.api; | ||
|
||
import com.simibubi.create.foundation.ponder.PonderScene; | ||
import com.simibubi.create.foundation.ponder.element.PonderOverlayElement; | ||
import com.simibubi.create.foundation.ponder.ui.PonderUI; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
|
||
@FunctionalInterface | ||
public interface OnRenderOverlay { | ||
|
||
void render(RenderContext context); | ||
|
||
record RenderContext(PonderOverlayElement getElement, PonderScene getScene, PonderUI getScreen, | ||
GuiGraphics getGraphics, float getPartialTicks, float getFade) {} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/almostreliable/ponderjs/api/OnRenderWorld.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.almostreliable.ponderjs.api; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.simibubi.create.foundation.ponder.PonderWorld; | ||
import com.simibubi.create.foundation.ponder.element.PonderElement; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.client.renderer.RenderType; | ||
|
||
@FunctionalInterface | ||
public interface OnRenderWorld { | ||
|
||
void renderWorld(RenderContext context); | ||
|
||
@FunctionalInterface | ||
interface Layer { | ||
void renderLayer(RenderContext context); | ||
|
||
record RenderContext(PonderElement getElement, PonderWorld getWorld, MultiBufferSource getBuffer, | ||
RenderType getType, PoseStack getPoseStack, float getPartialTicks, float getFade) {} | ||
} | ||
|
||
|
||
record RenderContext(PonderElement getElement, PonderWorld getWorld, MultiBufferSource getBuffer, | ||
PoseStack getPoseStack, float getPartialTicks, float getFade) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters