-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hack block ID seen by ShadersMod mid-render
move block ID override to dedicated class
- Loading branch information
1 parent
6700e72
commit 0736915
Showing
5 changed files
with
66 additions
and
10 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
55 changes: 55 additions & 0 deletions
55
src/main/java/mods/betterfoliage/client/ShadersModIntegration.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,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; | ||
} | ||
} |
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