generated from VulpixelMC/MDK-1.21-ModDevGradle
-
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.
feat(day 2): swap block textures to programmer art in legacy chunks
- Loading branch information
Showing
13 changed files
with
169 additions
and
24 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
29 changes: 29 additions & 0 deletions
29
src/main/java/gay/sylv/legacy_landscape/client/HackedRenderSystem.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,29 @@ | ||
package gay.sylv.legacy_landscape.client; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import gay.sylv.legacy_landscape.mixin.client.Accessor_RenderSystem; | ||
import net.minecraft.client.renderer.texture.AbstractTexture; | ||
import net.minecraft.client.renderer.texture.TextureManager; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public final class HackedRenderSystem { | ||
private HackedRenderSystem() {} | ||
|
||
public static void setShaderTexture(int shaderTexture, ResourceLocation textureId, boolean blur, boolean mipmap) { | ||
if (!RenderSystem.isOnRenderThread()) { | ||
RenderSystem.recordRenderCall(() -> _setShaderTexture(shaderTexture, textureId, blur, mipmap)); | ||
} else { | ||
_setShaderTexture(shaderTexture, textureId, blur, mipmap); | ||
} | ||
} | ||
|
||
private static void _setShaderTexture(int shaderTexture, ResourceLocation textureId, boolean blur, boolean mipmap) { | ||
int[] shaderTextures = Accessor_RenderSystem.getShaderTextures(); | ||
if (shaderTexture >= 0 && shaderTexture < shaderTextures.length) { | ||
TextureManager textureManager = LegacyResourceFaker.getTextureManager(); | ||
AbstractTexture abstractTexture = textureManager.getTexture(textureId); | ||
abstractTexture.setFilter(blur, mipmap); | ||
shaderTextures[shaderTexture] = abstractTexture.getId(); | ||
} | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/java/gay/sylv/legacy_landscape/mixin/client/Accessor_CompositeRenderType.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,11 @@ | ||
package gay.sylv.legacy_landscape.mixin.client; | ||
|
||
import net.minecraft.client.renderer.RenderType; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(RenderType.CompositeRenderType.class) | ||
public interface Accessor_CompositeRenderType { | ||
@Accessor | ||
RenderType.CompositeState getState(); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/gay/sylv/legacy_landscape/mixin/client/Accessor_CompositeState.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 gay.sylv.legacy_landscape.mixin.client; | ||
|
||
import net.minecraft.client.renderer.RenderStateShard; | ||
import net.minecraft.client.renderer.RenderType; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(RenderType.CompositeState.class) | ||
public interface Accessor_CompositeState { | ||
@Accessor | ||
RenderStateShard.EmptyTextureStateShard getTextureState(); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/gay/sylv/legacy_landscape/mixin/client/Accessor_RenderSystem.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,13 @@ | ||
package gay.sylv.legacy_landscape.mixin.client; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(RenderSystem.class) | ||
public interface Accessor_RenderSystem { | ||
@Accessor | ||
static int[] getShaderTextures() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/gay/sylv/legacy_landscape/mixin/client/Accessor_TextureStateShard.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,20 @@ | ||
package gay.sylv.legacy_landscape.mixin.client; | ||
|
||
import net.minecraft.client.renderer.RenderStateShard; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
import java.util.Optional; | ||
|
||
@Mixin(RenderStateShard.TextureStateShard.class) | ||
public interface Accessor_TextureStateShard { | ||
@Accessor | ||
Optional<ResourceLocation> getTexture(); | ||
|
||
@Accessor | ||
boolean isBlur(); | ||
|
||
@Accessor | ||
boolean isMipmap(); | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/gay/sylv/legacy_landscape/mixin/client/Mixin_LevelRenderer.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,43 @@ | ||
package gay.sylv.legacy_landscape.mixin.client; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import gay.sylv.legacy_landscape.client.HackedRenderSystem; | ||
import gay.sylv.legacy_landscape.data_attachment.LegacyAttachments; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.renderer.LevelRenderer; | ||
import net.minecraft.client.renderer.RenderType; | ||
import net.minecraft.client.renderer.ShaderInstance; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.chunk.LevelChunk; | ||
import org.joml.Matrix4f; | ||
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.CallbackInfo; | ||
|
||
@Mixin(LevelRenderer.class) | ||
public final class Mixin_LevelRenderer { | ||
private Mixin_LevelRenderer() {} | ||
|
||
@Inject( | ||
method = "renderSectionLayer", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/client/renderer/ShaderInstance;setDefaultUniforms(Lcom/mojang/blaze3d/vertex/VertexFormat$Mode;Lorg/joml/Matrix4f;Lorg/joml/Matrix4f;Lcom/mojang/blaze3d/platform/Window;)V" | ||
) | ||
) | ||
private void setLegacyTextures(RenderType renderType, double x, double y, double z, Matrix4f frustrumMatrix, Matrix4f projectionMatrix, CallbackInfo ci, @Local ShaderInstance shaderInstance) { | ||
Minecraft client = Minecraft.getInstance(); | ||
assert client.level != null; | ||
LevelChunk chunk = client.level.getChunkAt(BlockPos.containing(x, y, z)); | ||
if (chunk.getData(LegacyAttachments.LEGACY_CHUNK)) { | ||
Accessor_CompositeRenderType compositeRenderType = (Accessor_CompositeRenderType) renderType; | ||
Accessor_CompositeState compositeState = (Accessor_CompositeState) (Object) compositeRenderType.getState(); | ||
assert compositeState != null; | ||
Accessor_TextureStateShard textureState = (Accessor_TextureStateShard) (compositeState.getTextureState()); | ||
if (textureState.getTexture().isPresent()) { | ||
HackedRenderSystem.setShaderTexture(0, textureState.getTexture().get(), textureState.isBlur(), textureState.isMipmap()); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
public net.minecraft.client.renderer.RenderType$CompositeRenderType |
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