hack block ID seen by ShadersMod mid-render
move block ID override to dedicated class
This commit is contained in:
@@ -18,7 +18,6 @@ import mods.betterfoliage.client.resource.LeafTextureGenerator;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
@@ -71,6 +70,8 @@ public class BetterFoliageClient {
|
||||
});
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new BetterFoliageClient());
|
||||
|
||||
ShadersModIntegration.init();
|
||||
}
|
||||
|
||||
public static boolean isLeafTexture(TextureAtlasSprite icon) {
|
||||
@@ -90,14 +91,6 @@ public class BetterFoliageClient {
|
||||
return original;
|
||||
}
|
||||
|
||||
public static int getGLSLBlockIdOverride(int original, Block block) {
|
||||
if (leaves.matchesID(original & 0xFFFF))
|
||||
return Block.blockRegistry.getIDForObject(Blocks.leaves) & 0xFFFF | block.getRenderType() << 16;
|
||||
if (crops.matchesID(original & 0xFFFF))
|
||||
return Block.blockRegistry.getIDForObject(Blocks.tallgrass) & 0xFFFF | block.getRenderType() << 16;
|
||||
return original;
|
||||
}
|
||||
|
||||
public static void registerRenderer(IRenderBlockDecorator decorator) {
|
||||
int renderId = RenderingRegistry.getNextAvailableRenderId();
|
||||
decorators.put(renderId, decorator);
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package mods.betterfoliage.client;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
|
||||
public class ShadersModIntegration {
|
||||
|
||||
private static boolean hasShadersMod = false;
|
||||
private static int tallGrassEntityData;
|
||||
private static int leavesEntityData;
|
||||
private static Field shadersEntityData;
|
||||
private static Field shadersEntityDataIndex;
|
||||
|
||||
private ShadersModIntegration() {}
|
||||
|
||||
public static void init() {
|
||||
tallGrassEntityData = Block.blockRegistry.getIDForObject(Blocks.tallgrass) & 0xFFFF | Blocks.tallgrass.getRenderType() << 16;
|
||||
leavesEntityData = Block.blockRegistry.getIDForObject(Blocks.leaves) & 0xFFFF | Blocks.leaves.getRenderType() << 16;
|
||||
|
||||
try {
|
||||
Class<?> classShaders = Class.forName("shadersmodcore.client.Shaders");
|
||||
shadersEntityData = classShaders.getDeclaredField("entityData");
|
||||
shadersEntityDataIndex = classShaders.getDeclaredField("entityDataIndex");
|
||||
hasShadersMod = true;
|
||||
} catch(Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void startGrassQuads() {
|
||||
if (!hasShadersMod) return;
|
||||
setShadersEntityData(tallGrassEntityData);
|
||||
}
|
||||
|
||||
public static void startLeavesQuads() {
|
||||
if (!hasShadersMod) return;
|
||||
setShadersEntityData(leavesEntityData);
|
||||
}
|
||||
|
||||
private static void setShadersEntityData(int data) {
|
||||
try {
|
||||
int[] entityData = (int[]) shadersEntityData.get(null);
|
||||
int entityDataIndex = shadersEntityDataIndex.getInt(null);
|
||||
entityData[(entityDataIndex * 2)] = data;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getBlockIdOverride(int original, Block block) {
|
||||
if (BetterFoliageClient.leaves.matchesID(original & 0xFFFF)) return tallGrassEntityData;
|
||||
if (BetterFoliageClient.crops.matchesID(original & 0xFFFF)) return leavesEntityData;
|
||||
return original;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package mods.betterfoliage.client.render.impl;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.client.ShadersModIntegration;
|
||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||
import mods.betterfoliage.client.render.IconSet;
|
||||
import mods.betterfoliage.client.render.RenderBlockAOBase;
|
||||
@@ -49,6 +50,9 @@ public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRender
|
||||
|
||||
double scale = BetterFoliage.config.grassSize.value * 0.5;
|
||||
double halfHeight = 0.5 * (BetterFoliage.config.grassHeightMin.value + pRand[heightVariation] * (BetterFoliage.config.grassHeightMax.value - BetterFoliage.config.grassHeightMin.value));
|
||||
|
||||
// render short grass
|
||||
ShadersModIntegration.startGrassQuads();
|
||||
Tessellator.instance.setBrightness(getBrightness(block, x, y + 1, z));
|
||||
renderCrossedSideQuads(new Double3(x + 0.5, y + 1.0 - 0.125 * halfHeight, z + 0.5), ForgeDirection.UP, scale, halfHeight, pRot[variation], BetterFoliage.config.grassHOffset.value, renderIcon, 0, false);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package mods.betterfoliage.client.render.impl;
|
||||
import java.util.Random;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.client.ShadersModIntegration;
|
||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||
import mods.betterfoliage.client.render.IconSet;
|
||||
import mods.betterfoliage.client.render.RenderBlockAOBase;
|
||||
@@ -59,6 +60,9 @@ public class RenderBlockBetterReed extends RenderBlockAOBase implements IRenderB
|
||||
double quarterHeight = 0.25 * (BetterFoliage.config.reedHeightMin.value + pRand[heightVariation] * (BetterFoliage.config.reedHeightMax.value - BetterFoliage.config.reedHeightMin.value));
|
||||
Tessellator.instance.setBrightness(getBrightness(block, x, y + 2, z));
|
||||
Tessellator.instance.setColorOpaque(255, 255, 255);
|
||||
|
||||
// render reeds
|
||||
ShadersModIntegration.startGrassQuads();
|
||||
renderCrossedSideQuads(new Double3(x + 0.5, y + 1.0, z + 0.5), ForgeDirection.UP, 0.5, quarterHeight, pRot[iconVariation], BetterFoliage.config.reedHOffset.value, bottomIcon, 0, true);
|
||||
renderCrossedSideQuads(new Double3(x + 0.5, y + 1.0 + 2.0 * quarterHeight, z + 0.5), ForgeDirection.UP, 0.5, quarterHeight, pRot[iconVariation], BetterFoliage.config.reedHOffset.value, topIcon, 0, true);
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public class BetterFoliageTransformer extends EZTransformerBase {
|
||||
AbstractInsnNode arrayStore = findNext(method.instructions.getFirst(), matchOpcode(Opcodes.IASTORE));
|
||||
insertAfter(method.instructions, arrayStore.getPrevious(),
|
||||
new VarInsnNode(Opcodes.ALOAD, 1),
|
||||
new MethodInsnNode(Opcodes.INVOKESTATIC, "mods/betterfoliage/client/BetterFoliageClient", "getGLSLBlockIdOverride", signature("(ILnet/minecraft/block/Block;)I"))
|
||||
new MethodInsnNode(Opcodes.INVOKESTATIC, "mods/betterfoliage/client/ShadersModIntegration", "getBlockIdOverride", signature("(ILnet/minecraft/block/Block;)I"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user