Made helper hooks for EntityLiving and EntityRenderer hooks for Optifine
This commit is contained in:
parent
0680e211fc
commit
0b1997a9e6
4 changed files with 154 additions and 76 deletions
|
@ -11,14 +11,20 @@ import net.minecraft.client.Minecraft;
|
|||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.EntityItem;
|
||||
import net.minecraft.src.EntityLiving;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemBlock;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.MathHelper;
|
||||
import net.minecraft.src.ModLoader;
|
||||
import net.minecraft.src.MovingObjectPosition;
|
||||
import net.minecraft.src.RenderBlocks;
|
||||
import net.minecraft.src.RenderEngine;
|
||||
import net.minecraft.src.RenderGlobal;
|
||||
import net.minecraft.src.Tessellator;
|
||||
import net.minecraft.src.TexturePackBase;
|
||||
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.client.event.TextureLoadEvent;
|
||||
import net.minecraftforge.common.IArmorTextureProvider;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
@ -215,39 +221,9 @@ public class ForgeHooksClient
|
|||
return _default;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is added for Optifine's convenience. And to explode if a ModMaker is developing.
|
||||
* @param texture
|
||||
*/
|
||||
public static void onTextureLoadPre(String texture)
|
||||
{
|
||||
if (Tessellator.renderingWorldRenderer)
|
||||
{
|
||||
String msg = String.format("Warning: Texture %s not preloaded, will cause render glitches!", texture);
|
||||
System.out.println(msg);
|
||||
if (Tessellator.class.getPackage() != null)
|
||||
{
|
||||
if (Tessellator.class.getPackage().equals("net.minecraft.src"))
|
||||
{
|
||||
Minecraft mc = ModLoader.getMinecraftInstance();
|
||||
if (mc.ingameGUI != null)
|
||||
{
|
||||
mc.ingameGUI.getChatGUI().printChatMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void onTextureLoad(String texture, TexturePackBase pack)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new TextureLoadEvent(texture, pack));
|
||||
}
|
||||
|
||||
public static boolean renderEntityItem(EntityItem entity, ItemStack item, float bobing, float rotation, Random random, RenderEngine engine, RenderBlocks renderBlocks)
|
||||
{
|
||||
IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item, ENTITY);
|
||||
|
||||
if (customRenderer == null)
|
||||
{
|
||||
return false;
|
||||
|
@ -262,7 +238,7 @@ public class ForgeHooksClient
|
|||
GL11.glTranslatef(0.0F, -bobing, 0.0F);
|
||||
}
|
||||
boolean is3D = customRenderer.shouldUseRenderHelper(ENTITY, item, BLOCK_3D);
|
||||
|
||||
|
||||
if (item.getItem() instanceof ItemBlock && (is3D || RenderBlocks.renderItemIn3d(Block.blocksList[item.itemID].getRenderType())))
|
||||
{
|
||||
engine.bindTexture(engine.getTexture(item.getItem().getTextureFile()));
|
||||
|
@ -314,8 +290,7 @@ public class ForgeHooksClient
|
|||
GL11.glScalef(1.0F, 1.0F, -1F);
|
||||
GL11.glRotatef(210F, 1.0F, 0.0F, 0.0F);
|
||||
GL11.glRotatef(45F, 0.0F, 1.0F, 0.0F);
|
||||
|
||||
|
||||
|
||||
if(inColor)
|
||||
{
|
||||
int color = Item.itemsList[item.itemID].getColorFromDamage(item.getItemDamage(), 0);
|
||||
|
@ -324,7 +299,7 @@ public class ForgeHooksClient
|
|||
float b = (float)(color & 0xff) / 255F;
|
||||
GL11.glColor4f(r, g, b, 1.0F);
|
||||
}
|
||||
|
||||
|
||||
GL11.glRotatef(-90F, 0.0F, 1.0F, 0.0F);
|
||||
renderBlocks.useInventoryTint = inColor;
|
||||
customRenderer.renderItem(INVENTORY, item, renderBlocks);
|
||||
|
@ -376,4 +351,60 @@ public class ForgeHooksClient
|
|||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
//Optifine Helper Functions u.u, these are here specifically for Optifine
|
||||
//Note: When using Optfine, these methods are invoked using reflection, which
|
||||
//incurs a major performance penalty.
|
||||
public static void orientBedCamera(Minecraft mc, EntityLiving entity)
|
||||
{
|
||||
int x = MathHelper.floor_double(entity.posX);
|
||||
int y = MathHelper.floor_double(entity.posY);
|
||||
int z = MathHelper.floor_double(entity.posZ);
|
||||
Block block = Block.blocksList[mc.theWorld.getBlockId(x, y, z)];
|
||||
|
||||
if (block != null && block.isBed(mc.theWorld, x, y, z, entity))
|
||||
{
|
||||
int var12 = block.getBedDirection(mc.theWorld, x, y, z);
|
||||
GL11.glRotatef((float)(var12 * 90), 0.0F, 1.0F, 0.0F);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean onDrawBlockHighlight(RenderGlobal context, EntityPlayer player, MovingObjectPosition target, int subID, ItemStack currentItem, float partialTicks)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new DrawBlockHighlightEvent(context, player, target, subID, currentItem, partialTicks));
|
||||
}
|
||||
|
||||
public static void dispatchRenderLast(RenderGlobal context, float partialTicks)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new RenderWorldLastEvent(context, partialTicks));
|
||||
}
|
||||
|
||||
public static void onTextureLoad(String texture, TexturePackBase pack)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new TextureLoadEvent(texture, pack));
|
||||
}
|
||||
|
||||
/**
|
||||
* This is added for Optifine's convenience. And to explode if a ModMaker is developing.
|
||||
* @param texture
|
||||
*/
|
||||
public static void onTextureLoadPre(String texture)
|
||||
{
|
||||
if (Tessellator.renderingWorldRenderer)
|
||||
{
|
||||
String msg = String.format("Warning: Texture %s not preloaded, will cause render glitches!", texture);
|
||||
System.out.println(msg);
|
||||
if (Tessellator.class.getPackage() != null)
|
||||
{
|
||||
if (Tessellator.class.getPackage().equals("net.minecraft.src"))
|
||||
{
|
||||
Minecraft mc = ModLoader.getMinecraftInstance();
|
||||
if (mc.ingameGUI != null)
|
||||
{
|
||||
mc.ingameGUI.getChatGUI().printChatMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package net.minecraftforge.common;
|
|||
import java.util.*;
|
||||
|
||||
import net.minecraft.src.*;
|
||||
import net.minecraftforge.event.entity.living.*;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent.*;
|
||||
|
||||
public class ForgeHooks
|
||||
{
|
||||
|
@ -284,4 +286,54 @@ public class ForgeHooks
|
|||
player.inventory.currentItem = slot;
|
||||
return true;
|
||||
}
|
||||
|
||||
//Optifine Helper Functions u.u, these are here specifically for Optifine
|
||||
//Note: When using Optfine, these methods are invoked using reflection, which
|
||||
//incurs a major performance penalty.
|
||||
public static void onLivingSetAttackTarget(EntityLiving entity, EntityLiving target)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new LivingSetAttackTargetEvent(entity, target));
|
||||
}
|
||||
|
||||
public static boolean onLivingUpdate(EntityLiving entity)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new LivingUpdateEvent(entity));
|
||||
}
|
||||
|
||||
public static boolean onLivingAttack(EntityLiving entity, DamageSource src, int amount)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new LivingAttackEvent(entity, src, amount));
|
||||
}
|
||||
|
||||
public static int onLivingHurt(EntityLiving entity, DamageSource src, int amount)
|
||||
{
|
||||
LivingHurtEvent event = new LivingHurtEvent(entity, src, amount);
|
||||
return (MinecraftForge.EVENT_BUS.post(event) ? 0 : event.ammount);
|
||||
}
|
||||
|
||||
public static boolean onLivingDeath(EntityLiving entity, DamageSource src)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new LivingDeathEvent(entity, src));
|
||||
}
|
||||
|
||||
public static boolean onLivingDrops(EntityLiving entity, DamageSource source, ArrayList<EntityItem> drops, int lootingLevel, boolean recentlyHit, int specialDropValue)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new LivingDropsEvent(entity, source, drops, lootingLevel, recentlyHit, specialDropValue));
|
||||
}
|
||||
|
||||
public static float onLivingFall(EntityLiving entity, float distance)
|
||||
{
|
||||
LivingFallEvent event = new LivingFallEvent(entity, distance);
|
||||
return (MinecraftForge.EVENT_BUS.post(event) ? 0.0f : event.distance);
|
||||
}
|
||||
|
||||
public static boolean isLivingOnLadder(Block block, World world, int x, int y, int z)
|
||||
{
|
||||
return block != null && block.isLadder(world, x, y, z);
|
||||
}
|
||||
|
||||
public static void onLivingJump(EntityLiving entity)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new LivingJumpEvent(entity));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
public void setAttackTarget(EntityLiving par1EntityLiving)
|
||||
{
|
||||
this.attackTarget = par1EntityLiving;
|
||||
+ MinecraftForge.EVENT_BUS.post(new LivingSetAttackTargetEvent(this, par1EntityLiving));
|
||||
+ ForgeHooks.onLivingSetAttackTarget(this, par1EntityLiving);
|
||||
}
|
||||
|
||||
public boolean isExplosiveMob(Class par1Class)
|
||||
|
@ -23,7 +23,7 @@
|
|||
{
|
||||
this.entityLivingToAttack = par1EntityLiving;
|
||||
this.revengeTimer = this.entityLivingToAttack != null ? 60 : 0;
|
||||
+ MinecraftForge.EVENT_BUS.post(new LivingSetAttackTargetEvent(this, par1EntityLiving));
|
||||
+ ForgeHooks.onLivingSetAttackTarget(this, par1EntityLiving);
|
||||
}
|
||||
|
||||
protected void entityInit()
|
||||
|
@ -31,7 +31,7 @@
|
|||
*/
|
||||
public void onUpdate()
|
||||
{
|
||||
+ if (MinecraftForge.EVENT_BUS.post(new LivingUpdateEvent(this)))
|
||||
+ if (ForgeHooks.onLivingUpdate(this))
|
||||
+ {
|
||||
+ return;
|
||||
+ }
|
||||
|
@ -43,7 +43,7 @@
|
|||
*/
|
||||
public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
|
||||
{
|
||||
+ if (MinecraftForge.EVENT_BUS.post(new LivingAttackEvent(this, par1DamageSource, par2)))
|
||||
+ if (ForgeHooks.onLivingAttack(this, par1DamageSource, par2))
|
||||
+ {
|
||||
+ return false;
|
||||
+ }
|
||||
|
@ -51,25 +51,24 @@
|
|||
if (this.worldObj.isRemote)
|
||||
{
|
||||
return false;
|
||||
@@ -1007,6 +1023,13 @@
|
||||
@@ -1007,6 +1023,12 @@
|
||||
*/
|
||||
protected void damageEntity(DamageSource par1DamageSource, int par2)
|
||||
{
|
||||
+ LivingHurtEvent event = new LivingHurtEvent(this, par1DamageSource, par2);
|
||||
+ if (MinecraftForge.EVENT_BUS.post(event) || event.ammount== 0)
|
||||
+ par2 = ForgeHooks.onLivingHurt(this, par1DamageSource, par2);
|
||||
+ if (par2 <= 0)
|
||||
+ {
|
||||
+ return;
|
||||
+ }
|
||||
+ par2 = event.ammount;
|
||||
+
|
||||
par2 = this.applyArmorCalculations(par1DamageSource, par2);
|
||||
par2 = this.applyPotionDamageCalculations(par1DamageSource, par2);
|
||||
this.health -= par2;
|
||||
@@ -1070,6 +1093,11 @@
|
||||
@@ -1070,6 +1092,11 @@
|
||||
*/
|
||||
public void onDeath(DamageSource par1DamageSource)
|
||||
{
|
||||
+ if (MinecraftForge.EVENT_BUS.post(new LivingDeathEvent(this, par1DamageSource)))
|
||||
+ if (ForgeHooks.onLivingDeath(this, par1DamageSource))
|
||||
+ {
|
||||
+ return;
|
||||
+ }
|
||||
|
@ -77,7 +76,7 @@
|
|||
Entity var2 = par1DamageSource.getEntity();
|
||||
|
||||
if (this.scoreValue >= 0 && var2 != null)
|
||||
@@ -1093,13 +1121,17 @@
|
||||
@@ -1093,13 +1120,17 @@
|
||||
var3 = EnchantmentHelper.getLootingModifier(((EntityPlayer)var2).inventory);
|
||||
}
|
||||
|
||||
|
@ -96,14 +95,14 @@
|
|||
|
||||
if (var4 < 5)
|
||||
{
|
||||
@@ -1107,6 +1139,16 @@
|
||||
@@ -1107,6 +1138,16 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
+
|
||||
+ captureDrops = false;
|
||||
+
|
||||
+ if (!MinecraftForge.EVENT_BUS.post(new LivingDropsEvent(this, par1DamageSource, capturedDrops, var3, recentlyHit > 0, var4)))
|
||||
+
|
||||
+ if (!ForgeHooks.onLivingDrops(this, par1DamageSource, capturedDrops, var3, recentlyHit > 0, var4))
|
||||
+ {
|
||||
+ for (EntityItem item : capturedDrops)
|
||||
+ {
|
||||
|
@ -113,34 +112,33 @@
|
|||
}
|
||||
|
||||
this.worldObj.setEntityState(this, (byte)3);
|
||||
@@ -1150,6 +1192,13 @@
|
||||
@@ -1150,6 +1191,12 @@
|
||||
*/
|
||||
protected void fall(float par1)
|
||||
{
|
||||
+ LivingFallEvent event = new LivingFallEvent(this, par1);
|
||||
+ if (MinecraftForge.EVENT_BUS.post(event))
|
||||
+ par1 = ForgeHooks.onLivingFall(this, par1);
|
||||
+ if (par1 <= 0)
|
||||
+ {
|
||||
+ return;
|
||||
+ }
|
||||
+ par1 = event.distance;
|
||||
+
|
||||
super.fall(par1);
|
||||
int var2 = MathHelper.ceiling_float_int(par1 - 3.0F);
|
||||
|
||||
@@ -1337,7 +1386,7 @@
|
||||
@@ -1337,7 +1384,7 @@
|
||||
int var2 = MathHelper.floor_double(this.boundingBox.minY);
|
||||
int var3 = MathHelper.floor_double(this.posZ);
|
||||
int var4 = this.worldObj.getBlockId(var1, var2, var3);
|
||||
- return var4 == Block.ladder.blockID || var4 == Block.vine.blockID;
|
||||
+ return Block.blocksList[var4] != null && Block.blocksList[var4].isLadder(worldObj, var1, var2, var3);
|
||||
+ return ForgeHooks.isLivingOnLadder(Block.blocksList[var4], worldObj, var1, var2, var3);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1600,6 +1649,7 @@
|
||||
@@ -1600,6 +1647,7 @@
|
||||
}
|
||||
|
||||
this.isAirBorne = true;
|
||||
+ MinecraftForge.EVENT_BUS.post(new LivingJumpEvent(this));
|
||||
+ ForgeHooks.onLivingJump(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,33 +39,30 @@
|
|||
float var4 = 70.0F;
|
||||
|
||||
if (par2)
|
||||
@@ -397,11 +409,14 @@
|
||||
@@ -396,15 +408,7 @@
|
||||
|
||||
if (!this.mc.gameSettings.debugCamEnable)
|
||||
{
|
||||
int var10 = this.mc.theWorld.getBlockId(MathHelper.floor_double(var2.posX), MathHelper.floor_double(var2.posY), MathHelper.floor_double(var2.posZ));
|
||||
- int var10 = this.mc.theWorld.getBlockId(MathHelper.floor_double(var2.posX), MathHelper.floor_double(var2.posY), MathHelper.floor_double(var2.posZ));
|
||||
-
|
||||
- if (var10 == Block.bed.blockID)
|
||||
- {
|
||||
- int var11 = this.mc.theWorld.getBlockMetadata(MathHelper.floor_double(var2.posX), MathHelper.floor_double(var2.posY), MathHelper.floor_double(var2.posZ));
|
||||
- int var12 = var11 & 3;
|
||||
+ int x = MathHelper.floor_double(var2.posX);
|
||||
+ int y = MathHelper.floor_double(var2.posY);
|
||||
+ int z = MathHelper.floor_double(var2.posZ);
|
||||
+ Block block = Block.blocksList[mc.theWorld.getBlockId(x, y, z)];
|
||||
+
|
||||
+ if (block != null && block.isBed(mc.theWorld, x, y, z, var2))
|
||||
+ {
|
||||
+ int var12 = block.getBedDirection(mc.theWorld, x, y, z);
|
||||
GL11.glRotatef((float)(var12 * 90), 0.0F, 1.0F, 0.0F);
|
||||
}
|
||||
|
||||
@@ -1037,8 +1052,11 @@
|
||||
- GL11.glRotatef((float)(var12 * 90), 0.0F, 1.0F, 0.0F);
|
||||
- }
|
||||
-
|
||||
+ ForgeHooksClient.orientBedCamera(mc, var2);
|
||||
GL11.glRotatef(var2.prevRotationYaw + (var2.rotationYaw - var2.prevRotationYaw) * par1 + 180.0F, 0.0F, -1.0F, 0.0F);
|
||||
GL11.glRotatef(var2.prevRotationPitch + (var2.rotationPitch - var2.prevRotationPitch) * par1, -1.0F, 0.0F, 0.0F);
|
||||
}
|
||||
@@ -1037,8 +1041,11 @@
|
||||
var17 = (EntityPlayer)var4;
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
this.mc.mcProfiler.endStartSection("outline");
|
||||
- var5.drawBlockBreaking(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1);
|
||||
- var5.drawSelectionBox(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1);
|
||||
+ if (!MinecraftForge.EVENT_BUS.post(new DrawBlockHighlightEvent(var5, var17, mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1)))
|
||||
+ if (!ForgeHooksClient.onDrawBlockHighlight(var5, var17, mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1))
|
||||
+ {
|
||||
+ var5.drawBlockBreaking(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1);
|
||||
+ var5.drawSelectionBox(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1);
|
||||
|
@ -73,13 +70,13 @@
|
|||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
}
|
||||
}
|
||||
@@ -1102,8 +1120,11 @@
|
||||
@@ -1102,8 +1109,11 @@
|
||||
var17 = (EntityPlayer)var4;
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
this.mc.mcProfiler.endStartSection("outline");
|
||||
- var5.drawBlockBreaking(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1);
|
||||
- var5.drawSelectionBox(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1);
|
||||
+ if (!MinecraftForge.EVENT_BUS.post(new DrawBlockHighlightEvent(var5, var17, mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1)))
|
||||
+ if (!ForgeHooksClient.onDrawBlockHighlight(var5, var17, mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1))
|
||||
+ {
|
||||
+ var5.drawBlockBreaking(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1);
|
||||
+ var5.drawSelectionBox(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1);
|
||||
|
@ -87,13 +84,13 @@
|
|||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
}
|
||||
|
||||
@@ -1127,6 +1148,9 @@
|
||||
@@ -1127,6 +1137,9 @@
|
||||
this.setupFog(1, par1);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
+
|
||||
+ this.mc.mcProfiler.endStartSection("fhooks");
|
||||
+ MinecraftForge.EVENT_BUS.post(new RenderWorldLastEvent(var5, par1));
|
||||
+ this.mc.mcProfiler.endStartSection("FRenderLast");
|
||||
+ ForgeHooksClient.dispatchRenderLast(var5, par1);
|
||||
|
||||
this.mc.mcProfiler.endStartSection("hand");
|
||||
|
||||
|
|
Loading…
Reference in a new issue