mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-28 07:55:53 +00:00
More conversions, added all the entity living events.
This commit is contained in:
1 parent
4e91293271
commit
41f1a60f32
43 files changed
+1343
-207
No files matched your search
@@ -1,16 +1,29 @@
|
||||
package net.minecraftforge.client;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.EntityItem;
|
||||
import net.minecraft.src.EntityLiving;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemBlock;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.ModLoader;
|
||||
import net.minecraft.src.RenderBlocks;
|
||||
import net.minecraft.src.RenderEngine;
|
||||
import net.minecraft.src.Tessellator;
|
||||
import net.minecraft.src.TexturePackBase;
|
||||
import net.minecraftforge.client.event.TextureLoadEvent;
|
||||
import net.minecraftforge.common.IArmorTextureProvider;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import static net.minecraftforge.client.IItemRenderer.ItemRenderType.*;
|
||||
import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.*;
|
||||
|
||||
public class ForgeHooksClient
|
||||
{
|
||||
@@ -201,4 +214,166 @@ 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.func_73827_b().func_73765_a(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;
|
||||
}
|
||||
|
||||
if (customRenderer.shouldUseRenderHelper(ENTITY, item, ENTITY_ROTATION))
|
||||
{
|
||||
GL11.glRotatef(rotation, 0.0F, 1.0F, 0.0F);
|
||||
}
|
||||
if (!customRenderer.shouldUseRenderHelper(ENTITY, item, ENTITY_BOBBING))
|
||||
{
|
||||
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()));
|
||||
int renderType = Block.blocksList[item.itemID].getRenderType();
|
||||
float scale = (renderType == 1 || renderType == 19 || renderType == 12 || renderType == 2 ? 0.5F : 0.25F);
|
||||
|
||||
GL11.glScalef(scale, scale, scale);
|
||||
int size = entity.item.stackSize;
|
||||
int count = (size > 20 ? 4 : (size > 5 ? 3 : (size > 1 ? 2 : 1)));
|
||||
|
||||
for(int j = 0; j < size; j++)
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
if (j > 0)
|
||||
{
|
||||
GL11.glTranslatef(
|
||||
((random.nextFloat() * 2.0F - 1.0F) * 0.2F) / 0.5F,
|
||||
((random.nextFloat() * 2.0F - 1.0F) * 0.2F) / 0.5F,
|
||||
((random.nextFloat() * 2.0F - 1.0F) * 0.2F) / 0.5F);
|
||||
}
|
||||
customRenderer.renderItem(ENTITY, item, renderBlocks, entity);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
engine.bindTexture(engine.getTexture(item.getItem().getTextureFile()));
|
||||
GL11.glScalef(0.5F, 0.5F, 0.5F);
|
||||
customRenderer.renderItem(ENTITY, item, renderBlocks, entity);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean renderInventoryItem(RenderBlocks renderBlocks, RenderEngine engine, ItemStack item, boolean inColor, float zLevel, float x, float y)
|
||||
{
|
||||
IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item, INVENTORY);
|
||||
if (customRenderer == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
engine.bindTexture(engine.getTexture(Item.itemsList[item.itemID].getTextureFile()));
|
||||
if (customRenderer.shouldUseRenderHelper(INVENTORY, item, INVENTORY_BLOCK))
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(x - 2, y + 3, -3.0F + zLevel);
|
||||
GL11.glScalef(10F, 10F, 10F);
|
||||
GL11.glTranslatef(1.0F, 0.5F, 1.0F);
|
||||
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);
|
||||
float r = (float)(color >> 16 & 0xff) / 255F;
|
||||
float g = (float)(color >> 8 & 0xff) / 255F;
|
||||
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);
|
||||
renderBlocks.useInventoryTint = true;
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
else
|
||||
{
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(x, y, -3.0F + zLevel);
|
||||
|
||||
if (inColor)
|
||||
{
|
||||
int color = Item.itemsList[item.itemID].getColorFromDamage(item.getItemDamage(), 0);
|
||||
float r = (float)(color >> 16 & 255) / 255.0F;
|
||||
float g = (float)(color >> 8 & 255) / 255.0F;
|
||||
float b = (float)(color & 255) / 255.0F;
|
||||
GL11.glColor4f(r, g, b, 1.0F);
|
||||
}
|
||||
|
||||
customRenderer.renderItem(INVENTORY, item, renderBlocks);
|
||||
GL11.glPopMatrix();
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void renderEquippedItem(IItemRenderer customRenderer, RenderBlocks renderBlocks, EntityLiving entity, ItemStack item)
|
||||
{
|
||||
if (customRenderer.shouldUseRenderHelper(EQUIPPED, item, EQUIPPED_BLOCK))
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
|
||||
customRenderer.renderItem(EQUIPPED, item, renderBlocks, entity);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
else
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glTranslatef(0.0F, -0.3F, 0.0F);
|
||||
GL11.glScalef(1.5F, 1.5F, 1.5F);
|
||||
GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F);
|
||||
GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F);
|
||||
GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F);
|
||||
customRenderer.renderItem(EQUIPPED, item, renderBlocks, entity);
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user