Skip to content

Commit

Permalink
Code conversion to Mojang mappings
Browse files Browse the repository at this point in the history
Name conversion is still undone.
  • Loading branch information
IMS212 committed Aug 3, 2021
1 parent 0158656 commit 42ac525
Show file tree
Hide file tree
Showing 136 changed files with 1,678 additions and 1,744 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ minecraft {

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Critical, needed for loading our custom language files
Expand Down
43 changes: 21 additions & 22 deletions src/main/java/net/coderbot/iris/HorizonRenderer.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package net.coderbot.iris;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.BufferUploader;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.Minecraft;
import org.lwjgl.opengl.GL11;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;

/**
* Renders the sky horizon. Vanilla Minecraft simply uses the "clear color" for its horizon, and then draws a plane
* above the player. This class extends the sky rendering so that an octagonal prism is drawn around the player instead,
Expand Down Expand Up @@ -48,13 +47,13 @@ public HorizonRenderer() {

private void buildQuad(VertexConsumer consumer, double x1, double z1, double x2, double z2) {
consumer.vertex(x1, BOTTOM, z1);
consumer.next();
consumer.endVertex();
consumer.vertex(x1, TOP, z1);
consumer.next();
consumer.endVertex();
consumer.vertex(x2, TOP, z2);
consumer.next();
consumer.endVertex();
consumer.vertex(x2, BOTTOM, z2);
consumer.next();
consumer.endVertex();
}

private void buildHalf(VertexConsumer consumer, double adjacent, double opposite, boolean invert) {
Expand Down Expand Up @@ -96,13 +95,13 @@ private void buildBottomPlane(VertexConsumer consumer, int radius) {
for(int x = -radius; x <= radius; x += 64) {
for(int z = -radius; z <= radius; z += 64) {
consumer.vertex(x + 64, BOTTOM, z);
consumer.next();
consumer.endVertex();
consumer.vertex(x, BOTTOM, z);
consumer.next();
consumer.endVertex();
consumer.vertex(x, BOTTOM, z + 64);
consumer.next();
consumer.endVertex();
consumer.vertex(x + 64, BOTTOM, z + 64);
consumer.next();
consumer.endVertex();
}
}
}
Expand All @@ -123,22 +122,22 @@ private void buildHorizon(VertexConsumer consumer) {
}

private int getRenderDistanceInBlocks() {
return MinecraftClient.getInstance().options.viewDistance * 16;
return Minecraft.getInstance().options.renderDistance * 16;
}

public void renderHorizon(MatrixStack matrices) {
BufferBuilder buffer = Tessellator.getInstance().getBuffer();
public void renderHorizon(PoseStack matrices) {
BufferBuilder buffer = Tesselator.getInstance().getBuilder();

// Build the horizon quads into a buffer
buffer.begin(GL11.GL_QUADS, VertexFormats.POSITION);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormat.POSITION);
buildHorizon(buffer);
buffer.end();

// Render the horizon buffer
RenderSystem.pushMatrix();
RenderSystem.loadIdentity();
RenderSystem.multMatrix(matrices.peek().getModel());
BufferRenderer.draw(buffer);
RenderSystem.multMatrix(matrices.last().pose());
BufferUploader.end(buffer);
RenderSystem.popMatrix();
}
}
61 changes: 29 additions & 32 deletions src/main/java/net/coderbot/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,24 @@
import java.util.zip.ZipException;

import com.google.common.base.Throwables;
import com.mojang.blaze3d.platform.InputConstants;
import net.coderbot.iris.config.IrisConfig;
import net.coderbot.iris.gui.screen.ShaderPackScreen;
import net.coderbot.iris.pipeline.*;
import net.coderbot.iris.shaderpack.DimensionId;
import net.coderbot.iris.shaderpack.ProgramSet;
import net.coderbot.iris.shaderpack.ShaderPack;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import net.minecraft.ChatFormatting;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceKey;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.glfw.GLFW;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -48,9 +45,9 @@ public class Iris implements ClientModInitializer {
private static PipelineManager pipelineManager;
private static IrisConfig irisConfig;
private static FileSystem zipFileSystem;
private static KeyBinding reloadKeybind;
private static KeyBinding toggleShadersKeybind;
private static KeyBinding shaderpackScreenKeybind;
private static KeyMapping reloadKeybind;
private static KeyMapping toggleShadersKeybind;
private static KeyMapping shaderpackScreenKeybind;

private static String IRIS_VERSION;

Expand Down Expand Up @@ -92,48 +89,48 @@ public void onInitializeClient() {

loadShaderpack();

reloadKeybind = KeyBindingHelper.registerKeyBinding(new KeyBinding("iris.keybind.reload", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_R, "iris.keybinds"));
toggleShadersKeybind = KeyBindingHelper.registerKeyBinding(new KeyBinding("iris.keybind.toggleShaders", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_K, "iris.keybinds"));
shaderpackScreenKeybind = KeyBindingHelper.registerKeyBinding(new KeyBinding("iris.keybind.shaderPackSelection", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_O, "iris.keybinds"));
reloadKeybind = KeyBindingHelper.registerKeyBinding(new KeyMapping("iris.keybind.reload", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_R, "iris.keybinds"));
toggleShadersKeybind = KeyBindingHelper.registerKeyBinding(new KeyMapping("iris.keybind.toggleShaders", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_K, "iris.keybinds"));
shaderpackScreenKeybind = KeyBindingHelper.registerKeyBinding(new KeyMapping("iris.keybind.shaderPackSelection", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_O, "iris.keybinds"));

ClientTickEvents.END_CLIENT_TICK.register(minecraftClient -> {
if (reloadKeybind.wasPressed()) {
if (reloadKeybind.consumeClick()) {
try {
reload();

if (minecraftClient.player != null) {
minecraftClient.player.sendMessage(new TranslatableText("iris.shaders.reloaded"), false);
minecraftClient.player.displayClientMessage(new TranslatableComponent("iris.shaders.reloaded"), false);
}

} catch (Exception e) {
Iris.logger.error("Error while reloading Shaders for Iris!", e);

if (minecraftClient.player != null) {
minecraftClient.player.sendMessage(new TranslatableText("iris.shaders.reloaded.failure", Throwables.getRootCause(e).getMessage()).formatted(Formatting.RED), false);
minecraftClient.player.displayClientMessage(new TranslatableComponent("iris.shaders.reloaded.failure", Throwables.getRootCause(e).getMessage()).withStyle(ChatFormatting.RED), false);
}
}
} else if (toggleShadersKeybind.wasPressed()) {
} else if (toggleShadersKeybind.consumeClick()) {
IrisConfig config = getIrisConfig();
try {
config.setShadersEnabled(!config.areShadersEnabled());
config.save();

reload();
if (minecraftClient.player != null) {
minecraftClient.player.sendMessage(new TranslatableText("iris.shaders.toggled", config.areShadersEnabled() ? currentPackName : "off"), false);
minecraftClient.player.displayClientMessage(new TranslatableComponent("iris.shaders.toggled", config.areShadersEnabled() ? currentPackName : "off"), false);
}
} catch (Exception e) {
Iris.logger.error("Error while toggling shaders!", e);

if (minecraftClient.player != null) {
minecraftClient.player.sendMessage(new TranslatableText("iris.shaders.toggled.failure", Throwables.getRootCause(e).getMessage()).formatted(Formatting.RED), false);
minecraftClient.player.displayClientMessage(new TranslatableComponent("iris.shaders.toggled.failure", Throwables.getRootCause(e).getMessage()).withStyle(ChatFormatting.RED), false);
}

setShadersDisabled();
currentPackName = "(off) [fallback, check your logs for errors]";
}
} else if (shaderpackScreenKeybind.wasPressed()) {
minecraftClient.openScreen(new ShaderPackScreen(null));
} else if (shaderpackScreenKeybind.consumeClick()) {
minecraftClient.setScreen(new ShaderPackScreen(null));
}
});

Expand Down Expand Up @@ -373,14 +370,14 @@ private static void destroyEverything() {
public static DimensionId lastDimension = DimensionId.OVERWORLD;

public static DimensionId getCurrentDimension() {
ClientWorld world = MinecraftClient.getInstance().world;
ClientLevel world = Minecraft.getInstance().level;

if (world != null) {
RegistryKey<World> worldRegistryKey = world.getRegistryKey();
ResourceKey<net.minecraft.world.level.Level> worldRegistryKey = world.dimension();

if (worldRegistryKey.equals(World.END)) {
if (worldRegistryKey.equals(net.minecraft.world.level.Level.END)) {
return DimensionId.END;
} else if (worldRegistryKey.equals(World.NETHER)) {
} else if (worldRegistryKey.equals(net.minecraft.world.level.Level.NETHER)) {
return DimensionId.NETHER;
} else {
return DimensionId.OVERWORLD;
Expand Down Expand Up @@ -441,15 +438,15 @@ public static String getVersion() {
}

public static String getFormattedVersion() {
Formatting color;
ChatFormatting color;
String version = getVersion();

if (version.endsWith("-dirty") || version.contains("unknown")) {
color = Formatting.RED;
color = ChatFormatting.RED;
} else if (version.contains("+rev.")) {
color = Formatting.LIGHT_PURPLE;
color = ChatFormatting.LIGHT_PURPLE;
} else {
color = Formatting.GREEN;
color = ChatFormatting.GREEN;
}

return color + version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

import net.coderbot.iris.layer.GbufferProgram;
import net.coderbot.iris.layer.GbufferPrograms;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.renderer.RenderType;

public class PhysicsModHooks {
public static void redirectEndDrawing(RenderLayer layer) {
public static void redirectEndDrawing(RenderType layer) {
GbufferPrograms.push(GbufferProgram.TEXTURED_LIT);
}

public static void redirectStartDrawing(RenderLayer layer) {
public static void redirectStartDrawing(RenderType layer) {
if (layer == getTargetRenderLayer()) {
GbufferPrograms.pop(GbufferProgram.TEXTURED_LIT);
}
}

public static RenderLayer getTargetRenderLayer() {
return RenderLayer.getCutout();
public static RenderType getTargetRenderLayer() {
return RenderType.cutout();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package net.coderbot.iris.compat.physicsmod.mixin;

import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.renderer.LevelRenderer;
import org.spongepowered.asm.mixin.Mixin;

// Run after the PhysicsMod injection
@Mixin(value = WorldRenderer.class, priority = 1001)
@Mixin(value = LevelRenderer.class, priority = 1001)
public class MixinWorldRenderer {
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package net.coderbot.iris.fantastic;

import net.coderbot.iris.layer.IrisRenderLayerWrapper;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;

import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.VertexConsumer;
import java.util.Collections;

public class FantasticVertexConsumerProvider extends VertexConsumerProvider.Immediate implements FlushableVertexConsumerProvider {
public class FantasticVertexConsumerProvider extends MultiBufferSource.BufferSource implements FlushableVertexConsumerProvider {
private final FullyBufferedVertexConsumerProvider opaque;
private final FullyBufferedVertexConsumerProvider transparent;

Expand All @@ -19,8 +18,8 @@ public FantasticVertexConsumerProvider() {
this.transparent = new FullyBufferedVertexConsumerProvider();
}

private boolean isTransparent(RenderLayer layer) {
if (layer == RenderLayer.getWaterMask()) {
private boolean isTransparent(RenderType layer) {
if (layer == RenderType.waterMask()) {
// Don't break boats...
return true;
}
Expand All @@ -38,7 +37,7 @@ private boolean isTransparent(RenderLayer layer) {
}

@Override
public VertexConsumer getBuffer(RenderLayer renderLayer) {
public VertexConsumer getBuffer(RenderType renderLayer) {
if (isTransparent(renderLayer)) {
return transparent.getBuffer(renderLayer);
} else {
Expand All @@ -47,27 +46,27 @@ public VertexConsumer getBuffer(RenderLayer renderLayer) {
}

@Override
public void draw() {
opaque.draw();
transparent.draw();
public void endBatch() {
opaque.endBatch();
transparent.endBatch();
}

@Override
public void draw(RenderLayer layer) {
public void endBatch(RenderType layer) {
if (isTransparent(layer)) {
transparent.draw(layer);
transparent.endBatch(layer);
} else {
opaque.draw(layer);
opaque.endBatch(layer);
}
}

@Override
public void flushNonTranslucentContent() {
opaque.draw();
opaque.endBatch();
}

@Override
public void flushTranslucentContent() {
transparent.draw();
transparent.endBatch();
}
}
Loading

0 comments on commit 42ac525

Please sign in to comment.