3030
3131final class FluidsPatch extends GamePatch {
3232 private static final String World = "net/minecraft/common/world/World" ;
33+ private static final String Fluid = "net/minecraft/common/block/fluid/Fluid" ;
34+ private static final String Fluids = "net/minecraft/common/block/fluid/Fluids" ;
3335 private static final String BlockFluid = "net/minecraft/common/block/children/BlockFluid" ;
3436 private static final String InternalFluidsHooks = "com/fox2code/foxloader/internal/InternalFluidsHooks" ;
3537
3638 FluidsPatch () {
37- super (BlockFluid );
39+ super (new String []{ BlockFluid , Fluids } );
3840 }
3941
4042 @ Override
4143 public ClassNode transform (ClassNode classNode ) {
4244 if (BlockFluid .equals (classNode .name )) {
4345 patchBlockFluid (classNode );
46+ } else if (Fluids .equals (classNode .name )) {
47+ patchFluids (classNode );
4448 }
4549 return classNode ;
4650 }
@@ -67,4 +71,22 @@ private static void patchBlockFluid(ClassNode classNode) {
6771 insnList .add (new JumpInsnNode (IFNE , jumpInstance .label ));
6872 methodNode .instructions .insert (jumpInstance , insnList );
6973 }
74+
75+ private static void patchFluids (ClassNode classNode ) {
76+ FieldNode mat2fluids = TransformerUtils .getFieldDesc (classNode , "Ljava/util/IdentityHashMap;" );
77+ MethodNode getFluids = new MethodNode (ACC_PUBLIC | ACC_STATIC , "getFluids" ,
78+ "()Ljava/util/Collection;" , "()Ljava/util/Collection<L" + Fluid + ";>;" , null );
79+ getFluids .instructions .add (new FieldInsnNode (GETSTATIC , Fluids , mat2fluids .name , mat2fluids .desc ));
80+ getFluids .instructions .add (new MethodInsnNode (INVOKEVIRTUAL ,
81+ "java/util/IdentityHashMap" , "values" , "()Ljava/util/Collection;" ));
82+ getFluids .instructions .add (new MethodInsnNode (INVOKESTATIC ,
83+ "java/util/Collections" , "unmodifiableCollection" ,
84+ "(Ljava/util/Collection;)Ljava/util/Collection;" ));
85+ getFluids .instructions .add (new InsnNode (ARETURN ));
86+ if ("<clinit>" .equals (classNode .methods .get (classNode .methods .size () - 1 ).name )) {
87+ TransformerUtils .addMethodBefore (classNode , "<clinit>" , getFluids );
88+ } else {
89+ classNode .methods .add (getFluids );
90+ }
91+ }
7092}
0 commit comments