Made leather armor protect you from deathblooms, burning blossoms, thorns, and tiny cacti

This commit is contained in:
Matt Caughey 2013-11-10 04:00:47 -05:00
parent 8dd75eb294
commit e5f93b651c
12 changed files with 59 additions and 486 deletions

View File

@ -1,43 +0,0 @@
package worldcore.asm;
import java.io.File;
import java.util.Map;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.TransformerExclusions;
@TransformerExclusions({ "worldcore.asm" })
public class WCFMLLoadingPlugin implements IFMLLoadingPlugin
{
public static File location;
@Override
public String[] getLibraryRequestClass()
{
return null;
}
@Override
public String[] getASMTransformerClass()
{
return new String[] {WCFogColour.class.getName(), WCFogDistance.class.getName()};
}
@Override
public String getModContainerClass()
{
return null;
}
@Override
public String getSetupClass()
{
return null;
}
@Override
public void injectData(Map<String, Object> data)
{
location = (File)data.get("coremodLocation");
}
}

View File

@ -1,225 +0,0 @@
package worldcore.asm;
import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.ASTORE;
import static org.objectweb.asm.Opcodes.FLOAD;
import static org.objectweb.asm.Opcodes.INVOKESTATIC;
import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
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 worldcore.interfaces.IWCFog;
public class WCFogColour implements IClassTransformer
{
@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, true);
}
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));
if (obfuscated)
toInject.add(new MethodInsnNode(INVOKESTATIC, "worldcore/asm/WCFogColour", "getFogVec", "(Lnn;Labw;F)Latc;"));
else
toInject.add(new MethodInsnNode(INVOKESTATIC, "worldcore/asm/WCFogColour", "getFogVec", "(Lnet/minecraft/entity/Entity;Lnet/minecraft/world/World;F)Lnet/minecraft/util/Vec3;"));
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)
{
int distance = Minecraft.getMinecraft().gameSettings.fancyGraphics ? ForgeDummyContainer.blendRanges[Minecraft.getMinecraft().gameSettings.renderDistance] : 0;
int r = 0;
int g = 0;
int b = 0;
float celestialAngle = world.getCelestialAngle(partialRenderTick);
int wr = (int)(world.provider.getFogColor(celestialAngle, partialRenderTick).xCoord * 255);
int wg = (int)(world.provider.getFogColor(celestialAngle, partialRenderTick).yCoord * 255);
int wb = (int)(world.provider.getFogColor(celestialAngle, 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 IWCFog)
{
colour = ((IWCFog)biome).getFogColour();
}
else
{
colour = defaultcolour;
}
r += (colour & 0xFF0000) >> 16;
g += (colour & 0x00FF00) >> 8;
b += colour & 0x0000FF;
divider++;
}
}
float celestialAngleMultiplier = MathHelper.cos(celestialAngle * (float)Math.PI * 2.0F) * 2.0F + 0.5F;
if (celestialAngleMultiplier < 0.0F)
{
celestialAngleMultiplier = 0.0F;
}
if (celestialAngleMultiplier > 1.0F)
{
celestialAngleMultiplier = 1.0F;
}
r *= celestialAngleMultiplier;
g *= celestialAngleMultiplier;
b *= celestialAngleMultiplier;
int multiplier = (r / divider & 255) << 16 | (g / divider & 255) << 8 | b / divider & 255;
return multiplier;
}
public static Vec3 getFogVec(Entity entity, World world, float partialRenderTick)
{
int x = MathHelper.floor_double(entity.posX);
int z = MathHelper.floor_double(entity.posZ);
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,201 +0,0 @@
package worldcore.asm;
import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.FLOAD;
import static org.objectweb.asm.Opcodes.ILOAD;
import static org.objectweb.asm.Opcodes.INVOKESTATIC;
import java.util.Iterator;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.launchwrapper.IClassTransformer;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.ForgeDummyContainer;
import org.lwjgl.opengl.GL11;
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 worldcore.interfaces.IWCFog;
public class WCFogDistance implements IClassTransformer
{
private static int fogX, fogZ;
private static boolean fogInit;
private static float storedFinalFogCloseness;
@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, true);
}
return bytes;
}
public static byte[] patchEntityRenderer(String name, byte[] bytes, boolean obfuscated)
{
String targetMethodName = "";
if (obfuscated)
targetMethodName ="a";
else
targetMethodName ="setupFog";
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("(IF)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() == ALOAD)
{
if (timesFound == 22)
{
targetNode = currentNode;
fdiv_index = index;
break;
}
else
{
timesFound++;
}
}
}
/*
mv.visitMethodInsn(INVOKESTATIC, "org/lwjgl/opengl/GL11", "glFogf", "(IF)V");
mv.visitLabel(l71);
mv.visitLineNumber(1922, l71);
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
mv.visitVarInsn(ALOAD, 3);
mv.visitVarInsn(FLOAD, 6);
mv.visitMethodInsn(INVOKESTATIC, "biomesoplenty/asm/BOPFogDistance", "setBiomeFogDistance", "(Lnet/minecraft/entity/Entity;F)V");
mv.visitLabel(l32);
*/
InsnList toInject = new InsnList();
toInject.add(new VarInsnNode(ALOAD, 3));
toInject.add(new VarInsnNode(ILOAD, 1));
toInject.add(new VarInsnNode(FLOAD, 6));
if (obfuscated)
toInject.add(new MethodInsnNode(INVOKESTATIC, "worldcore/asm/WCFogDistance", "setBiomeFogDistance", "(Lnn;IF)V"));
else
toInject.add(new MethodInsnNode(INVOKESTATIC, "worldcore/asm/WCFogDistance", "setBiomeFogDistance", "(Lnet/minecraft/entity/Entity;IF)V"));
m.instructions.insertBefore(m.instructions.get(fdiv_index), toInject);
break;
}
}
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classNode.accept(writer);
return writer.toByteArray();
}
public static void setBiomeFogDistance(Entity entity, int distance, float farPlaneDistance)
{
World world = entity.worldObj;
int playerX = MathHelper.floor_double(entity.posX);
int playerZ = MathHelper.floor_double(entity.posZ);
if (playerX == fogX && playerZ == fogZ && fogInit)
{
if (distance < 0)
{
GL11.glFogf(GL11.GL_FOG_START, 0.0F);
GL11.glFogf(GL11.GL_FOG_END, farPlaneDistance * 0.8F);
}
else
{
GL11.glFogf(GL11.GL_FOG_START, farPlaneDistance * (storedFinalFogCloseness / 10));
GL11.glFogf(GL11.GL_FOG_END, Math.min(farPlaneDistance, 192.0F) * storedFinalFogCloseness);
}
return;
}
fogInit = true;
int blenddistance = Minecraft.getMinecraft().gameSettings.fancyGraphics ? ForgeDummyContainer.blendRanges[Minecraft.getMinecraft().gameSettings.renderDistance] : 0;
int divider = 0;
float fogCloseness = 0.0F;
for (int x = -blenddistance; x <= blenddistance; ++x)
{
for (int z = -blenddistance; z <= blenddistance; ++z)
{
BiomeGenBase biome = world.getBiomeGenForCoords(playerX + x, playerZ + z);
if (biome instanceof IWCFog)
{
fogCloseness += ((IWCFog)biome).getFogCloseness();
}
else
{
fogCloseness += 1.0F;
}
divider++;
}
}
float finalFogCloseness = fogCloseness / divider;
fogX = playerX;
fogZ = playerZ;
storedFinalFogCloseness = finalFogCloseness;
if (distance < 0)
{
GL11.glFogf(GL11.GL_FOG_START, 0.0F);
GL11.glFogf(GL11.GL_FOG_END, farPlaneDistance * 0.8F);
}
else
{
GL11.glFogf(GL11.GL_FOG_START, farPlaneDistance * (finalFogCloseness / 10));
GL11.glFogf(GL11.GL_FOG_END, Math.min(farPlaneDistance, 192.0F) * finalFogCloseness);
}
}
}

