From 3980bf79da3852c0e98cacf1dd9f77b481f240f4 Mon Sep 17 00:00:00 2001 From: RainWarrior Date: Tue, 20 May 2014 21:51:46 +0400 Subject: [PATCH] Added world display list render events --- .../client/renderer/WorldRenderer.java.patch | 27 ++++++++++--- .../client/ForgeHooksClient.java | 34 ++++++++++++++++ .../client/event/RenderWorldEvent.java | 39 +++++++++++++++++++ 3 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 src/main/java/net/minecraftforge/client/event/RenderWorldEvent.java diff --git a/patches/minecraft/net/minecraft/client/renderer/WorldRenderer.java.patch b/patches/minecraft/net/minecraft/client/renderer/WorldRenderer.java.patch index 8e74e1346..db5e237b2 100644 --- a/patches/minecraft/net/minecraft/client/renderer/WorldRenderer.java.patch +++ b/patches/minecraft/net/minecraft/client/renderer/WorldRenderer.java.patch @@ -9,7 +9,15 @@ public static int field_78922_b; public int field_78923_c; public int field_78920_d; -@@ -157,7 +157,7 @@ +@@ -132,6 +132,7 @@ + { + ++field_78922_b; + RenderBlocks renderblocks = new RenderBlocks(chunkcache); ++ net.minecraftforge.client.ForgeHooksClient.setWorldRendererRB(renderblocks); + this.field_78917_C = 0; + this.field_147894_y = null; + +@@ -157,7 +158,7 @@ this.func_147890_b(k2); } @@ -18,7 +26,7 @@ { TileEntity tileentity = chunkcache.func_147438_o(j3, l2, i3); -@@ -173,7 +173,9 @@ +@@ -173,7 +174,9 @@ { flag = true; } @@ -29,12 +37,21 @@ { flag1 |= renderblocks.func_147805_b(block, j3, l2, i3); -@@ -232,21 +234,22 @@ +@@ -210,6 +213,7 @@ + break; + } + } ++ net.minecraftforge.client.ForgeHooksClient.setWorldRendererRB(null); + } + + HashSet hashset1 = new HashSet(); +@@ -232,21 +236,23 @@ GL11.glTranslatef(-8.0F, -8.0F, -8.0F); GL11.glScalef(f, f, f); GL11.glTranslatef(8.0F, 8.0F, 8.0F); - field_78941_z.func_78382_b(); - field_78941_z.func_78373_b((double)(-this.field_78923_c), (double)(-this.field_78920_d), (double)(-this.field_78921_e)); ++ net.minecraftforge.client.ForgeHooksClient.onPreRenderWorld(this, p_147890_1_); + Tessellator.field_78398_a.func_78382_b(); + Tessellator.field_78398_a.func_78373_b((double)(-this.field_78923_c), (double)(-this.field_78920_d), (double)(-this.field_78921_e)); } @@ -48,8 +65,8 @@ } - this.field_78917_C += field_78941_z.func_78381_a(); -+ //ForgeHooksClient.afterRenderPass(l1); Noop fo now, TODO: Event if anyone needs + this.field_78917_C += Tessellator.field_78398_a.func_78381_a(); ++ net.minecraftforge.client.ForgeHooksClient.onPostRenderWorld(this, p_147891_1_); GL11.glPopMatrix(); GL11.glEndList(); - field_78941_z.func_78373_b(0.0D, 0.0D, 0.0D); @@ -57,7 +74,7 @@ } public void func_147889_b(EntityLivingBase p_147889_1_) -@@ -254,7 +257,7 @@ +@@ -254,7 +260,7 @@ if (this.field_147894_y != null && !this.field_78928_m[1]) { this.func_147890_b(1); diff --git a/src/main/java/net/minecraftforge/client/ForgeHooksClient.java b/src/main/java/net/minecraftforge/client/ForgeHooksClient.java index d80abf1c3..b960a3118 100644 --- a/src/main/java/net/minecraftforge/client/ForgeHooksClient.java +++ b/src/main/java/net/minecraftforge/client/ForgeHooksClient.java @@ -35,6 +35,7 @@ import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.ChunkCache; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.client.model.ModelBiped; @@ -42,6 +43,7 @@ import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.RenderGlobal; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.TextureMap; @@ -49,6 +51,7 @@ import net.minecraft.client.settings.GameSettings; import net.minecraftforge.client.IItemRenderer.ItemRenderType; import net.minecraftforge.client.event.DrawBlockHighlightEvent; import net.minecraftforge.client.event.RenderHandEvent; +import net.minecraftforge.client.event.RenderWorldEvent; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.client.event.sound.PlaySoundEvent17; @@ -453,4 +456,35 @@ public class ForgeHooksClient MinecraftForge.EVENT_BUS.post(e); return e.result; } + + static RenderBlocks worldRendererRB; + static int worldRenderPass; + + public static int getWorldRenderPass() + { + return worldRenderPass; + } + + public static void setWorldRendererRB(RenderBlocks renderBlocks) + { + worldRendererRB = renderBlocks; + } + + public static void onPreRenderWorld(WorldRenderer worldRenderer, int pass) + { + if(worldRendererRB != null) + { + worldRenderPass = pass; + MinecraftForge.EVENT_BUS.post(new RenderWorldEvent.Pre(worldRenderer, (ChunkCache)worldRendererRB.blockAccess, worldRendererRB, pass)); + } + } + + public static void onPostRenderWorld(WorldRenderer worldRenderer, int pass) + { + if(worldRendererRB != null) + { + MinecraftForge.EVENT_BUS.post(new RenderWorldEvent.Post(worldRenderer, (ChunkCache)worldRendererRB.blockAccess, worldRendererRB, pass)); + worldRenderPass = -1; + } + } } diff --git a/src/main/java/net/minecraftforge/client/event/RenderWorldEvent.java b/src/main/java/net/minecraftforge/client/event/RenderWorldEvent.java new file mode 100644 index 000000000..5b353f35f --- /dev/null +++ b/src/main/java/net/minecraftforge/client/event/RenderWorldEvent.java @@ -0,0 +1,39 @@ +package net.minecraftforge.client.event; + +import cpw.mods.fml.common.eventhandler.Event; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.world.ChunkCache; + +public abstract class RenderWorldEvent extends Event +{ + public final WorldRenderer renderer; + public final ChunkCache chunkCache; + public final RenderBlocks renderBlocks; + public final int pass; + + public RenderWorldEvent(WorldRenderer renderer, ChunkCache chunkCache, RenderBlocks renderBlocks, int pass) + { + this.renderer = renderer; + this.chunkCache = chunkCache; + this.renderBlocks = renderBlocks; + this.pass = pass; + } + + /** + * Fired when 16x16x16 chunk area is being redrawn. + * Fired after GL state is setup, before tessellator is started. + */ + public static class Pre extends RenderWorldEvent + { + public Pre(WorldRenderer renderer, ChunkCache chunkCache, RenderBlocks renderBlocks, int pass){ super(renderer, chunkCache, renderBlocks, pass); } + } + + /** + * Fired after the tessellator is stopped, before the display list is ended. + */ + public static class Post extends RenderWorldEvent + { + public Post(WorldRenderer renderer, ChunkCache chunkCache, RenderBlocks renderBlocks, int pass){ super(renderer, chunkCache, renderBlocks, pass); } + } +}