Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.

Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
This commit is contained in:
Lex Manos committed 2014-11-26 00:00:54 -08:00
1 parent 0e91787efb
commit 53659fca06
410 files changed
+8717 -14103

No files matched your search

@@ -12,17 +12,17 @@ import net.minecraft.command.WrongUsageException;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.CommandEvent;
import cpw.mods.fml.client.FMLClientHandler;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraft.util.EnumChatFormatting;
import static net.minecraft.util.EnumChatFormatting.*;
/**
* The class that handles client-side chat commands. You should register any
* commands that you want handled on the client with this command handler.
*
*
* If there is a command with the same name registered both on the server and
* client, the client takes precedence!
*
*
*/
public class ClientCommandHandler extends CommandHandler
{
@@ -114,7 +114,7 @@ public class ClientCommandHandler extends CommandHandler
if (mc.currentScreen instanceof GuiChat)
{
@SuppressWarnings("unchecked")
List<String> commands = getPossibleCommands(mc.thePlayer, leftOfCursor);
List<String> commands = getTabCompletionOptions(mc.thePlayer, leftOfCursor, mc.thePlayer.getPosition());
if (commands != null && !commands.isEmpty())
{
if (leftOfCursor.indexOf(' ') == -1)
@@ -1,70 +1,69 @@
package net.minecraftforge.client;
import static net.minecraftforge.common.ForgeVersion.Status.BETA;
import static net.minecraftforge.common.ForgeVersion.Status.BETA_OUTDATED;
import java.util.Random;
import javax.imageio.ImageIO;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraft.block.Block;
import net.minecraft.block.BlockBed;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.SoundEventAccessorComposite;
import net.minecraft.client.audio.SoundManager;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraftforge.client.event.FOVUpdateEvent;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import org.lwjgl.opengl.PixelFormat;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLLog;
import net.minecraft.client.Minecraft;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.ChunkCache;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.GameSettings;
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
import net.minecraftforge.client.event.EntityViewRenderEvent;
import net.minecraftforge.client.event.FOVUpdateEvent;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.client.event.RenderWorldEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.client.event.sound.PlaySoundEvent17;
import net.minecraftforge.client.event.sound.PlaySoundEvent;
import net.minecraftforge.common.ForgeModContainer;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.common.ForgeVersion.Status;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.RenderBlockFluid;
import static net.minecraftforge.client.IItemRenderer.ItemRenderType.*;
import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.*;
import static net.minecraftforge.common.ForgeVersion.Status.*;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.FMLLog;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.PixelFormat;
//import static net.minecraftforge.client.IItemRenderer.ItemRenderType.*;
//import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.*;
public class ForgeHooksClient
{
@@ -81,6 +80,8 @@ public class ForgeHooksClient
return result != null ? result : _default;
}
/*
* Removed, Modders let me know if this is needed anymore.
public static boolean renderEntityItem(EntityItem entity, ItemStack item, float bobing, float rotation, Random random, TextureManager engine, RenderBlocks renderBlocks, int count)
{
IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item, ENTITY);
@@ -147,9 +148,12 @@ public class ForgeHooksClient
GL11.glScalef(0.5F, 0.5F, 0.5F);
customRenderer.renderItem(ENTITY, item, renderBlocks, entity);
}
return true;
}
*/
/*
public static boolean renderInventoryItem(RenderBlocks renderBlocks, TextureManager engine, ItemStack item, boolean inColor, float zLevel, float x, float y)
{
IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item, INVENTORY);
@@ -233,21 +237,18 @@ public class ForgeHooksClient
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
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, EntityLivingBase entity)
public static void orientBedCamera(IBlockAccess world, BlockPos pos, IBlockState state, Entity entity)
{
int x = MathHelper.floor_double(entity.posX);
int y = MathHelper.floor_double(entity.posY);
int z = MathHelper.floor_double(entity.posZ);
Block block = mc.theWorld.getBlock(x, y, z);
Block block = state.getBlock();
if (block != null && block.isBed(mc.theWorld, x, y, z, entity))
if (block != null && block.isBed(world, pos, entity))
{
GL11.glRotatef((float)(block.getBedDirection(mc.theWorld, x, y, z) * 90), 0.0F, 1.0F, 0.0F);
GL11.glRotatef((float)(block.getBedDirection(world, pos).getHorizontalIndex() * 90), 0.0F, 1.0F, 0.0F);
}
}
@@ -275,31 +276,8 @@ public class ForgeHooksClient
{
MinecraftForge.EVENT_BUS.post(new TextureStitchEvent.Post(map));
FluidRegistry.WATER.setIcons(BlockLiquid.getLiquidIcon("water_still"), BlockLiquid.getLiquidIcon("water_flow"));
FluidRegistry.LAVA.setIcons(BlockLiquid.getLiquidIcon("lava_still"), BlockLiquid.getLiquidIcon("lava_flow"));
}
/**
* 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)
{
FMLLog.warning("Warning: Texture %s not preloaded, will cause render glitches!", texture);
if (Tessellator.class.getPackage() != null)
{
if (Tessellator.class.getPackage().getName().startsWith("net.minecraft."))
{
Minecraft mc = FMLClientHandler.instance().getClient();
if (mc.ingameGUI != null)
{
mc.ingameGUI.getChatGUI().printChatMessage(new ChatComponentTranslation("forge.texture.preload.warning", texture));
}
}
}
}
//FluidRegistry.WATER.setIcons(BlockLiquid.getLiquidIcon("water_still"), BlockLiquid.getLiquidIcon("water_flow"));
//FluidRegistry.LAVA.setIcons(BlockLiquid.getLiquidIcon("lava_still"), BlockLiquid.getLiquidIcon("lava_flow"));
}
static int renderPass = -1;
@@ -308,37 +286,10 @@ public class ForgeHooksClient
renderPass = pass;
}
public static ModelBiped getArmorModel(EntityLivingBase entityLiving, ItemStack itemStack, int slotID, ModelBiped _default)
public static ModelBase getArmorModel(EntityLivingBase entityLiving, ItemStack itemStack, int slotID, ModelBase _default)
{
ModelBiped modelbiped = itemStack.getItem().getArmorModel(entityLiving, itemStack, slotID);
return modelbiped == null ? _default : modelbiped;
}
static int stencilBits = 0;
public static void createDisplay() throws LWJGLException
{
ImageIO.setUseCache(false); //Disable on-disc stream cache should speed up texture pack reloading.
PixelFormat format = new PixelFormat().withDepthBits(24);
if (!Boolean.parseBoolean(System.getProperty("forge.forceDisplayStencil", "false")))
{
//Creating the display with Stencil bits causes issues on some displays.
//According to ChickenBones, Mumfrey and Pig The only real use is in the FBO.
//So lets default to normal init to fix the issues yet add the bits to the FBO.
Display.create(format);
stencilBits = 0;
return;
}
try
{
//TODO: Figure out how to determine the max bits.
Display.create(format.withStencilBits(8));
stencilBits = 8;
}
catch(LWJGLException e)
{
Display.create(format);
stencilBits = 0;
}
ModelBase modelbase = itemStack.getItem().getArmorModel(entityLiving, itemStack, slotID);
return modelbase == null ? _default : modelbase;
}
//This properly moves the domain, if provided, to the front of the string before concatenating
@@ -367,7 +318,7 @@ public class ForgeHooksClient
return MinecraftForge.EVENT_BUS.post(new MouseEvent());
}
public static float getOffsetFOV(EntityPlayerSP entity, float fov)
public static float getOffsetFOV(EntityPlayer entity, float fov)
{
FOVUpdateEvent fovUpdateEvent = new FOVUpdateEvent(entity, fov);
MinecraftForge.EVENT_BUS.post(fovUpdateEvent);
@@ -379,9 +330,9 @@ public class ForgeHooksClient
private static boolean skyInit;
private static int skyRGBMultiplier;
public static int getSkyBlendColour(World world, int playerX, int playerY, int playerZ)
public static int getSkyBlendColour(World world, BlockPos center)
{
if (playerX == skyX && playerZ == skyZ && skyInit)
if (center.getX() == skyX && center.getZ() == skyZ && skyInit)
{
return skyRGBMultiplier;
}
@@ -404,8 +355,9 @@ public class ForgeHooksClient
{
for (int z = -distance; z <= distance; ++z)
{
BiomeGenBase biome = world.getBiomeGenForCoords(playerX + x, playerZ + z);
int colour = biome.getSkyColorByTemp(biome.getFloatTemperature(playerX + x, playerY, playerZ + z));
BlockPos pos = center.add(x, 0, z);
BiomeGenBase biome = world.getBiomeGenForCoords(pos);
int colour = biome.getSkyColorByTemp(biome.func_180626_a(pos));
r += (colour & 0xFF0000) >> 16;
g += (colour & 0x00FF00) >> 8;
b += colour & 0x0000FF;
@@ -415,8 +367,8 @@ public class ForgeHooksClient
int multiplier = (r / divider & 255) << 16 | (g / divider & 255) << 8 | b / divider & 255;
skyX = playerX;
skyZ = playerZ;
skyX = center.getX();
skyZ = center.getY();
skyRGBMultiplier = multiplier;
return skyRGBMultiplier;
}
@@ -425,8 +377,8 @@ public class ForgeHooksClient
*/
static
{
FluidRegistry.renderIdFluid = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerBlockHandler(RenderBlockFluid.instance);
//FluidRegistry.renderIdFluid = RenderingRegistry.getNextAvailableRenderId();
//RenderingRegistry.registerBlockHandler(RenderBlockFluid.instance);
}
public static void renderMainMenu(GuiMainMenu gui, FontRenderer font, int width, int height)
@@ -461,13 +413,13 @@ public class ForgeHooksClient
public static ISound playSound(SoundManager manager, ISound sound)
{
SoundEventAccessorComposite accessor = manager.sndHandler.getSound(sound.getPositionedSoundLocation());
PlaySoundEvent17 e = new PlaySoundEvent17(manager, sound, (accessor == null ? null : accessor.getSoundCategory()));
SoundEventAccessorComposite accessor = manager.sndHandler.getSound(sound.getSoundLocation());
PlaySoundEvent e = new PlaySoundEvent(manager, sound, (accessor == null ? null : accessor.getSoundCategory()));
MinecraftForge.EVENT_BUS.post(e);
return e.result;
}
static RenderBlocks worldRendererRB;
//static RenderBlocks worldRendererRB;
static int worldRenderPass;
public static int getWorldRenderPass()
@@ -475,6 +427,26 @@ public class ForgeHooksClient
return worldRenderPass;
}
public static void drawScreen(GuiScreen screen, int mouseX, int mouseY, float partialTicks)
{
if (!MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.DrawScreenEvent.Pre(screen, mouseX, mouseY, partialTicks)))
screen.drawScreen(mouseX, mouseY, partialTicks);
MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.DrawScreenEvent.Post(screen, mouseX, mouseY, partialTicks));
}
public static float getFogDensity(EntityRenderer renderer, Entity entity, Block block, float partial, float density)
{
EntityViewRenderEvent.FogDensity event = new EntityViewRenderEvent.FogDensity(renderer, entity, block, partial, density);
if (MinecraftForge.EVENT_BUS.post(event)) return event.density;
return -1;
}
public static void onFogRender(EntityRenderer renderer, Entity entity, Block block, float partial, int mode, float distance)
{
MinecraftForge.EVENT_BUS.post(new EntityViewRenderEvent.RenderFogEvent(renderer, entity, block, partial, mode, distance));
}
/*
public static void setWorldRendererRB(RenderBlocks renderBlocks)
{
worldRendererRB = renderBlocks;
@@ -497,4 +469,5 @@ public class ForgeHooksClient
worldRenderPass = -1;
}
}
*/
}
@@ -11,9 +11,10 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiIngame;
import net.minecraft.client.gui.GuiPlayerInfo;
import net.minecraft.client.gui.GuiOverlayDebug;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.resources.I18n;
@@ -21,6 +22,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
@@ -29,7 +31,7 @@ import net.minecraft.potion.Potion;
import net.minecraft.scoreboard.Score;
import net.minecraft.scoreboard.ScoreObjective;
import net.minecraft.scoreboard.ScorePlayerTeam;
import net.minecraft.util.Direction;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.FoodStats;
import net.minecraft.util.MathHelper;
@@ -45,7 +47,9 @@ import net.minecraftforge.common.MinecraftForge;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import cpw.mods.fml.common.FMLCommonHandler;
import com.google.common.base.Strings;
import net.minecraftforge.fml.common.FMLCommonHandler;
public class GuiIngameForge extends GuiIngame
{
@@ -79,17 +83,19 @@ public class GuiIngameForge extends GuiIngame
private FontRenderer fontrenderer = null;
private RenderGameOverlayEvent eventParent;
private static final String MC_VERSION = MinecraftForge.MC_VERSION;
private GuiOverlayDebugForge debugOverlay;
public GuiIngameForge(Minecraft mc)
{
super(mc);
debugOverlay = new GuiOverlayDebugForge(mc);
}
@Override
public void renderGameOverlay(float partialTicks, boolean hasScreen, int mouseX, int mouseY)
public void func_175180_a(float partialTicks)
{
res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
eventParent = new RenderGameOverlayEvent(partialTicks, res, mouseX, mouseY);
eventParent = new RenderGameOverlayEvent(partialTicks, res);
int width = res.getScaledWidth();
int height = res.getScaledHeight();
renderHealthMount = mc.thePlayer.ridingEntity instanceof EntityLivingBase;
@@ -101,45 +107,44 @@ public class GuiIngameForge extends GuiIngame
if (pre(ALL)) return;
fontrenderer = mc.fontRenderer;
fontrenderer = mc.fontRendererObj;
mc.entityRenderer.setupOverlayRendering();
GL11.glEnable(GL11.GL_BLEND);
GlStateManager.enableBlend();
if (Minecraft.isFancyGraphicsEnabled())
{
renderVignette(mc.thePlayer.getBrightness(partialTicks), width, height);
func_180480_a(mc.thePlayer.getBrightness(partialTicks), res);
}
else
{
OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
}
if (renderHelmet) renderHelmet(res, partialTicks, hasScreen, mouseX, mouseY);
if (renderHelmet) renderHelmet(res, partialTicks);
if (renderPortal && !mc.thePlayer.isPotionActive(Potion.confusion))
{
renderPortal(width, height, partialTicks);
renderPortal(res, partialTicks);
}
if (!mc.playerController.enableEverythingIsScrewedUpMode())
if (renderHotbar) func_180479_a(res, partialTicks);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
zLevel = -90.0F;
rand.setSeed((long)(updateCounter * 312871));
if (renderCrosshairs) renderCrosshairs(width, height);
if (renderBossHealth) renderBossHealth();
if (this.mc.playerController.shouldDrawHUD() && this.mc.func_175606_aa() instanceof EntityPlayer)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
zLevel = -90.0F;
rand.setSeed((long)(updateCounter * 312871));
if (renderCrosshairs) renderCrosshairs(width, height);
if (renderBossHealth) renderBossHealth();
if (this.mc.playerController.shouldDrawHUD())
{
if (renderHealth) renderHealth(width, height);
if (renderArmor) renderArmor(width, height);
if (renderFood) renderFood(width, height);
if (renderHealthMount) renderHealthMount(width, height);
if (renderAir) renderAir(width, height);
}
if (renderHotbar) renderHotbar(width, height, partialTicks);
if (renderHealth) renderHealth(width, height);
if (renderArmor) renderArmor(width, height);
if (renderFood) renderFood(width, height);
if (renderHealthMount) renderHealthMount(width, height);
if (renderAir) renderAir(width, height);
}
renderSleepFade(width, height);
if (renderJumpBar)
{
@@ -150,28 +155,37 @@ public class GuiIngameForge extends GuiIngame
renderExperience(width, height);
}
renderSleepFade(width, height);
renderToolHightlight(width, height);
renderToolHightlight(res);
renderHUDText(width, height);
renderRecordOverlay(width, height, partialTicks);
renderTitle(width, height, partialTicks);
ScoreObjective objective = mc.theWorld.getScoreboard().func_96539_a(1);
Scoreboard scoreboard = this.mc.theWorld.getScoreboard();
ScoreObjective objective = null;
ScorePlayerTeam scoreplayerteam = scoreboard.getPlayersTeam(mc.thePlayer.getName());
if (scoreplayerteam != null)
{
int slot = scoreplayerteam.func_178775_l().func_175746_b();
if (slot >= 0) objective = scoreboard.getObjectiveInDisplaySlot(3 + slot);
}
ScoreObjective scoreobjective1 = objective != null ? objective : scoreboard.getObjectiveInDisplaySlot(1);
if (renderObjective && objective != null)
{
this.func_96136_a(objective, height, width, fontrenderer);
this.func_180475_a(objective, res);
}
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
GlStateManager.disableAlpha();
renderChat(width, height);
renderPlayerList(width, height);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableLighting();
GlStateManager.enableAlpha();
post(ALL);
}
@@ -181,46 +195,19 @@ public class GuiIngameForge extends GuiIngame
return res;
}
protected void renderHotbar(int width, int height, float partialTicks)
{
if (pre(HOTBAR)) return;
mc.mcProfiler.startSection("actionBar");
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(WIDGITS);
InventoryPlayer inv = mc.thePlayer.inventory;
drawTexturedModalRect(width / 2 - 91, height - 22, 0, 0, 182, 22);
drawTexturedModalRect(width / 2 - 91 - 1 + inv.currentItem * 20, height - 22 - 1, 0, 22, 24, 22);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
RenderHelper.enableGUIStandardItemLighting();
for (int i = 0; i < 9; ++i)
{
int x = width / 2 - 90 + i * 20 + 2;
int z = height - 16 - 3;
renderInventorySlot(i, x, z, partialTicks);
}
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
mc.mcProfiler.endSection();
post(HOTBAR);
}
protected void renderCrosshairs(int width, int height)
{
if (pre(CROSSHAIRS)) return;
bind(Gui.icons);
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(GL11.GL_ONE_MINUS_DST_COLOR, GL11.GL_ONE_MINUS_SRC_COLOR, 1, 0);
drawTexturedModalRect(width / 2 - 7, height / 2 - 7, 0, 0, 16, 16);
OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
GL11.glDisable(GL11.GL_BLEND);
if (this.func_175183_b())
{
bind(Gui.icons);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GL11.GL_ONE_MINUS_DST_COLOR, GL11.GL_ONE_MINUS_SRC_COLOR, 1, 0);
GlStateManager.enableAlpha();
drawTexturedModalRect(width / 2 - 7, height / 2 - 7, 0, 0, 16, 16);
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
GL11.glDisable(GL11.GL_BLEND);
}
post(CROSSHAIRS);
}
@@ -228,15 +215,16 @@ public class GuiIngameForge extends GuiIngame
protected void renderBossHealth()
{
if (pre(BOSSHEALTH)) return;
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
mc.mcProfiler.startSection("bossHealth");
GL11.glEnable(GL11.GL_BLEND);
GlStateManager.enableBlend();
super.renderBossHealth();
GL11.glDisable(GL11.GL_BLEND);
GlStateManager.disableBlend();
mc.mcProfiler.endSection();
post(BOSSHEALTH);
}
private void renderHelmet(ScaledResolution res, float partialTicks, boolean hasScreen, int mouseX, int mouseY)
private void renderHelmet(ScaledResolution res, float partialTicks)
{
if (pre(HELMET)) return;
@@ -246,11 +234,11 @@ public class GuiIngameForge extends GuiIngame
{
if (itemstack.getItem() == Item.getItemFromBlock(Blocks.pumpkin))
{
renderPumpkinBlur(res.getScaledWidth(), res.getScaledHeight());
func_180476_e(res);
}
else
{
itemstack.getItem().renderHelmetOverlay(itemstack, mc.thePlayer, res, partialTicks, hasScreen, mouseX, mouseY);
itemstack.getItem().renderHelmetOverlay(itemstack, mc.thePlayer, res, partialTicks);
}
}
@@ -262,7 +250,7 @@ public class GuiIngameForge extends GuiIngame
if (pre(ARMOR)) return;
mc.mcProfiler.startSection("armor");
GL11.glEnable(GL11.GL_BLEND);
GlStateManager.enableBlend();
int left = width / 2 - 91;
int top = height - left_height;
@@ -285,12 +273,12 @@ public class GuiIngameForge extends GuiIngame
}
left_height += 10;
GL11.glDisable(GL11.GL_BLEND);
GlStateManager.disableBlend();
mc.mcProfiler.endSection();
post(ARMOR);
}
protected void renderPortal(int width, int height, float partialTicks)
protected void renderPortal(ScaledResolution res, float partialTicks)
{
if (pre(PORTAL)) return;
@@ -298,23 +286,40 @@ public class GuiIngameForge extends GuiIngame
if (f1 > 0.0F)
{
func_130015_b(f1, width, height);
func_180474_b(f1, res);
}
post(PORTAL);
}
protected void func_180479_a(ScaledResolution res, float partialTicks)
{
if (pre(HOTBAR)) return;
if (mc.playerController.enableEverythingIsScrewedUpMode())
{
this.field_175197_u.func_175264_a(res, partialTicks);
}
else
{
super.func_180479_a(res, partialTicks);
}
post(HOTBAR);
}
protected void renderAir(int width, int height)
{
if (pre(AIR)) return;
mc.mcProfiler.startSection("air");
GL11.glEnable(GL11.GL_BLEND);
EntityPlayer player = (EntityPlayer)this.mc.func_175606_aa();
GlStateManager.enableBlend();
int left = width / 2 + 91;
int top = height - right_height;
if (mc.thePlayer.isInsideOfMaterial(Material.water))
if (player.isInsideOfMaterial(Material.water))
{
int air = mc.thePlayer.getAir();
int air = player.getAir();
int full = MathHelper.ceiling_double_int((double)(air - 2) * 10.0D / 300.0D);
int partial = MathHelper.ceiling_double_int((double)air * 10.0D / 300.0D) - full;
@@ -325,7 +330,7 @@ public class GuiIngameForge extends GuiIngame
right_height += 10;
}
GL11.glDisable(GL11.GL_BLEND);
GlStateManager.disableBlend();
mc.mcProfiler.endSection();
post(AIR);
}
@@ -335,20 +340,36 @@ public class GuiIngameForge extends GuiIngame
bind(icons);
if (pre(HEALTH)) return;
mc.mcProfiler.startSection("health");
GL11.glEnable(GL11.GL_BLEND);
GlStateManager.enableBlend();
boolean highlight = mc.thePlayer.hurtResistantTime / 3 % 2 == 1;
EntityPlayer player = (EntityPlayer)this.mc.func_175606_aa();
int health = MathHelper.ceiling_float_int(player.getHealth());
boolean highlight = field_175191_F > (long)updateCounter && (field_175191_F - (long)updateCounter) / 3L %2L == 1L;
if (mc.thePlayer.hurtResistantTime < 10)
if (health < this.field_175194_C && player.hurtResistantTime > 0)
{
highlight = false;
this.field_175190_E = Minecraft.getSystemTime();
this.field_175191_F = (long)(this.updateCounter + 20);
}
else if (health > this.field_175194_C && player.hurtResistantTime > 0)
{
this.field_175190_E = Minecraft.getSystemTime();
this.field_175191_F = (long)(this.updateCounter + 10);
}
IAttributeInstance attrMaxHealth = this.mc.thePlayer.getEntityAttribute(SharedMonsterAttributes.maxHealth);
int health = MathHelper.ceiling_float_int(mc.thePlayer.getHealth());
int healthLast = MathHelper.ceiling_float_int(mc.thePlayer.prevHealth);
if (Minecraft.getSystemTime() - this.field_175190_E > 1000L)
{
this.field_175194_C = health;
this.field_175189_D = health;
this.field_175190_E = Minecraft.getSystemTime();
}
this.field_175194_C = health;
int healthLast = this.field_175189_D;
IAttributeInstance attrMaxHealth = player.getEntityAttribute(SharedMonsterAttributes.maxHealth);
float healthMax = (float)attrMaxHealth.getAttributeValue();
float absorb = this.mc.thePlayer.getAbsorptionAmount();
float absorb = player.getAbsorptionAmount();
int healthRows = MathHelper.ceiling_float_int((healthMax + absorb) / 2.0F / 10.0F);
int rowHeight = Math.max(10 - (healthRows - 2), 3);
@@ -361,7 +382,7 @@ public class GuiIngameForge extends GuiIngame
if (rowHeight != 10) left_height += 10 - rowHeight;
int regen = -1;
if (mc.thePlayer.isPotionActive(Potion.regeneration))
if (player.isPotionActive(Potion.regeneration))
{
regen = updateCounter % 25;
}
@@ -369,8 +390,8 @@ public class GuiIngameForge extends GuiIngame
final int TOP = 9 * (mc.theWorld.getWorldInfo().isHardcoreModeEnabled() ? 5 : 0);
final int BACKGROUND = (highlight ? 25 : 16);
int MARGIN = 16;
if (mc.thePlayer.isPotionActive(Potion.poison)) MARGIN += 36;
else if (mc.thePlayer.isPotionActive(Potion.wither)) MARGIN += 72;
if (player.isPotionActive(Potion.poison)) MARGIN += 36;
else if (player.isPotionActive(Potion.wither)) MARGIN += 72;
float absorbRemaining = absorb;
for (int i = MathHelper.ceiling_float_int((healthMax + absorb) / 2.0F) - 1; i >= 0; --i)
@@ -410,7 +431,7 @@ public class GuiIngameForge extends GuiIngame
}
}
GL11.glDisable(GL11.GL_BLEND);
GlStateManager.disableBlend();
mc.mcProfiler.endSection();
post(HEALTH);
}
@@ -420,7 +441,8 @@ public class GuiIngameForge extends GuiIngame
if (pre(FOOD)) return;
mc.mcProfiler.startSection("food");
GL11.glEnable(GL11.GL_BLEND);
EntityPlayer player = (EntityPlayer)this.mc.func_175606_aa();
GlStateManager.enableBlend();
int left = width / 2 + 91;
int top = height - right_height;
right_height += 10;
@@ -445,7 +467,7 @@ public class GuiIngameForge extends GuiIngame
}
if (unused) backgound = 1; //Probably should be a += 1 but vanilla never uses this
if (mc.thePlayer.getFoodStats().getSaturationLevel() <= 0.0F && updateCounter % (level * 3 + 1) == 0)
if (player.getFoodStats().getSaturationLevel() <= 0.0F && updateCounter % (level * 3 + 1) == 0)
{
y = top + (rand.nextInt(3) - 1);
}
@@ -465,7 +487,7 @@ public class GuiIngameForge extends GuiIngame
else if (idx == level)
drawTexturedModalRect(x, y, icon + 45, 27, 9, 9);
}
GL11.glDisable(GL11.GL_BLEND);
GlStateManager.disableBlend();
mc.mcProfiler.endSection();
post(FOOD);
}
@@ -475,8 +497,8 @@ public class GuiIngameForge extends GuiIngame
if (mc.thePlayer.getSleepTimer() > 0)
{
mc.mcProfiler.startSection("sleep");
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GlStateManager.disableDepth();
GlStateManager.disableAlpha();
int sleepTime = mc.thePlayer.getSleepTimer();
float opacity = (float)sleepTime / 100.0F;
@@ -487,8 +509,8 @@ public class GuiIngameForge extends GuiIngame
int color = (int)(220.0F * opacity) << 24 | 1052704;
drawRect(0, 0, width, height, color);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GlStateManager.enableAlpha();
GlStateManager.enableDepth();
mc.mcProfiler.endSection();
}
}
@@ -497,8 +519,8 @@ public class GuiIngameForge extends GuiIngame
{
bind(icons);
if (pre(EXPERIENCE)) return;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_BLEND);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableBlend();
if (mc.playerController.gameIsSurvivalOrAdventure())
{
@@ -538,8 +560,8 @@ public class GuiIngameForge extends GuiIngame
mc.mcProfiler.endSection();
}
}
GL11.glEnable(GL11.GL_BLEND);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.enableBlend();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
post(EXPERIENCE);
}
@@ -549,7 +571,7 @@ public class GuiIngameForge extends GuiIngame
bind(icons);
if (pre(JUMPBAR)) return;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_BLEND);
GlStateManager.disableBlend();
mc.mcProfiler.startSection("jumpBar");
float charge = mc.thePlayer.getHorseJumpPower();
@@ -565,152 +587,108 @@ public class GuiIngameForge extends GuiIngame
this.drawTexturedModalRect(x, top, 0, 89, filled, 5);
}
GL11.glEnable(GL11.GL_BLEND);
GlStateManager.enableBlend();
mc.mcProfiler.endSection();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
post(JUMPBAR);
}
protected void renderToolHightlight(int width, int height)
protected void renderToolHightlight(ScaledResolution res)
{
if (this.mc.gameSettings.heldItemTooltips)
if (this.mc.gameSettings.heldItemTooltips && !this.mc.playerController.enableEverythingIsScrewedUpMode())
{
mc.mcProfiler.startSection("toolHighlight");
if (this.remainingHighlightTicks > 0 && this.highlightingItemStack != null)
{
String name = this.highlightingItemStack.getDisplayName();
if (this.highlightingItemStack.hasDisplayName())
name = EnumChatFormatting.ITALIC + name;
int opacity = (int)((float)this.remainingHighlightTicks * 256.0F / 10.0F);
if (opacity > 255) opacity = 255;
if (opacity > 0)
{
int y = height - 59;
int y = res.getScaledHeight() - 59;
if (!mc.playerController.shouldDrawHUD()) y += 14;
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
FontRenderer font = highlightingItemStack.getItem().getFontRenderer(highlightingItemStack);
if (font != null)
{
int x = (width - font.getStringWidth(name)) / 2;
font.drawStringWithShadow(name, x, y, WHITE | (opacity << 24));
int x = (res.getScaledWidth() - font.getStringWidth(name)) / 2;
font.func_175063_a(name, x, y, WHITE | (opacity << 24));
}
else
{
int x = (width - fontrenderer.getStringWidth(name)) / 2;
fontrenderer.drawStringWithShadow(name, x, y, WHITE | (opacity << 24));
int x = (res.getScaledWidth() - fontrenderer.getStringWidth(name)) / 2;
fontrenderer.func_175063_a(name, x, y, WHITE | (opacity << 24));
}
GL11.glDisable(GL11.GL_BLEND);
GL11.glPopMatrix();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
}
mc.mcProfiler.endSection();
}
else if (this.mc.thePlayer.func_175149_v())
{
this.field_175197_u.func_175263_a(res);
}
}
protected void renderHUDText(int width, int height)
{
mc.mcProfiler.startSection("forgeHudText");
OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
ArrayList<String> left = new ArrayList<String>();
ArrayList<String> right = new ArrayList<String>();
ArrayList<String> listL = new ArrayList<String>();
ArrayList<String> listR = new ArrayList<String>();
if (mc.isDemo())
{
long time = mc.theWorld.getTotalWorldTime();
if (time >= 120500L)
{
right.add(I18n.format("demo.demoExpired"));
listR.add(I18n.format("demo.demoExpired"));
}
else
{
right.add(I18n.format("demo.remainingTime", StringUtils.ticksToElapsedTime((int)(120500L - time))));
listR.add(I18n.format("demo.remainingTime", StringUtils.ticksToElapsedTime((int)(120500L - time))));
}
}
if (this.mc.gameSettings.showDebugInfo && !pre(DEBUG))
{
mc.mcProfiler.startSection("debug");
GL11.glPushMatrix();
left.add("Minecraft " + MC_VERSION + " (" + this.mc.debug + ")");
left.add(mc.debugInfoRenders());
left.add(mc.getEntityDebug());
left.add(mc.debugInfoEntities());
left.add(mc.getWorldProviderName());
left.add(null); //Spacer
long max = Runtime.getRuntime().maxMemory();
long total = Runtime.getRuntime().totalMemory();
long free = Runtime.getRuntime().freeMemory();
long used = total - free;
right.add("Used memory: " + used * 100L / max + "% (" + used / 1024L / 1024L + "MB) of " + max / 1024L / 1024L + "MB");
right.add("Allocated memory: " + total * 100L / max + "% (" + total / 1024L / 1024L + "MB)");
int x = MathHelper.floor_double(mc.thePlayer.posX);
int y = MathHelper.floor_double(mc.thePlayer.posY);
int z = MathHelper.floor_double(mc.thePlayer.posZ);
float yaw = mc.thePlayer.rotationYaw;
int heading = MathHelper.floor_double((double)(mc.thePlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
left.add(String.format("x: %.5f (%d) // c: %d (%d)", mc.thePlayer.posX, x, x >> 4, x & 15));
left.add(String.format("y: %.3f (feet pos, %.3f eyes pos)", mc.thePlayer.boundingBox.minY, mc.thePlayer.posY));
left.add(String.format("z: %.5f (%d) // c: %d (%d)", mc.thePlayer.posZ, z, z >> 4, z & 15));
left.add(String.format("f: %d (%s) / %f", heading, Direction.directions[heading], MathHelper.wrapAngleTo180_float(yaw)));
if (mc.theWorld != null && mc.theWorld.blockExists(x, y, z))
{
Chunk chunk = this.mc.theWorld.getChunkFromBlockCoords(x, z);
left.add(String.format("lc: %d b: %s bl: %d sl: %d rl: %d",
chunk.getTopFilledSegment() + 15,
chunk.getBiomeGenForWorldCoords(x & 15, z & 15, mc.theWorld.getWorldChunkManager()).biomeName,
chunk.getSavedLightValue(EnumSkyBlock.Block, x & 15, y, z & 15),
chunk.getSavedLightValue(EnumSkyBlock.Sky, x & 15, y, z & 15),
chunk.getBlockLightValue(x & 15, y, z & 15, 0)));
}
else
{
left.add(null);
}
left.add(String.format("ws: %.3f, fs: %.3f, g: %b, fl: %d", mc.thePlayer.capabilities.getWalkSpeed(), mc.thePlayer.capabilities.getFlySpeed(), mc.thePlayer.onGround, mc.theWorld.getHeightValue(x, z)));
if (mc.entityRenderer != null && mc.entityRenderer.isShaderActive())
{
left.add(String.format("shader: %s", mc.entityRenderer.getShaderGroup().getShaderGroupName()));
}
right.add(null);
for (String brand : FMLCommonHandler.instance().getBrandings(false))
{
right.add(brand);
}
GL11.glPopMatrix();
mc.mcProfiler.endSection();
listL.addAll(debugOverlay.getLeft());
listR.addAll(debugOverlay.getRight());
post(DEBUG);
}
RenderGameOverlayEvent.Text event = new RenderGameOverlayEvent.Text(eventParent, left, right);
RenderGameOverlayEvent.Text event = new RenderGameOverlayEvent.Text(eventParent, listL, listR);
if (!MinecraftForge.EVENT_BUS.post(event))
{
for (int x = 0; x < left.size(); x++)
int top = 2;
for (String msg : listL)
{
String msg = left.get(x);
top += fontrenderer.FONT_HEIGHT;
if (msg == null) continue;
fontrenderer.drawStringWithShadow(msg, 2, 2 + x * 10, WHITE);
drawRect(1, top - 1, 2 + fontrenderer.getStringWidth(msg) + 1, top - 1, -1873784752);
fontrenderer.drawString(msg, 2, top, 14737632);
}
for (int x = 0; x < right.size(); x++)
top = 2;
for (String msg : listR)
{
String msg = right.get(x);
top += fontrenderer.FONT_HEIGHT;
if (msg == null) continue;
int w = fontrenderer.getStringWidth(msg);
fontrenderer.drawStringWithShadow(msg, width - w - 10, 2 + x * 10, WHITE);
int left = width - 2 - w;
drawRect(left - 1, top - 1, left + w + 1, top - 1, -1873784752);
fontrenderer.drawString(msg, left, top, 14737632);
}
}
@@ -729,20 +707,60 @@ public class GuiIngameForge extends GuiIngame
if (opacity > 0)
{
GL11.glPushMatrix();
GL11.glTranslatef((float)(width / 2), (float)(height - 48), 0.0F);
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
GlStateManager.pushMatrix();
GlStateManager.translate((float)(width / 2), (float)(height - 48), 0.0F);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
int color = (recordIsPlaying ? Color.HSBtoRGB(hue / 50.0F, 0.7F, 0.6F) & WHITE : WHITE);
fontrenderer.drawString(recordPlaying, -fontrenderer.getStringWidth(recordPlaying) / 2, -4, color | (opacity << 24));
GL11.glDisable(GL11.GL_BLEND);
GL11.glPopMatrix();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
mc.mcProfiler.endSection();
}
}
protected void renderTitle(int width, int height, float partialTicks)
{
if (field_175195_w > 0)
{
mc.mcProfiler.startSection("titleAndSubtitle");
float age = (float)this.field_175195_w - partialTicks;
int opacity = 255;
if (field_175195_w > field_175193_B + field_175192_A)
{
float f3 = (float)(field_175199_z + field_175192_A + field_175193_B) - age;
opacity = (int)(f3 * 255.0F / (float)field_175199_z);
}
if (field_175195_w <= field_175193_B) opacity = (int)(age * 255.0F / (float)this.field_175193_B);
opacity = MathHelper.clamp_int(opacity, 0, 255);
if (opacity > 8)
{
GlStateManager.pushMatrix();
GlStateManager.translate((float)(width / 2), (float)(height / 2), 0.0F);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.pushMatrix();
GlStateManager.scale(4.0F, 4.0F, 4.0F);
int l = opacity << 24 & -16777216;
this.func_175179_f().func_175065_a(this.field_175201_x, (float)(-this.func_175179_f().getStringWidth(this.field_175201_x) / 2), -10.0F, 16777215 | l, true);
GlStateManager.popMatrix();
GlStateManager.pushMatrix();
GlStateManager.scale(2.0F, 2.0F, 2.0F);
this.func_175179_f().func_175065_a(this.field_175200_y, (float)(-this.func_175179_f().getStringWidth(this.field_175200_y) / 2), 5.0F, 16777215 | l, true);
GlStateManager.popMatrix();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
this.mc.mcProfiler.endSection();
}
}
protected void renderChat(int width, int height)
{
mc.mcProfiler.startSection("chat");
@@ -750,98 +768,38 @@ public class GuiIngameForge extends GuiIngame
RenderGameOverlayEvent.Chat event = new RenderGameOverlayEvent.Chat(eventParent, 0, height - 48);
if (MinecraftForge.EVENT_BUS.post(event)) return;
GL11.glPushMatrix();
GL11.glTranslatef((float)event.posX, (float)event.posY, 0.0F);
GlStateManager.pushMatrix();
GlStateManager.translate((float)event.posX, (float)event.posY, 0.0F);
persistantChatGUI.drawChat(updateCounter);
GL11.glPopMatrix();
GlStateManager.popMatrix();
post(CHAT);
mc.mcProfiler.endSection();
}
@SuppressWarnings("unchecked")
protected void renderPlayerList(int width, int height)
{
ScoreObjective scoreobjective = this.mc.theWorld.getScoreboard().func_96539_a(0);
ScoreObjective scoreobjective = this.mc.theWorld.getScoreboard().getObjectiveInDisplaySlot(0);
NetHandlerPlayClient handler = mc.thePlayer.sendQueue;
if (mc.gameSettings.keyBindPlayerList.getIsKeyPressed() && (!mc.isIntegratedServerRunning() || handler.playerInfoList.size() > 1 || scoreobjective != null))
if (mc.gameSettings.keyBindPlayerList.getIsKeyPressed() && (!mc.isIntegratedServerRunning() || handler.func_175106_d().size() > 1 || scoreobjective != null))
{
this.overlayPlayerList.func_175246_a(true);
if (pre(PLAYER_LIST)) return;
this.mc.mcProfiler.startSection("playerList");
List<GuiPlayerInfo> players = (List<GuiPlayerInfo>)handler.playerInfoList;
int maxPlayers = handler.currentServerMaxPlayers;
int rows = maxPlayers;
int columns = 1;
for (columns = 1; rows > 20; rows = (maxPlayers + columns - 1) / columns)
{
columns++;
}
int columnWidth = 300 / columns;
if (columnWidth > 150)
{
columnWidth = 150;
}
int left = (width - columns * columnWidth) / 2;
byte border = 10;
drawRect(left - 1, border - 1, left + columnWidth * columns, border + 9 * rows, Integer.MIN_VALUE);
for (int i = 0; i < maxPlayers; i++)
{
int xPos = left + i % columns * columnWidth;
int yPos = border + i / columns * 9;
drawRect(xPos, yPos, xPos + columnWidth - 1, yPos + 8, 553648127);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glEnable(GL11.GL_ALPHA_TEST);
if (i < players.size())
{
GuiPlayerInfo player = (GuiPlayerInfo)players.get(i);
ScorePlayerTeam team = mc.theWorld.getScoreboard().getPlayersTeam(player.name);
String displayName = ScorePlayerTeam.formatPlayerName(team, player.name);
fontrenderer.drawStringWithShadow(displayName, xPos, yPos, 16777215);
if (scoreobjective != null)
{
int endX = xPos + fontrenderer.getStringWidth(displayName) + 5;
int maxX = xPos + columnWidth - 12 - 5;
if (maxX - endX > 5)
{
Score score = scoreobjective.getScoreboard().func_96529_a(player.name, scoreobjective);
String scoreDisplay = EnumChatFormatting.YELLOW + "" + score.getScorePoints();
fontrenderer.drawStringWithShadow(scoreDisplay, maxX - fontrenderer.getStringWidth(scoreDisplay), yPos, 16777215);
}
}
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(Gui.icons);
int pingIndex = 4;
int ping = player.responseTime;
if (ping < 0) pingIndex = 5;
else if (ping < 150) pingIndex = 0;
else if (ping < 300) pingIndex = 1;
else if (ping < 600) pingIndex = 2;
else if (ping < 1000) pingIndex = 3;
zLevel += 100.0F;
drawTexturedModalRect(xPos + columnWidth - 12, yPos, 0, 176 + pingIndex * 8, 10, 8);
zLevel -= 100.0F;
}
}
this.overlayPlayerList.func_175249_a(width, this.mc.theWorld.getScoreboard(), scoreobjective);
post(PLAYER_LIST);
}
else
{
this.overlayPlayerList.func_175246_a(false);
}
}
protected void renderHealthMount(int width, int height)
{
Entity tmp = mc.thePlayer.ridingEntity;
EntityPlayer player = (EntityPlayer)mc.func_175606_aa();
Entity tmp = player.ridingEntity;
if (!(tmp instanceof EntityLivingBase)) return;
bind(icons);
@@ -852,7 +810,7 @@ public class GuiIngameForge extends GuiIngame
int left_align = width / 2 + 91;
mc.mcProfiler.endStartSection("mountHealth");
GL11.glEnable(GL11.GL_BLEND);
GlStateManager.enableBlend();
EntityLivingBase mount = (EntityLivingBase)tmp;
int health = (int)Math.ceil((double)mount.getHealth());
float healthMax = mount.getMaxHealth();
@@ -885,7 +843,7 @@ public class GuiIngameForge extends GuiIngame
right_height += 10;
}
GL11.glDisable(GL11.GL_BLEND);
GlStateManager.disableBlend();
post(HEALTHMOUNT);
}
@@ -902,4 +860,13 @@ public class GuiIngameForge extends GuiIngame
{
mc.getTextureManager().bindTexture(res);
}
private class GuiOverlayDebugForge extends GuiOverlayDebug
{
private GuiOverlayDebugForge(Minecraft mc){ super(mc); }
@Override protected void func_180798_a(){}
@Override protected void func_175239_b(ScaledResolution res){}
private List<String> getLeft(){ return this.call(); }
private List<String> getRight(){ return this.func_175238_c(); }
}
}
@@ -2,65 +2,68 @@ package net.minecraftforge.client;
import net.minecraft.item.ItemStack;
@Deprecated //Unused, for now. Rendering emensely changed in 1.8, Is this even needed at all anymore?
//Modders should speak up if needed.
public interface IItemRenderer
{
@Deprecated
public enum ItemRenderType
{
/**
/**
* Called to render an in-world item, e.g. one that has been thrown or
* dropped. The appropriate OpenGL transformations and scaling have already
* been applied, so Tessellator location (0,0,0) is the center of the
* EntityItem.
*
*
* Data parameters:
* RenderBlocks render - The RenderBlocks instance
* EntityItem entity - The in-world item to be rendered
*/
ENTITY,
/**
ENTITY,
/**
* Called to render an item currently held in-hand by a living entity. If
* rendering as a 3D block, the item will be rotated to a 45-degree angle.
* To render a 2D texture with some thickness (like default items), see
* net.minecraft.src.ItemRenderer. In either case, rendering should be done
* in local coordinates from (0,0,0)-(1,1,1).
*
*
* Data parameters:
* RenderBlocks render - The RenderBlocks instance
* EntityLiving entity - The entity holding this item
*/
EQUIPPED,
/**
EQUIPPED,
/**
* Called to render an item currently held in-hand by a living entity in
* first person. If rendering as a 3D block, the item will be rotated to a
* 45-degree angle. To render a 2D texture with some thickness, see
* net.minecraft.src.ItemRenderer. In either case, rendering should be done
* in local coordinates from (0,0,0)-(1,1,1).
*
*
* Data parameters:
* RenderBlocks render - The RenderBlocks instance
* EntityLiving entity - The entity holding this item
*/
EQUIPPED_FIRST_PERSON,
/**
EQUIPPED_FIRST_PERSON,
/**
* Called to render an item in a GUI inventory slot. If rendering as a 3D
* block, the appropriate OpenGL translations and scaling have already been
* applied, and the rendering should be done in local coordinates from
* (0,0,0)-(1,1,1). If rendering as a 2D texture, the rendering should be in
* GUI pixel coordinates from (0, 0, 0)-(16, 16, 0).
*
*
* Data parameters:
* RenderBlocks render - The RenderBlocks instance
*/
INVENTORY,
/**
* The render type used for when a ItemMap is rendered in first person,
* All appropriate rotations have been applied, and the player's hands,
* The render type used for when a ItemMap is rendered in first person,
* All appropriate rotations have been applied, and the player's hands,
* and the map BG are already rendered.
*
*
* Data Parameters:
* EntityPlayer player - The player holding the map
* RenderEngine engine - The RenderEngine instance
@@ -68,67 +71,71 @@ public interface IItemRenderer
*/
FIRST_PERSON_MAP
}
@Deprecated
public enum ItemRendererHelper
{
/**
/**
* Determines if a rotation effect should be used when rendering an
* EntityItem, like most default blocks do.
*/
ENTITY_ROTATION,
/**
/**
* Determines if an up-and-down bobbing effect should be used when
* rendering an EntityItem, like most default items do.
*/
ENTITY_BOBBING,
/**
/**
* Determines if the currently equipped item should be rendered as a 3D
* block or as a 2D texture.
*/
EQUIPPED_BLOCK,
/**
* Determines if the item should equate to a block that has
* Determines if the item should equate to a block that has
* RenderBlocks.renderItemIn3d return true
*/
BLOCK_3D,
/**
/**
* Determines if the item should be rendered in GUI inventory slots as a 3D
* block or as a 2D texture.
*/
INVENTORY_BLOCK
}
/**
/**
* Checks if this renderer should handle a specific item's render type
* @param item The item we are trying to render
* @param type A render type to check if this renderer handles
* @return true if this renderer should handle the given render type,
* otherwise false
*/
@Deprecated
public boolean handleRenderType(ItemStack item, ItemRenderType type);
/**
* Checks if certain helper functionality should be executed for this renderer.
* See ItemRendererHelper for more info
*
*
* @param type The render type
* @param item The ItemStack being rendered
* @param helper The type of helper functionality to be ran
* @return True to run the helper functionality, false to not.
*/
@Deprecated
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper);
/**
* Called to do the actual rendering, see ItemRenderType for details on when specific
* Called to do the actual rendering, see ItemRenderType for details on when specific
* types are run, and what extra data is passed into the data parameter.
*
*
* @param type The render type
* @param item The ItemStack being rendered
* @param data Extra Type specific data
*/
@Deprecated
public void renderItem(ItemRenderType type, ItemStack item, Object... data);
}
@@ -1,7 +1,7 @@
package net.minecraftforge.client;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
@@ -46,21 +46,18 @@ public class MinecraftForgeClient
return ForgeHooksClient.renderPass;
}
public static int getStencilBits()
{
return ForgeHooksClient.stencilBits;
}
private static BitSet stencilBits = new BitSet(getStencilBits());
private static BitSet stencilBits = new BitSet(8);
static
{
stencilBits.set(0,getStencilBits());
stencilBits.set(0,8);
}
/**
* Reserve a stencil bit for use in rendering
*
* Note: you must check the Framebuffer you are working with to
* determine if stencil bits are enabled on it before use.
*
* @return A bit or -1 if no further stencil bits are available
*/
public static int reserveStencilBit()
@@ -80,7 +77,7 @@ public class MinecraftForgeClient
*/
public static void releaseStencilBit(int bit)
{
if (bit >= 0 && bit < getStencilBits())
if (bit >= 0 && bit < stencilBits.length())
{
stencilBits.set(bit);
}
@@ -1,15 +1,23 @@
package net.minecraftforge.client.event;
import net.minecraft.util.IChatComponent;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
@Cancelable
public class ClientChatReceivedEvent extends Event
{
public IChatComponent message;
public ClientChatReceivedEvent(IChatComponent message)
/**
* Introduced in 1.8:
* 0 : Standard Text Message
* 1 : 'System' message, displayed as standard text.
* 2 : 'Status' message, displayed above action bar, where song notifications are.
*/
public final byte type;
public ClientChatReceivedEvent(byte type, IChatComponent message)
{
this.type = type;
this.message = message;
}
}
@@ -1,7 +1,7 @@
package net.minecraftforge.client.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
@@ -2,10 +2,11 @@ package net.minecraftforge.client.event;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import cpw.mods.fml.common.eventhandler.Event.Result;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event.Result;
/**
* Event that hooks into EntityRenderer, allowing any feature to customize visual attributes of
@@ -14,11 +15,11 @@ import cpw.mods.fml.common.eventhandler.Event.Result;
public abstract class EntityViewRenderEvent extends Event
{
public final EntityRenderer renderer;
public final EntityLivingBase entity;
public final Entity entity;
public final Block block;
public final double renderPartialTicks;
public EntityViewRenderEvent(EntityRenderer renderer, EntityLivingBase entity, Block block, double renderPartialTicks)
public EntityViewRenderEvent(EntityRenderer renderer, Entity entity, Block block, double renderPartialTicks)
{
this.renderer = renderer;
this.entity = entity;
@@ -35,13 +36,13 @@ public abstract class EntityViewRenderEvent extends Event
{
public float density;
public FogDensity(EntityRenderer renderer, EntityLivingBase entity, Block block, double renderPartialTicks, float density)
public FogDensity(EntityRenderer renderer, Entity entity, Block block, double renderPartialTicks, float density)
{
super(renderer, entity, block, renderPartialTicks);
this.density = density;
}
}
/**
* Event that allows any feature to customize the rendering of fog.
*/
@@ -50,8 +51,8 @@ public abstract class EntityViewRenderEvent extends Event
{
public final int fogMode;
public final float farPlaneDistance;
public RenderFogEvent(EntityRenderer renderer, EntityLivingBase entity, Block block, double renderPartialTicks, int fogMode, float farPlaneDistance)
public RenderFogEvent(EntityRenderer renderer, Entity entity, Block block, double renderPartialTicks, int fogMode, float farPlaneDistance)
{
super(renderer, entity, block, renderPartialTicks);
this.fogMode = fogMode;
@@ -69,7 +70,7 @@ public abstract class EntityViewRenderEvent extends Event
public float green;
public float blue;
public FogColors(EntityRenderer renderer, EntityLivingBase entity, Block block, double renderPartialTicks, float red, float green, float blue)
public FogColors(EntityRenderer renderer, Entity entity, Block block, double renderPartialTicks, float red, float green, float blue)
{
super(renderer, entity, block, renderPartialTicks);
this.red = red;
@@ -1,7 +1,7 @@
package net.minecraftforge.client.event;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.common.eventhandler.Event;
/**
* Author: MachineMuse (Claire Semple)
@@ -9,11 +9,11 @@ import net.minecraft.client.entity.EntityPlayerSP;
*/
public class FOVUpdateEvent extends Event
{
public final EntityPlayerSP entity;
public final EntityPlayer entity;
public final float fov;
public float newfov;
public FOVUpdateEvent(EntityPlayerSP entity, float fov)
public FOVUpdateEvent(EntityPlayer entity, float fov)
{
this.entity = entity;
this.fov = fov;
@@ -1,7 +1,7 @@
package net.minecraftforge.client.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.client.gui.GuiScreen;
/**
@@ -5,10 +5,10 @@ import java.util.List;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/**
* Event classes for GuiScreen events.
@@ -2,8 +2,8 @@ package net.minecraftforge.client.event;
import org.lwjgl.input.Mouse;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
/**
* Author: MachineMuse (Claire Semple)
@@ -3,8 +3,8 @@ package net.minecraftforge.client.event;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
/**
* Called when a block's texture is going to be overlaid on the player's HUD. Cancel this event to prevent the overlay.
@@ -2,8 +2,8 @@ package net.minecraftforge.client.event;
import java.util.ArrayList;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.client.gui.ScaledResolution;
@@ -33,16 +33,12 @@ public class RenderGameOverlayEvent extends Event
public final float partialTicks;
public final ScaledResolution resolution;
public final int mouseX;
public final int mouseY;
public final ElementType type;
public RenderGameOverlayEvent(float partialTicks, ScaledResolution resolution, int mouseX, int mouseY)
public RenderGameOverlayEvent(float partialTicks, ScaledResolution resolution)
{
this.partialTicks = partialTicks;
this.resolution = resolution;
this.mouseX = mouseX;
this.mouseY = mouseY;
this.type = null;
}
@@ -50,8 +46,6 @@ public class RenderGameOverlayEvent extends Event
{
this.partialTicks = parent.partialTicks;
this.resolution = parent.resolution;
this.mouseX = parent.mouseX;
this.mouseY = parent.mouseY;
this.type = type;
}
@@ -1,7 +1,7 @@
package net.minecraftforge.client.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.client.renderer.RenderGlobal;
@Cancelable
@@ -3,8 +3,8 @@ package net.minecraftforge.client.event;
import net.minecraft.client.renderer.tileentity.RenderItemFrame;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
/**
* This event is called when an item is rendered in an item frame.
@@ -1,7 +1,7 @@
package net.minecraftforge.client.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.entity.EntityLivingBase;
@@ -1,6 +1,6 @@
package net.minecraftforge.client.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -1,7 +1,7 @@
package net.minecraftforge.client.event;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraftforge.fml.common.eventhandler.Event;
//import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.world.ChunkCache;
@@ -9,14 +9,14 @@ public abstract class RenderWorldEvent extends Event
{
public final WorldRenderer renderer;
public final ChunkCache chunkCache;
public final RenderBlocks renderBlocks;
//public final RenderBlocks renderBlocks;
public final int pass;
public RenderWorldEvent(WorldRenderer renderer, ChunkCache chunkCache, RenderBlocks renderBlocks, int pass)
public RenderWorldEvent(WorldRenderer renderer, ChunkCache chunkCache, /*RenderBlocks renderBlocks,*/ int pass)
{
this.renderer = renderer;
this.chunkCache = chunkCache;
this.renderBlocks = renderBlocks;
//this.renderBlocks = renderBlocks;
this.pass = pass;
}
@@ -26,7 +26,7 @@ public abstract class RenderWorldEvent extends Event
*/
public static class Pre extends RenderWorldEvent
{
public Pre(WorldRenderer renderer, ChunkCache chunkCache, RenderBlocks renderBlocks, int pass){ super(renderer, chunkCache, renderBlocks, pass); }
public Pre(WorldRenderer renderer, ChunkCache chunkCache, /*RenderBlocks renderBlocks,*/ int pass){ super(renderer, chunkCache, /*renderBlocks,*/ pass); }
}
/**
@@ -34,6 +34,6 @@ public abstract class RenderWorldEvent extends Event
*/
public static class Post extends RenderWorldEvent
{
public Post(WorldRenderer renderer, ChunkCache chunkCache, RenderBlocks renderBlocks, int pass){ super(renderer, chunkCache, renderBlocks, pass); }
public Post(WorldRenderer renderer, ChunkCache chunkCache, /*RenderBlocks renderBlocks,*/ int pass){ super(renderer, chunkCache, /*renderBlocks,*/ pass); }
}
}
@@ -1,6 +1,6 @@
package net.minecraftforge.client.event;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.client.renderer.RenderGlobal;
public class RenderWorldLastEvent extends Event
@@ -1,6 +1,6 @@
package net.minecraftforge.client.event;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.client.renderer.texture.TextureMap;
@@ -1,25 +1,29 @@
package net.minecraftforge.client.event.sound;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.SoundCategory;
import net.minecraft.client.audio.SoundManager;
import net.minecraft.client.audio.SoundPoolEntry;
/***
* Raised when the SoundManager tries to play a normal sound.
*
*
* If you return null from this function it will prevent the sound from being played,
* you can return a different entry if you want to change the sound being played.
*/
@Deprecated // Switch with PlaySoundEvent17 in 1.8
public class PlaySoundEvent extends SoundResultEvent
public class PlaySoundEvent extends SoundEvent
{
public final float x;
public final float y;
public final float z;
public PlaySoundEvent(SoundManager manager, SoundPoolEntry source, String name, float x, float y, float z, float volume, float pitch)
{
super(manager, source, name, volume, pitch);
this.x = x;
this.y = y;
this.z = z;
public final String name;
public final ISound sound;
public final SoundCategory category;
public ISound result;
public PlaySoundEvent(SoundManager manager, ISound sound, SoundCategory category)
{
super(manager);
this.sound = sound;
this.category = category;
this.name = sound.getSoundLocation().getResourcePath();
this.result = sound;
}
}
@@ -1,30 +0,0 @@
package net.minecraftforge.client.event.sound;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.SoundCategory;
import net.minecraft.client.audio.SoundManager;
import net.minecraft.client.audio.SoundPoolEntry;
/***
* Raised when the SoundManager tries to play a normal sound.
*
* If you return null from this function it will prevent the sound from being played,
* you can return a different entry if you want to change the sound being played.
*/
//TODO: Replace PlaySoundEvent in 1.8
public class PlaySoundEvent17 extends SoundEvent
{
public final String name;
public final ISound sound;
public final SoundCategory category;
public ISound result;
public PlaySoundEvent17(SoundManager manager, ISound sound, SoundCategory category)
{
super(manager);
this.sound = sound;
this.category = category;
this.name = sound.getPositionedSoundLocation().getResourcePath();
this.result = sound;
}
}
@@ -6,33 +6,8 @@ import net.minecraftforge.client.event.sound.SoundEvent.SoundSourceEvent;
public class PlaySoundSourceEvent extends SoundSourceEvent
{
@Deprecated
public final SoundManager manager;
@Deprecated
public final String name;
@Deprecated
public final float x;
@Deprecated
public final float y;
@Deprecated
public final float z;
@Deprecated
public PlaySoundSourceEvent(SoundManager manager, String name, float x, float y, float z)
{
super(manager, null, null);
this.manager = manager;
this.name = name;
this.x = x;
this.y = y;
this.z = z;
}
public PlaySoundSourceEvent(SoundManager manager, ISound sound, String uuid)
{
super(manager, sound, uuid);
this.name = sound.getPositionedSoundLocation().getResourcePath();
this.manager = manager;
this.x = this.y = this.z = 0;
}
}
@@ -6,33 +6,8 @@ import net.minecraftforge.client.event.sound.SoundEvent.SoundSourceEvent;
public class PlayStreamingSourceEvent extends SoundSourceEvent
{
@Deprecated
public final SoundManager manager;
@Deprecated
public final String name;
@Deprecated
public final float x;
@Deprecated
public final float y;
@Deprecated
public final float z;
@Deprecated
public PlayStreamingSourceEvent(SoundManager manager, String name, float x, float y, float z)
{
super(manager, null, null);
this.manager = manager;
this.name = name;
this.x = x;
this.y = y;
this.z = z;
}
public PlayStreamingSourceEvent(SoundManager manager, ISound sound, String uuid)
{
super(manager, sound, uuid);
this.x = this.y = this.z = 0;
this.manager = null;
this.name = sound.getPositionedSoundLocation().getResourcePath();
}
}
@@ -1,6 +1,6 @@
package net.minecraftforge.client.event.sound;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.SoundManager;
import net.minecraft.client.audio.SoundPoolEntry;
@@ -13,7 +13,7 @@ public class SoundEvent extends Event
{
this.manager = manager;
}
@Deprecated
public static SoundPoolEntry getResult(SoundResultEvent event)
{
@@ -30,7 +30,7 @@ public class SoundEvent extends Event
public SoundSourceEvent(SoundManager manager, ISound sound, String uuid)
{
super(manager);
this.name = sound.getPositionedSoundLocation().getResourcePath();
this.name = sound.getSoundLocation().getResourcePath();
this.sound = sound;
this.uuid = uuid;
}
@@ -22,33 +22,33 @@ import net.minecraftforge.common.config.ConfigCategory;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import cpw.mods.fml.client.IModGuiFactory;
import cpw.mods.fml.client.IModGuiFactory.RuntimeOptionCategoryElement;
import cpw.mods.fml.client.IModGuiFactory.RuntimeOptionGuiHandler;
import cpw.mods.fml.client.config.ConfigGuiType;
import cpw.mods.fml.client.config.DummyConfigElement;
import cpw.mods.fml.client.config.DummyConfigElement.DummyCategoryElement;
import cpw.mods.fml.client.config.GuiButtonExt;
import cpw.mods.fml.client.config.GuiConfig;
import cpw.mods.fml.client.config.GuiConfigEntries;
import cpw.mods.fml.client.config.GuiConfigEntries.CategoryEntry;
import cpw.mods.fml.client.config.GuiConfigEntries.IConfigEntry;
import cpw.mods.fml.client.config.GuiConfigEntries.SelectValueEntry;
import cpw.mods.fml.client.config.GuiConfigEntries.BooleanEntry;
import cpw.mods.fml.client.config.HoverChecker;
import cpw.mods.fml.client.config.IConfigElement;
import cpw.mods.fml.client.config.GuiConfigEntries.ListEntryBase;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.fml.client.IModGuiFactory;
import net.minecraftforge.fml.client.IModGuiFactory.RuntimeOptionCategoryElement;
import net.minecraftforge.fml.client.IModGuiFactory.RuntimeOptionGuiHandler;
import net.minecraftforge.fml.client.config.ConfigGuiType;
import net.minecraftforge.fml.client.config.DummyConfigElement;
import net.minecraftforge.fml.client.config.DummyConfigElement.DummyCategoryElement;
import net.minecraftforge.fml.client.config.GuiButtonExt;
import net.minecraftforge.fml.client.config.GuiConfig;
import net.minecraftforge.fml.client.config.GuiConfigEntries;
import net.minecraftforge.fml.client.config.GuiConfigEntries.CategoryEntry;
import net.minecraftforge.fml.client.config.GuiConfigEntries.IConfigEntry;
import net.minecraftforge.fml.client.config.GuiConfigEntries.SelectValueEntry;
import net.minecraftforge.fml.client.config.GuiConfigEntries.BooleanEntry;
import net.minecraftforge.fml.client.config.HoverChecker;
import net.minecraftforge.fml.client.config.IConfigElement;
import net.minecraftforge.fml.client.config.GuiConfigEntries.ListEntryBase;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/**
* This is the base GuiConfig screen class that all the other Forge-specific config screens will be called from.
* Since Forge has multiple config files I thought I would use that opportunity to show some of the ways
* that the config GUI system can be extended to create custom config GUIs that have additional features
* over the base functionality of just displaying Properties and ConfigCategories.
*
*
* The concepts implemented here are:
* - using custom IConfigEntry objects to define child-screens that have specific Properties listed
* - using custom IConfigEntry objects to define a dummy property that can be used to generate new ConfigCategory objects
@@ -58,25 +58,25 @@ import cpw.mods.fml.relauncher.SideOnly;
* - overriding the IConfigEntry.enabled() method to control the enabled state of one list entry based on the value of another entry
* - overriding the IConfigEntry.onGuiClosed() method to perform custom actions when the screen that owns the entry is closed (in this
* case a new ConfigCategory is added to the Configuration object)
*
*
* The config file structure looks like this:
* forge.cfg (general settings all in one category)
* forgeChunkLoading.cfg
* - Forge (category)
* - defaults (category)
* - [optional mod override categories]...
*
*
* The GUI structure is this:
* Base Screen
* - General Settings (from forge.cfg)
* - Chunk Loader Settings (from forgeChunkLoading.cfg)
* - Chunk Loader Settings (from forgeChunkLoading.cfg)
* - Defaults (these elements are listed directly on this screen)
* - Mod Overrides
* - Add New Mod Override
* - Mod1
* - Mod2
* - etc.
*
*
* Other things to check out:
* ForgeModContainer.syncConfig()
* ForgeModContainer.onConfigChanged()
@@ -87,23 +87,23 @@ public class ForgeGuiFactory implements IModGuiFactory
{
@Override
public void initialize(Minecraft minecraftInstance) {}
@Override
public Class<? extends GuiScreen> mainConfigGuiClass() { return ForgeConfigGui.class; }
@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() { return null; }
@Override
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) { return null; }
public static class ForgeConfigGui extends GuiConfig
public static class ForgeConfigGui extends GuiConfig
{
public ForgeConfigGui(GuiScreen parentScreen)
{
super(parentScreen, getConfigElements(), "Forge", false, false, I18n.format("forge.configgui.forgeConfigTitle"));
}
private static List<IConfigElement> getConfigElements()
{
List<IConfigElement> list = new ArrayList<IConfigElement>();
@@ -111,9 +111,9 @@ public class ForgeGuiFactory implements IModGuiFactory
list.add(new DummyCategoryElement("forgeChunkLoadingCfg", "forge.configgui.ctgy.forgeChunkLoadingConfig", ChunkLoaderEntry.class));
return list;
}
/**
* This custom list entry provides the General Settings entry on the Minecraft Forge Configuration screen.
* This custom list entry provides the General Settings entry on the Minecraft Forge Configuration screen.
* It extends the base Category entry class and defines the IConfigElement objects that will be used to build the child screen.
*/
public static class GeneralEntry extends CategoryEntry
@@ -122,20 +122,20 @@ public class ForgeGuiFactory implements IModGuiFactory
{
super(owningScreen, owningEntryList, prop);
}
@Override
protected GuiScreen buildChildScreen()
{
// This GuiConfig object specifies the configID of the object and as such will force-save when it is closed. The parent
// GuiConfig object's entryList will also be refreshed to reflect the changes.
return new GuiConfig(this.owningScreen,
(new ConfigElement(ForgeModContainer.getConfig().getCategory(Configuration.CATEGORY_GENERAL))).getChildElements(),
this.owningScreen.modID, Configuration.CATEGORY_GENERAL, this.configElement.requiresWorldRestart() || this.owningScreen.allRequireWorldRestart,
return new GuiConfig(this.owningScreen,
(new ConfigElement(ForgeModContainer.getConfig().getCategory(Configuration.CATEGORY_GENERAL))).getChildElements(),
this.owningScreen.modID, Configuration.CATEGORY_GENERAL, this.configElement.requiresWorldRestart() || this.owningScreen.allRequireWorldRestart,
this.configElement.requiresMcRestart() || this.owningScreen.allRequireMcRestart,
GuiConfig.getAbridgedConfigPath(ForgeModContainer.getConfig().toString()));
}
}
/**
* This custom list entry provides the Forge Chunk Manager Config entry on the Minecraft Forge Configuration screen.
* It extends the base Category entry class and defines the IConfigElement objects that will be used to build the child screen.
@@ -146,38 +146,38 @@ public class ForgeGuiFactory implements IModGuiFactory
{
super(owningScreen, owningEntryList, prop);
}
@Override
protected GuiScreen buildChildScreen()
{
List<IConfigElement> list = new ArrayList<IConfigElement>();
list.add(new DummyCategoryElement("forgeChunkLoadingModCfg", "forge.configgui.ctgy.forgeChunkLoadingModConfig",
list.add(new DummyCategoryElement("forgeChunkLoadingModCfg", "forge.configgui.ctgy.forgeChunkLoadingModConfig",
ModOverridesEntry.class));
list.addAll((new ConfigElement(ForgeChunkManager.getDefaultsCategory())).getChildElements());
// This GuiConfig object specifies the configID of the object and as such will force-save when it is closed. The parent
// GuiConfig object's propertyList will also be refreshed to reflect the changes.
return new GuiConfig(this.owningScreen, list, this.owningScreen.modID, "chunkLoader",
this.configElement.requiresWorldRestart() || this.owningScreen.allRequireWorldRestart,
return new GuiConfig(this.owningScreen, list, this.owningScreen.modID, "chunkLoader",
this.configElement.requiresWorldRestart() || this.owningScreen.allRequireWorldRestart,
this.configElement.requiresMcRestart() || this.owningScreen.allRequireMcRestart,
GuiConfig.getAbridgedConfigPath(ForgeChunkManager.getConfig().toString()),
I18n.format("forge.configgui.ctgy.forgeChunkLoadingConfig"));
}
}
/**
* This custom list entry provides the Mod Overrides entry on the Forge Chunk Loading config screen.
* It extends the base Category entry class and defines the IConfigElement objects that will be used to build the child screen.
* In this case it adds the custom entry for adding a new mod override and lists the existing mod overrides.
*/
public static class ModOverridesEntry extends CategoryEntry
{
{
public ModOverridesEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop)
{
super(owningScreen, owningEntryList, prop);
}
/**
* This method is called in the constructor and is used to set the childScreen field.
*/
@@ -185,21 +185,21 @@ public class ForgeGuiFactory implements IModGuiFactory
protected GuiScreen buildChildScreen()
{
List<IConfigElement> list = new ArrayList<IConfigElement>();
list.add(new DummyCategoryElement("addForgeChunkLoadingModCfg", "forge.configgui.ctgy.forgeChunkLoadingAddModConfig",
list.add(new DummyCategoryElement("addForgeChunkLoadingModCfg", "forge.configgui.ctgy.forgeChunkLoadingAddModConfig",
AddModOverrideEntry.class));
for (ConfigCategory cc : ForgeChunkManager.getModCategories())
list.add(new ConfigElement(cc));
return new GuiConfig(this.owningScreen, list, this.owningScreen.modID,
this.configElement.requiresWorldRestart() || this.owningScreen.allRequireWorldRestart,
this.configElement.requiresMcRestart() || this.owningScreen.allRequireMcRestart, this.owningScreen.title,
this.configElement.requiresMcRestart() || this.owningScreen.allRequireMcRestart, this.owningScreen.title,
I18n.format("forge.configgui.ctgy.forgeChunkLoadingModConfig"));
}
/**
* By overriding the enabled() method and checking the value of the "enabled" entry this entry is enabled/disabled based on the value of
* the other entry.
* the other entry.
*/
@Override
public boolean enabled()
@@ -211,10 +211,10 @@ public class ForgeGuiFactory implements IModGuiFactory
return Boolean.valueOf(entry.getCurrentValue().toString());
}
}
return true;
}
/**
* Check to see if the child screen's entry list has changed.
*/
@@ -228,7 +228,7 @@ public class ForgeGuiFactory implements IModGuiFactory
}
return false;
}
/**
* Since adding a new entry to the child screen is what constitutes a change here, reset the child
* screen listEntries to the saved list.
@@ -242,12 +242,12 @@ public class ForgeGuiFactory implements IModGuiFactory
for (IConfigEntry ice : child.entryList.listEntries)
if (!child.initEntries.contains(ice) && ForgeChunkManager.getConfig().hasCategory(ice.getName()))
ForgeChunkManager.getConfig().removeCategory(ForgeChunkManager.getConfig().getCategory(ice.getName()));
child.entryList.listEntries = new ArrayList<IConfigEntry>(child.initEntries);
}
}
}
/**
* This custom list entry provides a button that will open to a screen that will allow a user to define a new mod override.
*/
@@ -257,29 +257,29 @@ public class ForgeGuiFactory implements IModGuiFactory
{
super(owningScreen, owningEntryList, prop);
}
@Override
protected GuiScreen buildChildScreen()
{
List<IConfigElement> list = new ArrayList<IConfigElement>();
list.add(new DummyConfigElement("modID", "", ConfigGuiType.STRING, "forge.configgui.modID").setCustomListEntryClass(ModIDEntry.class));
list.add(new ConfigElement<Integer>(new Property("maximumTicketCount", "200", Property.Type.INTEGER, "forge.configgui.maximumTicketCount")));
list.add(new ConfigElement<Integer>(new Property("maximumChunksPerTicket", "25", Property.Type.INTEGER, "forge.configgui.maximumChunksPerTicket")));
list.add(new ConfigElement(new Property("maximumTicketCount", "200", Property.Type.INTEGER, "forge.configgui.maximumTicketCount")));
list.add(new ConfigElement(new Property("maximumChunksPerTicket", "25", Property.Type.INTEGER, "forge.configgui.maximumChunksPerTicket")));
return new GuiConfig(this.owningScreen, list, this.owningScreen.modID,
this.configElement.requiresWorldRestart() || this.owningScreen.allRequireWorldRestart,
this.configElement.requiresMcRestart() || this.owningScreen.allRequireMcRestart, this.owningScreen.title,
I18n.format("forge.configgui.ctgy.forgeChunkLoadingAddModConfig"));
}
@Override
public boolean isChanged()
{
return false;
}
}
/**
* This custom list entry provides a Mod ID selector. The control is a button that opens a list of values to select from.
* This entry also overrides onGuiClosed() to run code to save the data to a new ConfigCategory when the user is done.
@@ -287,26 +287,26 @@ public class ForgeGuiFactory implements IModGuiFactory
public static class ModIDEntry extends SelectValueEntry
{
public ModIDEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop)
{
{
super(owningScreen, owningEntryList, prop, getSelectableValues());
if (this.selectableValues.size() == 0)
this.btnValue.enabled = false;
}
private static Map<Object, String> getSelectableValues()
{
Map<Object, String> selectableValues = new TreeMap<Object, String>();
for (ModContainer mod : Loader.instance().getActiveModList())
// only add mods to the list that have a non-immutable ModContainer
if (!mod.isImmutable() && mod.getMod() != null)
selectableValues.put(mod.getModId(), mod.getName());
return selectableValues;
}
/**
* By overriding onGuiClosed() for this entry we can perform additional actions when the user is done such as saving
* By overriding onGuiClosed() for this entry we can perform additional actions when the user is done such as saving
* a new ConfigCategory object to the Configuration object.
*/
@Override
@@ -323,25 +323,25 @@ public class ForgeGuiFactory implements IModGuiFactory
maxTickets = Integer.valueOf(ice.get().toString());
else if ("maximumChunksPerTicket".equals(ice.getName()))
maxChunks = Integer.valueOf(ice.get().toString());
ForgeChunkManager.addConfigProperty(modObject, "maximumTicketCount", String.valueOf(maxTickets), Property.Type.INTEGER);
ForgeChunkManager.addConfigProperty(modObject, "maximumChunksPerTicket", String.valueOf(maxChunks), Property.Type.INTEGER);
if (this.owningScreen.parentScreen instanceof GuiConfig)
{
GuiConfig superParent = (GuiConfig) this.owningScreen.parentScreen;
ConfigCategory modCtgy = ForgeChunkManager.getConfigFor(modObject);
modCtgy.setPropertyOrder(ForgeChunkManager.MOD_PROP_ORDER);
ConfigElement modConfig = new ConfigElement(modCtgy);
boolean found = false;
for (IConfigElement ice : superParent.configElements)
if (ice.getName().equals(currentValue))
found = true;
if (!found)
superParent.configElements.add(modConfig);
superParent.needsRefresh = true;
superParent.initGui();
}
@@ -1,79 +0,0 @@
package net.minecraftforge.client.model;
// TODO: Move this package to net.minecraftforge.model in 1.8
import java.util.Collection;
import java.util.Map;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.obj.ObjModelLoader;
import net.minecraftforge.client.model.techne.TechneModelLoader;
import com.google.common.collect.Maps;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Common interface for advanced model loading from files, based on file suffix
* Model support can be queried through the {@link #getSupportedSuffixes()} method.
* Instances can be created by calling {@link #loadModel(String)} with a class-loadable-path
*
* @author cpw
*
*/
@SideOnly(Side.CLIENT)
public class AdvancedModelLoader {
private static Map<String, IModelCustomLoader> instances = Maps.newHashMap();
/**
* Register a new model handler
* @param modelHandler The model handler to register
*/
public static void registerModelHandler(IModelCustomLoader modelHandler)
{
for (String suffix : modelHandler.getSuffixes())
{
instances.put(suffix, modelHandler);
}
}
/**
* Load the model from the supplied classpath resolvable resource name
* @param resource The resource name
* @return A model
* @throws IllegalArgumentException if the resource name cannot be understood
* @throws ModelFormatException if the underlying model handler cannot parse the model format
*/
public static IModelCustom loadModel(ResourceLocation resource) throws IllegalArgumentException, ModelFormatException
{
String name = resource.getResourcePath();
int i = name.lastIndexOf('.');
if (i == -1)
{
FMLLog.severe("The resource name %s is not valid", resource);
throw new IllegalArgumentException("The resource name is not valid");
}
String suffix = name.substring(i+1);
IModelCustomLoader loader = instances.get(suffix);
if (loader == null)
{
FMLLog.severe("The resource name %s is not supported", resource);
throw new IllegalArgumentException("The resource name is not supported");
}
return loader.loadInstance(resource);
}
public static Collection<String> getSupportedSuffixes()
{
return instances.keySet();
}
static
{
registerModelHandler(new ObjModelLoader());
registerModelHandler(new TechneModelLoader());
}
}
@@ -1,17 +0,0 @@
package net.minecraftforge.client.model;
import static cpw.mods.fml.relauncher.Side.CLIENT;
import cpw.mods.fml.relauncher.SideOnly;
public interface IModelCustom
{
String getType();
@SideOnly(CLIENT)
void renderAll();
@SideOnly(CLIENT)
void renderOnly(String... groupNames);
@SideOnly(CLIENT)
void renderPart(String partName);
@SideOnly(CLIENT)
void renderAllExcept(String... excludedGroupNames);
}
@@ -1,29 +0,0 @@
package net.minecraftforge.client.model;
import net.minecraft.util.ResourceLocation;
/**
* Instances of this class act as factories for their model type
*
* @author cpw
*
*/
public interface IModelCustomLoader {
/**
* Get the main type name for this loader
* @return the type name
*/
String getType();
/**
* Get resource suffixes this model loader recognizes
* @return a list of suffixes
*/
String[] getSuffixes();
/**
* Load a model instance from the supplied path
* @param resource The ResourceLocation of the model
* @return A model instance
* @throws ModelFormatException if the model format is not correct
*/
IModelCustom loadInstance(ResourceLocation resource) throws ModelFormatException;
}
@@ -1,33 +0,0 @@
package net.minecraftforge.client.model;
/**
* Thrown if there is a problem parsing the model
*
* @author cpw
*
*/
public class ModelFormatException extends RuntimeException {
private static final long serialVersionUID = 2023547503969671835L;
public ModelFormatException()
{
super();
}
public ModelFormatException(String message, Throwable cause)
{
super(message, cause);
}
public ModelFormatException(String message)
{
super(message);
}
public ModelFormatException(Throwable cause)
{
super(cause);
}
}
@@ -1,84 +0,0 @@
package net.minecraftforge.client.model.obj;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.Vec3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class Face
{
public Vertex[] vertices;
public Vertex[] vertexNormals;
public Vertex faceNormal;
public TextureCoordinate[] textureCoordinates;
@SideOnly(Side.CLIENT)
public void addFaceForRender(Tessellator tessellator)
{
addFaceForRender(tessellator, 0.0005F);
}
@SideOnly(Side.CLIENT)
public void addFaceForRender(Tessellator tessellator, float textureOffset)
{
if (faceNormal == null)
{
faceNormal = this.calculateFaceNormal();
}
tessellator.setNormal(faceNormal.x, faceNormal.y, faceNormal.z);
float averageU = 0F;
float averageV = 0F;
if ((textureCoordinates != null) && (textureCoordinates.length > 0))
{
for (int i = 0; i < textureCoordinates.length; ++i)
{
averageU += textureCoordinates[i].u;
averageV += textureCoordinates[i].v;
}
averageU = averageU / textureCoordinates.length;
averageV = averageV / textureCoordinates.length;
}
float offsetU, offsetV;
for (int i = 0; i < vertices.length; ++i)
{
if ((textureCoordinates != null) && (textureCoordinates.length > 0))
{
offsetU = textureOffset;
offsetV = textureOffset;
if (textureCoordinates[i].u > averageU)
{
offsetU = -offsetU;
}
if (textureCoordinates[i].v > averageV)
{
offsetV = -offsetV;
}
tessellator.addVertexWithUV(vertices[i].x, vertices[i].y, vertices[i].z, textureCoordinates[i].u + offsetU, textureCoordinates[i].v + offsetV);
}
else
{
tessellator.addVertex(vertices[i].x, vertices[i].y, vertices[i].z);
}
}
}
public Vertex calculateFaceNormal()
{
Vec3 v1 = Vec3.createVectorHelper(vertices[1].x - vertices[0].x, vertices[1].y - vertices[0].y, vertices[1].z - vertices[0].z);
Vec3 v2 = Vec3.createVectorHelper(vertices[2].x - vertices[0].x, vertices[2].y - vertices[0].y, vertices[2].z - vertices[0].z);
Vec3 normalVector = null;
normalVector = v1.crossProduct(v2).normalize();
return new Vertex((float) normalVector.xCoord, (float) normalVector.yCoord, (float) normalVector.zCoord);
}
}
@@ -1,54 +0,0 @@
package net.minecraftforge.client.model.obj;
import java.util.ArrayList;
import net.minecraft.client.renderer.Tessellator;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class GroupObject
{
public String name;
public ArrayList<Face> faces = new ArrayList<Face>();
public int glDrawingMode;
public GroupObject()
{
this("");
}
public GroupObject(String name)
{
this(name, -1);
}
public GroupObject(String name, int glDrawingMode)
{
this.name = name;
this.glDrawingMode = glDrawingMode;
}
@SideOnly(Side.CLIENT)
public void render()
{
if (faces.size() > 0)
{
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawing(glDrawingMode);
render(tessellator);
tessellator.draw();
}
}
@SideOnly(Side.CLIENT)
public void render(Tessellator tessellator)
{
if (faces.size() > 0)
{
for (Face face : faces)
{
face.addFaceForRender(tessellator);
}
}
}
}
@@ -1,29 +0,0 @@
package net.minecraftforge.client.model.obj;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IModelCustom;
import net.minecraftforge.client.model.IModelCustomLoader;
import net.minecraftforge.client.model.ModelFormatException;
public class ObjModelLoader implements IModelCustomLoader
{
@Override
public String getType()
{
return "OBJ model";
}
private static final String[] types = { "obj" };
@Override
public String[] getSuffixes()
{
return types;
}
@Override
public IModelCustom loadInstance(ResourceLocation resource) throws ModelFormatException
{
return new WavefrontObject(resource);
}
}
@@ -1,21 +0,0 @@
package net.minecraftforge.client.model.obj;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class TextureCoordinate
{
public float u, v, w;
public TextureCoordinate(float u, float v)
{
this(u, v, 0F);
}
public TextureCoordinate(float u, float v, float w)
{
this.u = u;
this.v = v;
this.w = w;
}
}
@@ -1,21 +0,0 @@
package net.minecraftforge.client.model.obj;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class Vertex
{
public float x, y, z;
public Vertex(float x, float y)
{
this(x, y, 0F);
}
public Vertex(float x, float y, float z)
{
this.x = x;
this.y = y;
this.z = z;
}
}
@@ -1,660 +0,0 @@
package net.minecraftforge.client.model.obj;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.resources.IResource;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IModelCustom;
import net.minecraftforge.client.model.ModelFormatException;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Wavefront Object importer
* Based heavily off of the specifications found at http://en.wikipedia.org/wiki/Wavefront_.obj_file
*/
public class WavefrontObject implements IModelCustom
{
private static Pattern vertexPattern = Pattern.compile("(v( (\\-){0,1}\\d+\\.\\d+){3,4} *\\n)|(v( (\\-){0,1}\\d+\\.\\d+){3,4} *$)");
private static Pattern vertexNormalPattern = Pattern.compile("(vn( (\\-){0,1}\\d+\\.\\d+){3,4} *\\n)|(vn( (\\-){0,1}\\d+\\.\\d+){3,4} *$)");
private static Pattern textureCoordinatePattern = Pattern.compile("(vt( (\\-){0,1}\\d+\\.\\d+){2,3} *\\n)|(vt( (\\-){0,1}\\d+\\.\\d+){2,3} *$)");
private static Pattern face_V_VT_VN_Pattern = Pattern.compile("(f( \\d+/\\d+/\\d+){3,4} *\\n)|(f( \\d+/\\d+/\\d+){3,4} *$)");
private static Pattern face_V_VT_Pattern = Pattern.compile("(f( \\d+/\\d+){3,4} *\\n)|(f( \\d+/\\d+){3,4} *$)");
private static Pattern face_V_VN_Pattern = Pattern.compile("(f( \\d+//\\d+){3,4} *\\n)|(f( \\d+//\\d+){3,4} *$)");
private static Pattern face_V_Pattern = Pattern.compile("(f( \\d+){3,4} *\\n)|(f( \\d+){3,4} *$)");
private static Pattern groupObjectPattern = Pattern.compile("([go]( [\\w\\d\\.]+) *\\n)|([go]( [\\w\\d\\.]+) *$)");
private static Matcher vertexMatcher, vertexNormalMatcher, textureCoordinateMatcher;
private static Matcher face_V_VT_VN_Matcher, face_V_VT_Matcher, face_V_VN_Matcher, face_V_Matcher;
private static Matcher groupObjectMatcher;
public ArrayList<Vertex> vertices = new ArrayList<Vertex>();
public ArrayList<Vertex> vertexNormals = new ArrayList<Vertex>();
public ArrayList<TextureCoordinate> textureCoordinates = new ArrayList<TextureCoordinate>();
public ArrayList<GroupObject> groupObjects = new ArrayList<GroupObject>();
private GroupObject currentGroupObject;
private String fileName;
public WavefrontObject(ResourceLocation resource) throws ModelFormatException
{
this.fileName = resource.toString();
try
{
IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource);
loadObjModel(res.getInputStream());
}
catch (IOException e)
{
throw new ModelFormatException("IO Exception reading model format", e);
}
}
public WavefrontObject(String filename, InputStream inputStream) throws ModelFormatException
{
this.fileName = filename;
loadObjModel(inputStream);
}
private void loadObjModel(InputStream inputStream) throws ModelFormatException
{
BufferedReader reader = null;
String currentLine = null;
int lineCount = 0;
try
{
reader = new BufferedReader(new InputStreamReader(inputStream));
while ((currentLine = reader.readLine()) != null)
{
lineCount++;
currentLine = currentLine.replaceAll("\\s+", " ").trim();
if (currentLine.startsWith("#") || currentLine.length() == 0)
{
continue;
}
else if (currentLine.startsWith("v "))
{
Vertex vertex = parseVertex(currentLine, lineCount);
if (vertex != null)
{
vertices.add(vertex);
}
}
else if (currentLine.startsWith("vn "))
{
Vertex vertex = parseVertexNormal(currentLine, lineCount);
if (vertex != null)
{
vertexNormals.add(vertex);
}
}
else if (currentLine.startsWith("vt "))
{
TextureCoordinate textureCoordinate = parseTextureCoordinate(currentLine, lineCount);
if (textureCoordinate != null)
{
textureCoordinates.add(textureCoordinate);
}
}
else if (currentLine.startsWith("f "))
{
if (currentGroupObject == null)
{
currentGroupObject = new GroupObject("Default");
}
Face face = parseFace(currentLine, lineCount);
if (face != null)
{
currentGroupObject.faces.add(face);
}
}
else if (currentLine.startsWith("g ") | currentLine.startsWith("o "))
{
GroupObject group = parseGroupObject(currentLine, lineCount);
if (group != null)
{
if (currentGroupObject != null)
{
groupObjects.add(currentGroupObject);
}
}
currentGroupObject = group;
}
}
groupObjects.add(currentGroupObject);
}
catch (IOException e)
{
throw new ModelFormatException("IO Exception reading model format", e);
}
finally
{
try
{
reader.close();
}
catch (IOException e)
{
// hush
}
try
{
inputStream.close();
}
catch (IOException e)
{
// hush
}
}
}
@Override
@SideOnly(Side.CLIENT)
public void renderAll()
{
Tessellator tessellator = Tessellator.instance;
if (currentGroupObject != null)
{
tessellator.startDrawing(currentGroupObject.glDrawingMode);
}
else
{
tessellator.startDrawing(GL11.GL_TRIANGLES);
}
tessellateAll(tessellator);
tessellator.draw();
}
@SideOnly(Side.CLIENT)
public void tessellateAll(Tessellator tessellator)
{
for (GroupObject groupObject : groupObjects)
{
groupObject.render(tessellator);
}
}
@Override
@SideOnly(Side.CLIENT)
public void renderOnly(String... groupNames)
{
for (GroupObject groupObject : groupObjects)
{
for (String groupName : groupNames)
{
if (groupName.equalsIgnoreCase(groupObject.name))
{
groupObject.render();
}
}
}
}
@SideOnly(Side.CLIENT)
public void tessellateOnly(Tessellator tessellator, String... groupNames) {
for (GroupObject groupObject : groupObjects)
{
for (String groupName : groupNames)
{
if (groupName.equalsIgnoreCase(groupObject.name))
{
groupObject.render(tessellator);
}
}
}
}
@Override
@SideOnly(Side.CLIENT)
public void renderPart(String partName)
{
for (GroupObject groupObject : groupObjects)
{
if (partName.equalsIgnoreCase(groupObject.name))
{
groupObject.render();
}
}
}
@SideOnly(Side.CLIENT)
public void tessellatePart(Tessellator tessellator, String partName) {
for (GroupObject groupObject : groupObjects)
{
if (partName.equalsIgnoreCase(groupObject.name))
{
groupObject.render(tessellator);
}
}
}
@Override
@SideOnly(Side.CLIENT)
public void renderAllExcept(String... excludedGroupNames)
{
for (GroupObject groupObject : groupObjects)
{
boolean skipPart=false;
for (String excludedGroupName : excludedGroupNames)
{
if (excludedGroupName.equalsIgnoreCase(groupObject.name))
{
skipPart=true;
}
}
if(!skipPart)
{
groupObject.render();
}
}
}
@SideOnly(Side.CLIENT)
public void tessellateAllExcept(Tessellator tessellator, String... excludedGroupNames)
{
boolean exclude;
for (GroupObject groupObject : groupObjects)
{
exclude=false;
for (String excludedGroupName : excludedGroupNames)
{
if (excludedGroupName.equalsIgnoreCase(groupObject.name))
{
exclude=true;
}
}
if(!exclude)
{
groupObject.render(tessellator);
}
}
}
private Vertex parseVertex(String line, int lineCount) throws ModelFormatException
{
Vertex vertex = null;
if (isValidVertexLine(line))
{
line = line.substring(line.indexOf(" ") + 1);
String[] tokens = line.split(" ");
try
{
if (tokens.length == 2)
{
return new Vertex(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1]));
}
else if (tokens.length == 3)
{
return new Vertex(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2]));
}
}
catch (NumberFormatException e)
{
throw new ModelFormatException(String.format("Number formatting error at line %d",lineCount), e);
}
}
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format");
}
return vertex;
}
private Vertex parseVertexNormal(String line, int lineCount) throws ModelFormatException
{
Vertex vertexNormal = null;
if (isValidVertexNormalLine(line))
{
line = line.substring(line.indexOf(" ") + 1);
String[] tokens = line.split(" ");
try
{
if (tokens.length == 3)
return new Vertex(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2]));
}
catch (NumberFormatException e)
{
throw new ModelFormatException(String.format("Number formatting error at line %d",lineCount), e);
}
}
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format");
}
return vertexNormal;
}
private TextureCoordinate parseTextureCoordinate(String line, int lineCount) throws ModelFormatException
{
TextureCoordinate textureCoordinate = null;
if (isValidTextureCoordinateLine(line))
{
line = line.substring(line.indexOf(" ") + 1);
String[] tokens = line.split(" ");
try
{
if (tokens.length == 2)
return new TextureCoordinate(Float.parseFloat(tokens[0]), 1 - Float.parseFloat(tokens[1]));
else if (tokens.length == 3)
return new TextureCoordinate(Float.parseFloat(tokens[0]), 1 - Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2]));
}
catch (NumberFormatException e)
{
throw new ModelFormatException(String.format("Number formatting error at line %d",lineCount), e);
}
}
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format");
}
return textureCoordinate;
}
private Face parseFace(String line, int lineCount) throws ModelFormatException
{
Face face = null;
if (isValidFaceLine(line))
{
face = new Face();
String trimmedLine = line.substring(line.indexOf(" ") + 1);
String[] tokens = trimmedLine.split(" ");
String[] subTokens = null;
if (tokens.length == 3)
{
if (currentGroupObject.glDrawingMode == -1)
{
currentGroupObject.glDrawingMode = GL11.GL_TRIANGLES;
}
else if (currentGroupObject.glDrawingMode != GL11.GL_TRIANGLES)
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Invalid number of points for face (expected 4, found " + tokens.length + ")");
}
}
else if (tokens.length == 4)
{
if (currentGroupObject.glDrawingMode == -1)
{
currentGroupObject.glDrawingMode = GL11.GL_QUADS;
}
else if (currentGroupObject.glDrawingMode != GL11.GL_QUADS)
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Invalid number of points for face (expected 3, found " + tokens.length + ")");
}
}
// f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 ...
if (isValidFace_V_VT_VN_Line(line))
{
face.vertices = new Vertex[tokens.length];
face.textureCoordinates = new TextureCoordinate[tokens.length];
face.vertexNormals = new Vertex[tokens.length];
for (int i = 0; i < tokens.length; ++i)
{
subTokens = tokens[i].split("/");
face.vertices[i] = vertices.get(Integer.parseInt(subTokens[0]) - 1);
face.textureCoordinates[i] = textureCoordinates.get(Integer.parseInt(subTokens[1]) - 1);
face.vertexNormals[i] = vertexNormals.get(Integer.parseInt(subTokens[2]) - 1);
}
face.faceNormal = face.calculateFaceNormal();
}
// f v1/vt1 v2/vt2 v3/vt3 ...
else if (isValidFace_V_VT_Line(line))
{
face.vertices = new Vertex[tokens.length];
face.textureCoordinates = new TextureCoordinate[tokens.length];
for (int i = 0; i < tokens.length; ++i)
{
subTokens = tokens[i].split("/");
face.vertices[i] = vertices.get(Integer.parseInt(subTokens[0]) - 1);
face.textureCoordinates[i] = textureCoordinates.get(Integer.parseInt(subTokens[1]) - 1);
}
face.faceNormal = face.calculateFaceNormal();
}
// f v1//vn1 v2//vn2 v3//vn3 ...
else if (isValidFace_V_VN_Line(line))
{
face.vertices = new Vertex[tokens.length];
face.vertexNormals = new Vertex[tokens.length];
for (int i = 0; i < tokens.length; ++i)
{
subTokens = tokens[i].split("//");
face.vertices[i] = vertices.get(Integer.parseInt(subTokens[0]) - 1);
face.vertexNormals[i] = vertexNormals.get(Integer.parseInt(subTokens[1]) - 1);
}
face.faceNormal = face.calculateFaceNormal();
}
// f v1 v2 v3 ...
else if (isValidFace_V_Line(line))
{
face.vertices = new Vertex[tokens.length];
for (int i = 0; i < tokens.length; ++i)
{
face.vertices[i] = vertices.get(Integer.parseInt(tokens[i]) - 1);
}
face.faceNormal = face.calculateFaceNormal();
}
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format");
}
}
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format");
}
return face;
}
private GroupObject parseGroupObject(String line, int lineCount) throws ModelFormatException
{
GroupObject group = null;
if (isValidGroupObjectLine(line))
{
String trimmedLine = line.substring(line.indexOf(" ") + 1);
if (trimmedLine.length() > 0)
{
group = new GroupObject(trimmedLine);
}
}
else
{
throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format");
}
return group;
}
/***
* Verifies that the given line from the model file is a valid vertex
* @param line the line being validated
* @return true if the line is a valid vertex, false otherwise
*/
private static boolean isValidVertexLine(String line)
{
if (vertexMatcher != null)
{
vertexMatcher.reset();
}
vertexMatcher = vertexPattern.matcher(line);
return vertexMatcher.matches();
}
/***
* Verifies that the given line from the model file is a valid vertex normal
* @param line the line being validated
* @return true if the line is a valid vertex normal, false otherwise
*/
private static boolean isValidVertexNormalLine(String line)
{
if (vertexNormalMatcher != null)
{
vertexNormalMatcher.reset();
}
vertexNormalMatcher = vertexNormalPattern.matcher(line);
return vertexNormalMatcher.matches();
}
/***
* Verifies that the given line from the model file is a valid texture coordinate
* @param line the line being validated
* @return true if the line is a valid texture coordinate, false otherwise
*/
private static boolean isValidTextureCoordinateLine(String line)
{
if (textureCoordinateMatcher != null)
{
textureCoordinateMatcher.reset();
}
textureCoordinateMatcher = textureCoordinatePattern.matcher(line);
return textureCoordinateMatcher.matches();
}
/***
* Verifies that the given line from the model file is a valid face that is described by vertices, texture coordinates, and vertex normals
* @param line the line being validated
* @return true if the line is a valid face that matches the format "f v1/vt1/vn1 ..." (with a minimum of 3 points in the face, and a maximum of 4), false otherwise
*/
private static boolean isValidFace_V_VT_VN_Line(String line)
{
if (face_V_VT_VN_Matcher != null)
{
face_V_VT_VN_Matcher.reset();
}
face_V_VT_VN_Matcher = face_V_VT_VN_Pattern.matcher(line);
return face_V_VT_VN_Matcher.matches();
}
/***
* Verifies that the given line from the model file is a valid face that is described by vertices and texture coordinates
* @param line the line being validated
* @return true if the line is a valid face that matches the format "f v1/vt1 ..." (with a minimum of 3 points in the face, and a maximum of 4), false otherwise
*/
private static boolean isValidFace_V_VT_Line(String line)
{
if (face_V_VT_Matcher != null)
{
face_V_VT_Matcher.reset();
}
face_V_VT_Matcher = face_V_VT_Pattern.matcher(line);
return face_V_VT_Matcher.matches();
}
/***
* Verifies that the given line from the model file is a valid face that is described by vertices and vertex normals
* @param line the line being validated
* @return true if the line is a valid face that matches the format "f v1//vn1 ..." (with a minimum of 3 points in the face, and a maximum of 4), false otherwise
*/
private static boolean isValidFace_V_VN_Line(String line)
{
if (face_V_VN_Matcher != null)
{
face_V_VN_Matcher.reset();
}
face_V_VN_Matcher = face_V_VN_Pattern.matcher(line);
return face_V_VN_Matcher.matches();
}
/***
* Verifies that the given line from the model file is a valid face that is described by only vertices
* @param line the line being validated
* @return true if the line is a valid face that matches the format "f v1 ..." (with a minimum of 3 points in the face, and a maximum of 4), false otherwise
*/
private static boolean isValidFace_V_Line(String line)
{
if (face_V_Matcher != null)
{
face_V_Matcher.reset();
}
face_V_Matcher = face_V_Pattern.matcher(line);
return face_V_Matcher.matches();
}
/***
* Verifies that the given line from the model file is a valid face of any of the possible face formats
* @param line the line being validated
* @return true if the line is a valid face that matches any of the valid face formats, false otherwise
*/
private static boolean isValidFaceLine(String line)
{
return isValidFace_V_VT_VN_Line(line) || isValidFace_V_VT_Line(line) || isValidFace_V_VN_Line(line) || isValidFace_V_Line(line);
}
/***
* Verifies that the given line from the model file is a valid group (or object)
* @param line the line being validated
* @return true if the line is a valid group (or object), false otherwise
*/
private static boolean isValidGroupObjectLine(String line)
{
if (groupObjectMatcher != null)
{
groupObjectMatcher.reset();
}
groupObjectMatcher = groupObjectPattern.matcher(line);
return groupObjectMatcher.matches();
}
@Override
public String getType()
{
return "obj";
}
}
@@ -1,365 +0,0 @@
package net.minecraftforge.client.model.techne;
import java.awt.Dimension;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipInputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.resources.IResource;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IModelCustom;
import net.minecraftforge.client.model.ModelFormatException;
/**
* Techne model importer, based on iChun's Hats importer
*/
@SideOnly(Side.CLIENT)
public class TechneModel extends ModelBase implements IModelCustom {
public static final List<String> cubeTypes = Arrays.asList(
"d9e621f7-957f-4b77-b1ae-20dcd0da7751",
"de81aa14-bd60-4228-8d8d-5238bcd3caaa"
);
private String fileName;
private Map<String, byte[]> zipContents = new HashMap<String, byte[]>();
private Map<String, ModelRenderer> parts = new LinkedHashMap<String, ModelRenderer>();
private String texture = null;
private Dimension textureDims = null;
private int textureName;
private boolean textureNameSet = false;
public TechneModel(ResourceLocation resource) throws ModelFormatException
{
this.fileName = resource.toString();
try
{
IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource);
loadTechneModel(res.getInputStream());
}
catch (IOException e)
{
throw new ModelFormatException("IO Exception reading model format", e);
}
}
private void loadTechneModel(InputStream stream) throws ModelFormatException
{
try
{
ZipInputStream zipInput = new ZipInputStream(stream);
ZipEntry entry;
while ((entry = zipInput.getNextEntry()) != null)
{
byte[] data = new byte[(int) entry.getSize()];
// For some reason, using read(byte[]) makes reading stall upon reaching a 0x1E byte
int i = 0;
while (zipInput.available() > 0 && i < data.length)
{
data[i++] = (byte)zipInput.read();
}
zipContents.put(entry.getName(), data);
}
byte[] modelXml = zipContents.get("model.xml");
if (modelXml == null)
{
throw new ModelFormatException("Model " + fileName + " contains no model.xml file");
}
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(new ByteArrayInputStream(modelXml));
NodeList nodeListTechne = document.getElementsByTagName("Techne");
if (nodeListTechne.getLength() < 1)
{
throw new ModelFormatException("Model " + fileName + " contains no Techne tag");
}
NodeList nodeListModel = document.getElementsByTagName("Model");
if (nodeListModel.getLength() < 1)
{
throw new ModelFormatException("Model " + fileName + " contains no Model tag");
}
NamedNodeMap modelAttributes = nodeListModel.item(0).getAttributes();
if (modelAttributes == null)
{
throw new ModelFormatException("Model " + fileName + " contains a Model tag with no attributes");
}
Node modelTexture = modelAttributes.getNamedItem("texture");
if (modelTexture != null)
{
texture = modelTexture.getTextContent();
}
NodeList textureDim = document.getElementsByTagName("TextureSize");
if (textureDim.getLength() > 0)
{
try
{
String[] tmp = textureDim.item(0).getTextContent().split(",");
if (tmp.length == 2)
{
this.textureDims = new Dimension(Integer.parseInt(tmp[0]), Integer.parseInt(tmp[1]));
}
}
catch (NumberFormatException e)
{
throw new ModelFormatException("Model " + fileName + " contains a TextureSize tag with invalid data");
}
}
NodeList shapes = document.getElementsByTagName("Shape");
for (int i = 0; i < shapes.getLength(); i++)
{
Node shape = shapes.item(i);
NamedNodeMap shapeAttributes = shape.getAttributes();
if (shapeAttributes == null)
{
throw new ModelFormatException("Shape #" + (i + 1) + " in " + fileName + " has no attributes");
}
Node name = shapeAttributes.getNamedItem("name");
String shapeName = null;
if (name != null)
{
shapeName = name.getNodeValue();
}
if (shapeName == null)
{
shapeName = "Shape #" + (i + 1);
}
String shapeType = null;
Node type = shapeAttributes.getNamedItem("type");
if (type != null)
{
shapeType = type.getNodeValue();
}
if (shapeType != null && !cubeTypes.contains(shapeType))
{
FMLLog.warning("Model shape [" + shapeName + "] in " + fileName + " is not a cube, ignoring");
continue;
}
try
{
boolean mirrored = false;
String[] offset = new String[3];
String[] position = new String[3];
String[] rotation = new String[3];
String[] size = new String[3];
String[] textureOffset = new String[2];
NodeList shapeChildren = shape.getChildNodes();
for (int j = 0; j < shapeChildren.getLength(); j++)
{
Node shapeChild = shapeChildren.item(j);
String shapeChildName = shapeChild.getNodeName();
String shapeChildValue = shapeChild.getTextContent();
if (shapeChildValue != null)
{
shapeChildValue = shapeChildValue.trim();
if (shapeChildName.equals("IsMirrored"))
{
mirrored = !shapeChildValue.equals("False");
}
else if (shapeChildName.equals("Offset"))
{
offset = shapeChildValue.split(",");
}
else if (shapeChildName.equals("Position"))
{
position = shapeChildValue.split(",");
}
else if (shapeChildName.equals("Rotation"))
{
rotation = shapeChildValue.split(",");
}
else if (shapeChildName.equals("Size"))
{
size = shapeChildValue.split(",");
}
else if (shapeChildName.equals("TextureOffset"))
{
textureOffset = shapeChildValue.split(",");
}
}
}
// That's what the ModelBase subclassing is needed for
ModelRenderer cube = new ModelRenderer(this, Integer.parseInt(textureOffset[0]), Integer.parseInt(textureOffset[1]));
cube.mirror = mirrored;
cube.addBox(Float.parseFloat(offset[0]), Float.parseFloat(offset[1]), Float.parseFloat(offset[2]), Integer.parseInt(size[0]), Integer.parseInt(size[1]), Integer.parseInt(size[2]));
cube.setRotationPoint(Float.parseFloat(position[0]), Float.parseFloat(position[1]) - 23.4F, Float.parseFloat(position[2]));
cube.rotateAngleX = (float)Math.toRadians(Float.parseFloat(rotation[0]));
cube.rotateAngleY = (float)Math.toRadians(Float.parseFloat(rotation[1]));
cube.rotateAngleZ = (float)Math.toRadians(Float.parseFloat(rotation[2]));
if (this.textureDims != null)
{
cube.setTextureSize((int)textureDims.getWidth(), (int)textureDims.getHeight());
}
parts.put(shapeName, cube);
}
catch (NumberFormatException e)
{
FMLLog.warning("Model shape [" + shapeName + "] in " + fileName + " contains malformed integers within its data, ignoring");
e.printStackTrace();
}
}
}
catch (ZipException e)
{
throw new ModelFormatException("Model " + fileName + " is not a valid zip file");
}
catch (IOException e)
{
throw new ModelFormatException("Model " + fileName + " could not be read", e);
}
catch (ParserConfigurationException e)
{
// hush
}
catch (SAXException e)
{
throw new ModelFormatException("Model " + fileName + " contains invalid XML", e);
}
}
private void bindTexture()
{
/* TODO: Update to 1.6
if (texture != null)
{
if (!textureNameSet)
{
try
{
byte[] textureEntry = zipContents.get(texture);
if (textureEntry == null)
{
throw new ModelFormatException("Model " + fileName + " has no such texture " + texture);
}
BufferedImage image = ImageIO.read(new ByteArrayInputStream(textureEntry));
textureName = Minecraft.getMinecraft().renderEngine.allocateAndSetupTexture(image);
textureNameSet = true;
}
catch (ZipException e)
{
throw new ModelFormatException("Model " + fileName + " is not a valid zip file");
}
catch (IOException e)
{
throw new ModelFormatException("Texture for model " + fileName + " could not be read", e);
}
}
if (textureNameSet)
{
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureName);
Minecraft.getMinecraft().renderEngine.resetBoundTexture();
}
}
*/
}
@Override
public String getType()
{
return "tcn";
}
@Override
public void renderAll()
{
bindTexture();
for (ModelRenderer part : parts.values())
{
part.renderWithRotation(1.0F);
}
}
@Override
public void renderPart(String partName)
{
ModelRenderer part = parts.get(partName);
if (part != null)
{
bindTexture();
part.renderWithRotation(1.0F);
}
}
@Override
public void renderOnly(String... groupNames)
{
bindTexture();
for (ModelRenderer part : parts.values())
{
for (String groupName : groupNames)
{
if (groupName.equalsIgnoreCase(part.boxName))
{
part.render(1.0f);
}
}
}
}
@Override
public void renderAllExcept(String... excludedGroupNames)
{
for (ModelRenderer part : parts.values())
{
boolean skipPart=false;
for (String excludedGroupName : excludedGroupNames)
{
if (excludedGroupName.equalsIgnoreCase(part.boxName))
{
skipPart=true;
}
}
if(!skipPart)
{
part.render(1.0f);
}
}
}
}
@@ -1,29 +0,0 @@
package net.minecraftforge.client.model.techne;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IModelCustom;
import net.minecraftforge.client.model.IModelCustomLoader;
import net.minecraftforge.client.model.ModelFormatException;
public class TechneModelLoader implements IModelCustomLoader {
@Override
public String getType()
{
return "Techne model";
}
private static final String[] types = { "tcn" };
@Override
public String[] getSuffixes()
{
return types;
}
@Override
public IModelCustom loadInstance(ResourceLocation resource) throws ModelFormatException
{
return new TechneModel(resource);
}
}