View File

@ -1,8 +0,0 @@
package worldcore.interfaces;
public interface IWCFog
{
public int getFogColour();
public float getFogCloseness();
}

View File

@ -123,7 +123,6 @@ public class BiomeGenOminousWoods extends BiomeGenBase implements IWCFog
@Override @Override
public float getFogCloseness() public float getFogCloseness()
{ {
// TODO Auto-generated method stub return 0.1F;
return 0.2F;
} }
} }

View File

@ -126,7 +126,6 @@ public class BiomeGenOminousWoodsThick extends BiomeGenBase implements IWCFog
@Override @Override
public float getFogCloseness() public float getFogCloseness()
{ {
// TODO Auto-generated method stub return 0.1F;
return 0.2F;
} }
} }

View File

@ -11,6 +11,7 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion; import net.minecraft.potion.Potion;
@ -132,10 +133,22 @@ public class BlockBOPFlower extends BlockFlower
int meta = world.getBlockMetadata(x, y, z); int meta = world.getBlockMetadata(x, y, z);
if (!world.isRemote && meta == 2 && entity instanceof EntityLivingBase) if (!world.isRemote && meta == 2 && entity instanceof EntityLivingBase)
{
if (entity instanceof EntityPlayer)
{
InventoryPlayer inventory = ((EntityPlayer)entity).inventory;
if (!((inventory.armorInventory[0] != null && inventory.armorInventory[0].itemID == Item.bootsLeather.itemID) && (inventory.armorInventory[1] != null && inventory.armorInventory[1].itemID == Item.legsLeather.itemID)))
{ {
((EntityLivingBase)entity).addPotionEffect(new PotionEffect(Potion.wither.id, 200)); ((EntityLivingBase)entity).addPotionEffect(new PotionEffect(Potion.wither.id, 200));
} }
} }
else
{
((EntityLivingBase)entity).addPotionEffect(new PotionEffect(Potion.wither.id, 200));
}
}
}
/** /**
* A randomly called display update to be able to add particles or other items for display * A randomly called display update to be able to add particles or other items for display

View File

@ -10,6 +10,7 @@ import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon; import net.minecraft.util.Icon;
@ -91,10 +92,23 @@ public class BlockBOPFlower2 extends BlockFlower
@Override @Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity)
{ {
if (world.getBlockMetadata(x, y, z) == 2) { if (world.getBlockMetadata(x, y, z) == 2)
{
if (entity instanceof EntityPlayer)
{
InventoryPlayer inventory = ((EntityPlayer)entity).inventory;
if (!((inventory.armorInventory[0] != null && inventory.armorInventory[0].itemID == Item.bootsLeather.itemID) && (inventory.armorInventory[1] != null && inventory.armorInventory[1].itemID == Item.legsLeather.itemID)))
{
entity.setFire(1); entity.setFire(1);
} }
} }
else
{
entity.setFire(1);
}
}
}
@Override @Override
public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int meta) public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int meta)

View File

@ -12,6 +12,7 @@ import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion; import net.minecraft.potion.Potion;
@ -270,14 +271,38 @@ public class BlockBOPPlant extends BlockFlower implements IShearable
{ {
int meta = world.getBlockMetadata(x, y, z); int meta = world.getBlockMetadata(x, y, z);
if (meta == 5) if (meta == 5)
{
if (entity instanceof EntityPlayer)
{
InventoryPlayer inventory = ((EntityPlayer)entity).inventory;
if (!((inventory.armorInventory[0] != null && inventory.armorInventory[0].itemID == Item.bootsLeather.itemID) && (inventory.armorInventory[1] != null && inventory.armorInventory[1].itemID == Item.legsLeather.itemID)))
{ {
entity.attackEntityFrom(DamageSource.cactus, 1); entity.attackEntityFrom(DamageSource.cactus, 1);
} }
}
else
{
entity.attackEntityFrom(DamageSource.cactus, 1);
}
}
if (meta == 12) if (meta == 12)
{
if (entity instanceof EntityPlayer)
{
InventoryPlayer inventory = ((EntityPlayer)entity).inventory;
if (!((inventory.armorInventory[0] != null && inventory.armorInventory[0].itemID == Item.bootsLeather.itemID) && (inventory.armorInventory[1] != null && inventory.armorInventory[1].itemID == Item.legsLeather.itemID)))
{ {
entity.attackEntityFrom(DamageSource.cactus, 1); entity.attackEntityFrom(DamageSource.cactus, 1);
} }
} }
else
{
entity.attackEntityFrom(DamageSource.cactus, 1);
}
}
}
@Override @Override
public int idPicked(World world, int x, int y, int z) public int idPicked(World world, int x, int y, int z)

Binary file not shown.

After

Width:  |  Height:  |  Size: 661 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 372 B

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 331 B

After

Width:  |  Height:  |  Size: 362 B