-
Notifications
You must be signed in to change notification settings - Fork 11
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
1 parent
d362070
commit 918c19a
Showing
3 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
src/main/java/net/zepalesque/redux/client/event/listener/RenderListener.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,4 @@ | ||
package net.zepalesque.redux.client.event.listener; | ||
|
||
public class RenderListener { | ||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/net/zepalesque/redux/client/renderer/api/ICachedRerender.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,63 @@ | ||
package net.zepalesque.redux.client.renderer.api; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.world.entity.Entity; | ||
import net.zepalesque.zenith.util.lambda.Consumers; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public interface ICachedRerender<T extends Entity> { | ||
|
||
default boolean actuallyRender() { | ||
Cache<T> cache = this.getCache(); | ||
boolean success = cache.execute(this::internalRender); | ||
if (success) { | ||
cache.clear(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
Cache<T> getCache(); | ||
|
||
void internalRender(@NotNull T entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight); | ||
|
||
class Cache<T extends Entity> { | ||
|
||
private T entity; | ||
private float entityYaw, partialTicks; | ||
private PoseStack poseStack; | ||
private MultiBufferSource buffer; | ||
private int packedLight; | ||
private boolean cached = false; | ||
|
||
public Cache() {} | ||
|
||
public void cache(@NotNull T entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) { | ||
this.entity = entity; | ||
this.entityYaw = entityYaw; | ||
this.partialTicks = partialTicks; | ||
this.poseStack = poseStack; | ||
this.buffer = buffer; | ||
this.packedLight = packedLight; | ||
this.cached = true; | ||
} | ||
|
||
public void clear() { | ||
this.entity = null; | ||
this.entityYaw = Float.NaN; | ||
this.partialTicks = Float.NaN; | ||
this.poseStack = null; | ||
this.buffer = null; | ||
this.packedLight = Integer.MIN_VALUE; | ||
this.cached = false; | ||
} | ||
|
||
public boolean execute(Consumers.C6<T, Float, Float, PoseStack, MultiBufferSource, Integer> method) { | ||
if (this.cached) { | ||
method.accept(this.entity, this.entityYaw, this.partialTicks, this.poseStack, this.buffer, this.packedLight); | ||
return true; | ||
} else return false; | ||
} | ||
} | ||
} |
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