forked from KosmX/bendy-lib
-
Notifications
You must be signed in to change notification settings - Fork 1
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
4f0f248
commit 0c68f3f
Showing
11 changed files
with
230 additions
and
11 deletions.
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
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
common/src/main/java/io/github/kosmx/bendylib/compat/sodium/ModelCuboidAccessor.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 io.github.kosmx.bendylib.compat.sodium; | ||
|
||
import net.minecraft.client.model.ModelPart; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.util.Pair; | ||
|
||
public interface ModelCuboidAccessor { | ||
boolean isHackedByEmoteCraft(); | ||
|
||
ModelPart.Cuboid getOriginal(); | ||
void setOriginal(ModelPart.Cuboid cuboid); | ||
} |
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
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
23 changes: 23 additions & 0 deletions
23
common/src/main/java/io/github/kosmx/bendylib/mixin/sodium/CuboidMixin.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,23 @@ | ||
package io.github.kosmx.bendylib.mixin.sodium; | ||
|
||
import io.github.kosmx.bendylib.compat.sodium.ModelCuboidAccessor; | ||
import me.jellysquid.mods.sodium.client.render.immediate.model.ModelCuboid; | ||
import net.minecraft.client.model.ModelPart; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(ModelPart.Cuboid.class) | ||
public class CuboidMixin { | ||
@Inject( | ||
method = "sodium$copy", | ||
at = @At( | ||
value = "RETURN" | ||
) | ||
) | ||
public void sodium$copy(CallbackInfoReturnable<ModelCuboid> cir) { | ||
((ModelCuboidAccessor) cir.getReturnValue()) | ||
.setOriginal((ModelPart.Cuboid) (Object) this); | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
common/src/main/java/io/github/kosmx/bendylib/mixin/sodium/EntityRendererMixin.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,110 @@ | ||
package io.github.kosmx.bendylib.mixin.sodium; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import io.github.kosmx.bendylib.ModelPartAccessor; | ||
import io.github.kosmx.bendylib.compat.sodium.ModelCuboidAccessor; | ||
import io.github.kosmx.bendylib.impl.accessors.CuboidSideAccessor; | ||
import io.github.kosmx.bendylib.impl.accessors.IModelPartAccessor; | ||
import me.jellysquid.mods.sodium.client.render.immediate.model.EntityRenderer; | ||
import me.jellysquid.mods.sodium.client.render.immediate.model.ModelCuboid; | ||
import net.caffeinemc.mods.sodium.api.util.ColorABGR; | ||
import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; | ||
import net.caffeinemc.mods.sodium.api.vertex.format.common.ModelVertex; | ||
import net.minecraft.client.model.ModelPart; | ||
import net.minecraft.client.render.VertexConsumer; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.lwjgl.system.MemoryStack; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(EntityRenderer.class) | ||
public abstract class EntityRendererMixin { | ||
@Shadow | ||
private static void prepareNormals(MatrixStack.Entry matrices) { | ||
} | ||
|
||
@Shadow | ||
private static void prepareVertices(MatrixStack.Entry matrices, ModelCuboid cuboid) { | ||
} | ||
|
||
@Shadow | ||
private static int emitQuads(ModelCuboid cuboid, int color, int overlay, int light) { | ||
return 0; | ||
} | ||
|
||
@Shadow @Final private static long SCRATCH_BUFFER; | ||
|
||
@Unique | ||
private static VertexConsumer getVertexConsumer = null; | ||
|
||
@Redirect( | ||
method = "render", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lme/jellysquid/mods/sodium/client/render/immediate/model/EntityRenderer;renderCuboids(Lnet/minecraft/client/util/math/MatrixStack$Entry;Lnet/caffeinemc/mods/sodium/api/vertex/buffer/VertexBufferWriter;[Lme/jellysquid/mods/sodium/client/render/immediate/model/ModelCuboid;III)V" | ||
) | ||
) | ||
private static void redirectRenderCuboids(MatrixStack.Entry matrices, VertexBufferWriter writer, ModelCuboid[] cuboids, int light, int overlay, int color, @Local(argsOnly = true) ModelPart modelPart) { | ||
IModelPartAccessor accessor = (IModelPartAccessor) modelPart; | ||
ModelPartAccessor.Workaround workaround = accessor.getWorkaround(); | ||
|
||
getVertexConsumer = accessor.getVertexConsumer(); | ||
|
||
LogManager.getLogger().info(getVertexConsumer); | ||
|
||
if(workaround == ModelPartAccessor.Workaround.ExportQuads){ // Unchecked | ||
for (ModelCuboid cuboid : cuboids) { | ||
((CuboidSideAccessor) ((ModelCuboidAccessor) cuboid).getOriginal()).doSideSwapping(); //:D | ||
} | ||
|
||
renderCuboids(matrices, writer, cuboids, light, overlay, color); | ||
|
||
for(ModelCuboid cuboid : cuboids){ | ||
((CuboidSideAccessor) ((ModelCuboidAccessor) cuboid).getOriginal()).resetSides(); //:D | ||
} | ||
} else if(workaround == ModelPartAccessor.Workaround.VanillaDraw){ | ||
if(!accessor.hasMutatedCuboid() || cuboids.length == 1 && !((ModelCuboidAccessor) cuboids[0]).isHackedByEmoteCraft()) { | ||
renderCuboids(matrices, writer, cuboids, light, overlay, color); | ||
} | ||
else { | ||
for (ModelCuboid cuboid : cuboids) { | ||
((ModelCuboidAccessor) cuboid).getOriginal() | ||
.renderCuboid(matrices, getVertexConsumer, light, overlay, ColorABGR.unpackRed(color), ColorABGR.unpackGreen(color), ColorABGR.unpackBlue(color), ColorABGR.unpackAlpha(color)); | ||
} | ||
} | ||
} else { | ||
renderCuboids(matrices, writer, cuboids, light, overlay, color); | ||
} | ||
} | ||
|
||
/** | ||
* @author dima_dencep | ||
* @reason fix bend | ||
*/ | ||
@Overwrite | ||
private static void renderCuboids(MatrixStack.Entry matrices, VertexBufferWriter writer, ModelCuboid[] cuboids, int light, int overlay, int color) { | ||
prepareNormals(matrices); | ||
|
||
for (ModelCuboid cuboid : cuboids) { | ||
|
||
if (cuboid instanceof ModelCuboidAccessor accessor && accessor.isHackedByEmoteCraft()) { | ||
accessor.getOriginal() | ||
.renderCuboid(matrices, getVertexConsumer, light, overlay, ColorABGR.unpackRed(color), ColorABGR.unpackGreen(color), ColorABGR.unpackBlue(color), ColorABGR.unpackAlpha(color)); | ||
} else { | ||
prepareVertices(matrices, cuboid); | ||
|
||
var vertexCount = emitQuads(cuboid, color, overlay, light); | ||
|
||
try (MemoryStack stack = MemoryStack.stackPush()) { | ||
writer.push(stack, SCRATCH_BUFFER, vertexCount, ModelVertex.FORMAT); | ||
} | ||
} | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
common/src/main/java/io/github/kosmx/bendylib/mixin/sodium/ModelCuboidMixin.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,34 @@ | ||
package io.github.kosmx.bendylib.mixin.sodium; | ||
|
||
import io.github.kosmx.bendylib.MutableCuboid; | ||
import io.github.kosmx.bendylib.compat.sodium.ModelCuboidAccessor; | ||
import me.jellysquid.mods.sodium.client.render.immediate.model.ModelCuboid; | ||
import net.minecraft.client.model.ModelPart; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.util.Pair; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
@Mixin(ModelCuboid.class) | ||
public class ModelCuboidMixin implements ModelCuboidAccessor { | ||
@Unique | ||
public ModelPart.Cuboid orgiginal; | ||
|
||
@Override | ||
public boolean isHackedByEmoteCraft() { | ||
if (!(orgiginal instanceof MutableCuboid mutableCuboid)) | ||
return false; | ||
|
||
return mutableCuboid.getActiveMutator() != null; | ||
} | ||
|
||
@Override | ||
public ModelPart.Cuboid getOriginal() { | ||
return orgiginal; | ||
} | ||
|
||
@Override | ||
public void setOriginal(ModelPart.Cuboid cuboid) { | ||
this.orgiginal = cuboid; | ||
} | ||
} |
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
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
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,6 +1,6 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip | ||
networkTimeout=10000 | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |