Fog colours can now be on a per-biome basis

This commit is contained in:
Adubbz 2013-11-03 17:36:41 +11:00
parent 076f3682d1
commit 67c4f7faf7
13 changed files with 254 additions and 32 deletions

View File

@ -1,19 +1,19 @@
package biomesoplenty.asm.smoothing;
package biomesoplenty.asm;
import net.minecraft.launchwrapper.IClassTransformer;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.biome.BiomeGenBase;
import biomesoplenty.asm.smoothing.block.BlockFluid;
import biomesoplenty.asm.smoothing.block.BlockGrass;
import biomesoplenty.asm.smoothing.block.BlockLeaves;
import biomesoplenty.asm.smoothing.block.BlockTallGrass;
import biomesoplenty.asm.biomecolourblending.BlockFluid;
import biomesoplenty.asm.biomecolourblending.BlockGrass;
import biomesoplenty.asm.biomecolourblending.BlockLeaves;
import biomesoplenty.asm.biomecolourblending.BlockTallGrass;
import biomesoplenty.configuration.configfile.BOPConfigurationMisc;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.FMLLaunchHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BOPBiomeTransitionSmoothing implements IClassTransformer
public class BOPBiomeColourBlending implements IClassTransformer
{
private static String SIDE = FMLLaunchHandler.side().name();

View File

@ -3,7 +3,6 @@ package biomesoplenty.asm;
import java.io.File;
import java.util.Map;
import biomesoplenty.asm.smoothing.BOPBiomeTransitionSmoothing;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.TransformerExclusions;
@ -21,7 +20,7 @@ public class BOPFMLLoadingPlugin implements IFMLLoadingPlugin
@Override
public String[] getASMTransformerClass()
{
return new String[] {BOPBiomeTransitionSmoothing.class.getName()};
return new String[] {BOPBiomeColourBlending.class.getName(), BOPFogColour.class.getName()};
}
@Override

View File

@ -0,0 +1,217 @@
package biomesoplenty.asm;
import static org.objectweb.asm.Opcodes.*;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.launchwrapper.IClassTransformer;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.ForgeDummyContainer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.VarInsnNode;
import org.w3c.dom.css.RGBColor;
import biomesoplenty.interfaces.IFogColour;
public class BOPFogColour implements IClassTransformer
{
private static int fogX, fogZ;
private static boolean fogInit;
private static int fogRGBMultiplier;
@Override
public byte[] transform(String name, String newname, byte[] bytes)
{
if (name.equals("net.minecraft.client.renderer.EntityRenderer"))
{
return patchEntityRenderer(newname, bytes, false);
}
if (name.equals("bfe"))
{
return patchEntityRenderer(newname, bytes, false);
}
return bytes;
}
public static byte[] patchEntityRenderer(String name, byte[] bytes, boolean obfuscated)
{
String targetMethodName = "";
if (obfuscated)
targetMethodName ="i";
else
targetMethodName ="updateFogColor";
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(bytes);
classReader.accept(classNode, 0);
Iterator<MethodNode> methods = classNode.methods.iterator();
while (methods.hasNext())
{
MethodNode m = methods.next();
int fdiv_index = -1;
if (m.name.equals(targetMethodName) && (m.desc.equals("(F)V")))
{
AbstractInsnNode currentNode = null;
AbstractInsnNode targetNode = null;
Iterator<AbstractInsnNode> iter = m.instructions.iterator();
int index = -1;
int timesFound = 0;
while (iter.hasNext())
{
index++;
currentNode = iter.next();
if (currentNode.getOpcode() == INVOKEVIRTUAL)
{
if (timesFound == 1)
{
targetNode = currentNode;
fdiv_index = index;
break;
}
else
{
timesFound++;
}
}
}
/*
mv.visitLineNumber(1658, l8);
mv.visitVarInsn(ALOAD, 3);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKESTATIC, "biomesoplenty/asm/BOPFogColour", "getFogVec", "(Lnet/minecraft/entity/Entity;Lnet/minecraft/world/World;)Lnet/minecraft/util/Vec3;");
mv.visitVarInsn(ASTORE, 9);
*/
InsnList toInject = new InsnList();
toInject.add(new VarInsnNode(ALOAD, 3));
toInject.add(new VarInsnNode(ALOAD, 2));
toInject.add(new VarInsnNode(FLOAD, 1));
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/BOPFogColour", "getFogVec", "(Lnn;Labw;F)Latc;"));
toInject.add(new VarInsnNode(ASTORE, 9));
m.instructions.insert(m.instructions.get(fdiv_index + 1), toInject);
/*
mv.visitLineNumber(1654, l8);
mv.visitVarInsn(ALOAD, 2);
mv.visitVarInsn(FLOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraft/client/multiplayer/WorldClient", "getFogColor", "(F)Lnet/minecraft/util/Vec3;");
mv.visitVarInsn(ASTORE, 9);
*/
List<AbstractInsnNode> remNodes = new ArrayList();
for (int i = -2; i <= 1; i++)
{
remNodes.add(m.instructions.get(fdiv_index + i));
}
for (AbstractInsnNode remNode : remNodes)
{
m.instructions.remove(remNode);
}
break;
}
}
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classNode.accept(writer);
return writer.toByteArray();
}
public static int getFogBlendColour(World world, float partialRenderTick, int playerX, int playerZ)
{
if (playerX == fogX && playerZ == fogZ && fogInit)
{
return fogRGBMultiplier;
}
fogInit = true;
int distance = Minecraft.getMinecraft().gameSettings.fancyGraphics ? ForgeDummyContainer.blendRanges[Minecraft.getMinecraft().gameSettings.renderDistance] : 0;
int r = 0;
int g = 0;
int b = 0;
int wr = (int)(world.getFogColor(partialRenderTick).xCoord * 255);
int wg = (int)(world.getFogColor(partialRenderTick).yCoord * 255);
int wb = (int)(world.getFogColor(partialRenderTick).zCoord * 255);
int defaultcolour = (wr << 16) + (wg << 8) + (wb);
int divider = 0;
for (int x = -distance; x <= distance; ++x)
{
for (int z = -distance; z <= distance; ++z)
{
BiomeGenBase biome = world.getBiomeGenForCoords(playerX + x, playerZ + z);
int colour = 0;
if (biome instanceof IFogColour)
{
colour = ((IFogColour)biome).getFogColour();
}
else
{
colour = defaultcolour;
}
r += (colour & 0xFF0000) >> 16;
g += (colour & 0x00FF00) >> 8;
b += colour & 0x0000FF;
divider++;
}
}
int multiplier = (r / divider & 255) << 16 | (g / divider & 255) << 8 | b / divider & 255;
fogX = playerX;
fogZ = playerZ;
fogRGBMultiplier = multiplier;
return fogRGBMultiplier;
}
public static Vec3 getFogVec(Entity entity, World world, float partialRenderTick)
{
int x = MathHelper.floor_double(entity.posX);
int z = MathHelper.floor_double(entity.posZ);
BiomeGenBase biome = world.getBiomeGenForCoords(x, z);
int multiplier = getFogBlendColour(world, partialRenderTick, x, z);
float r = (float)(multiplier >> 16 & 255) / 255.0F;
float g = (float)(multiplier >> 8 & 255) / 255.0F;
float b = (float)(multiplier & 255) / 255.0F;
return world.getWorldVec3Pool().getVecFromPool(r, g, b);
}
}

View File

@ -1,4 +1,4 @@
package biomesoplenty.asm.smoothing.block;
package biomesoplenty.asm.biomecolourblending;
import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.ICONST_0;
@ -71,9 +71,9 @@ public class BlockFluid
toInject.add(new VarInsnNode(ILOAD, 3));
toInject.add(new VarInsnNode(ILOAD, 4));
if (obfuscated)
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/smoothing/BOPBiomeTransitionSmoothing", "getWaterColourMultiplier", "(Lacf;III)I"));
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/BOPBiomeColourBlending", "getWaterColourMultiplier", "(Lacf;III)I"));
else
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/smoothing/BOPBiomeTransitionSmoothing", "getWaterColourMultiplier", "(Lnet/minecraft/world/IBlockAccess;III)I"));
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/BOPBiomeColourBlending", "getWaterColourMultiplier", "(Lnet/minecraft/world/IBlockAccess;III)I"));
toInject.add(new InsnNode(IRETURN));
m.instructions.insertBefore(targetNode, toInject);

View File

@ -1,4 +1,4 @@
package biomesoplenty.asm.smoothing.block;
package biomesoplenty.asm.biomecolourblending;
import static org.objectweb.asm.Opcodes.*;
import static org.objectweb.asm.tree.AbstractInsnNode.*;
@ -69,9 +69,9 @@ public class BlockGrass
toInject.add(new VarInsnNode(ILOAD, 3));
toInject.add(new VarInsnNode(ILOAD, 4));
if (obfuscated)
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/smoothing/BOPBiomeTransitionSmoothing", "getGrassColourMultiplier", "(Lacf;III)I"));
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/BOPBiomeColourBlending", "getGrassColourMultiplier", "(Lacf;III)I"));
else
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/smoothing/BOPBiomeTransitionSmoothing", "getGrassColourMultiplier", "(Lnet/minecraft/world/IBlockAccess;III)I"));
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/BOPBiomeColourBlending", "getGrassColourMultiplier", "(Lnet/minecraft/world/IBlockAccess;III)I"));
toInject.add(new InsnNode(IRETURN));
m.instructions.insertBefore(targetNode, toInject);

View File

@ -1,4 +1,4 @@
package biomesoplenty.asm.smoothing.block;
package biomesoplenty.asm.biomecolourblending;
import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.ICONST_0;
@ -72,9 +72,9 @@ public class BlockLeaves
toInject.add(new VarInsnNode(ILOAD, 3));
toInject.add(new VarInsnNode(ILOAD, 4));
if (obfuscated)
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/smoothing/BOPBiomeTransitionSmoothing", "getLeavesColourMultiplier", "(Lacf;III)I"));
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/BOPBiomeColourBlending", "getLeavesColourMultiplier", "(Lacf;III)I"));
else
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/smoothing/BOPBiomeTransitionSmoothing", "getLeavesColourMultiplier", "(Lnet/minecraft/world/IBlockAccess;III)I"));
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/BOPBiomeColourBlending", "getLeavesColourMultiplier", "(Lnet/minecraft/world/IBlockAccess;III)I"));
toInject.add(new InsnNode(IRETURN));
m.instructions.insertBefore(targetNode, toInject);

View File

@ -1,4 +1,4 @@
package biomesoplenty.asm.smoothing.block;
package biomesoplenty.asm.biomecolourblending;
import static org.objectweb.asm.Opcodes.*;
import static org.objectweb.asm.tree.AbstractInsnNode.*;
@ -69,9 +69,9 @@ public class BlockTallGrass
toInject.add(new VarInsnNode(ILOAD, 3));
toInject.add(new VarInsnNode(ILOAD, 4));
if (obfuscated)
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/smoothing/BOPBiomeTransitionSmoothing", "getGrassColourMultiplier", "(Lacf;III)I"));
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/BOPBiomeColourBlending", "getGrassColourMultiplier", "(Lacf;III)I"));
else
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/smoothing/BOPBiomeTransitionSmoothing", "getGrassColourMultiplier", "(Lnet/minecraft/world/IBlockAccess;III)I"));
toInject.add(new MethodInsnNode(INVOKESTATIC, "biomesoplenty/asm/BOPBiomeColourBlending", "getGrassColourMultiplier", "(Lnet/minecraft/world/IBlockAccess;III)I"));
toInject.add(new InsnNode(IRETURN));
m.instructions.insertBefore(targetNode, toInject);

View File

@ -17,7 +17,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.IShearable;
import biomesoplenty.BiomesOPlenty;
import biomesoplenty.api.Blocks;
import biomesoplenty.asm.smoothing.BOPBiomeTransitionSmoothing;
import biomesoplenty.asm.BOPBiomeColourBlending;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -96,7 +96,7 @@ public class BlockBOPColorizedLeaves extends BlockLeavesBase implements IShearab
@Override
public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
{
return BOPBiomeTransitionSmoothing.getLeavesColourMultiplier(par1IBlockAccess, par2, par3, par4);
return BOPBiomeColourBlending.getLeavesColourMultiplier(par1IBlockAccess, par2, par3, par4);
}
@Override

View File

@ -30,8 +30,8 @@ import net.minecraftforge.common.IShearable;
import biomesoplenty.BiomesOPlenty;
import biomesoplenty.api.Blocks;
import biomesoplenty.api.Items;
import biomesoplenty.asm.smoothing.BOPBiomeTransitionSmoothing;
import biomesoplenty.asm.smoothing.block.BlockGrass;
import biomesoplenty.asm.BOPBiomeColourBlending;
import biomesoplenty.asm.biomecolourblending.BlockGrass;
import biomesoplenty.blocks.renderers.RenderUtils;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -244,10 +244,10 @@ public class BlockBOPFoliage extends BlockFlower implements IShearable
{
if (par1IBlockAccess.getBlockMetadata(par2, par3, par4) == 9)
{
return BOPBiomeTransitionSmoothing.getLeavesColourMultiplier(par1IBlockAccess, par2, par3, par4);
return BOPBiomeColourBlending.getLeavesColourMultiplier(par1IBlockAccess, par2, par3, par4);
}
return BOPBiomeTransitionSmoothing.getGrassColourMultiplier(par1IBlockAccess, par2, par3, par4);
return BOPBiomeColourBlending.getGrassColourMultiplier(par1IBlockAccess, par2, par3, par4);
}
@Override

View File

@ -16,7 +16,7 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.IShearable;
import biomesoplenty.BiomesOPlenty;
import biomesoplenty.asm.smoothing.BOPBiomeTransitionSmoothing;
import biomesoplenty.asm.BOPBiomeColourBlending;
public class BlockIvy extends Block implements IShearable
{
@ -250,7 +250,7 @@ public class BlockIvy extends Block implements IShearable
@Override
public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
{
return BOPBiomeTransitionSmoothing.getLeavesColourMultiplier(par1IBlockAccess, par2, par3, par4);
return BOPBiomeColourBlending.getLeavesColourMultiplier(par1IBlockAccess, par2, par3, par4);
}
/**

View File

@ -12,7 +12,7 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import biomesoplenty.BiomesOPlenty;
import biomesoplenty.api.Blocks;
import biomesoplenty.asm.smoothing.BOPBiomeTransitionSmoothing;
import biomesoplenty.asm.BOPBiomeColourBlending;
public class BlockMoss extends Block
{
@ -244,7 +244,7 @@ public class BlockMoss extends Block
@Override
public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
{
return BOPBiomeTransitionSmoothing.getLeavesColourMultiplier(par1IBlockAccess, par2, par3, par4);
return BOPBiomeColourBlending.getLeavesColourMultiplier(par1IBlockAccess, par2, par3, par4);
}
/**

View File

@ -15,7 +15,7 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.IShearable;
import biomesoplenty.BiomesOPlenty;
import biomesoplenty.asm.smoothing.BOPBiomeTransitionSmoothing;
import biomesoplenty.asm.BOPBiomeColourBlending;
public class BlockWillow extends Block implements IShearable
{
@ -250,7 +250,7 @@ public class BlockWillow extends Block implements IShearable
@Override
public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
{
return BOPBiomeTransitionSmoothing.getLeavesColourMultiplier(par1IBlockAccess, par2, par3, par4);
return BOPBiomeColourBlending.getLeavesColourMultiplier(par1IBlockAccess, par2, par3, par4);
}
/**

View File

@ -0,0 +1,6 @@
package biomesoplenty.interfaces;
public interface IFogColour
{
public int getFogColour();
}