2011-07-15 23:13:09 +00:00
|
|
|
/**
|
2012-02-25 06:07:58 +00:00
|
|
|
* This software is provided under the terms of the Minecraft Forge Public
|
2011-07-15 23:13:09 +00:00
|
|
|
* License v1.0.
|
|
|
|
*/
|
|
|
|
|
2011-07-15 23:04:10 +00:00
|
|
|
package net.minecraft.src.forge;
|
|
|
|
|
2012-03-20 13:43:05 +00:00
|
|
|
import org.lwjgl.opengl.Display;
|
|
|
|
|
2011-07-15 23:04:10 +00:00
|
|
|
import net.minecraft.src.Block;
|
2012-06-14 04:09:00 +00:00
|
|
|
import net.minecraft.src.Entity;
|
2011-09-03 11:46:59 +00:00
|
|
|
import net.minecraft.src.Item;
|
2012-03-19 18:37:51 +00:00
|
|
|
import net.minecraft.src.ItemStack;
|
2011-07-15 23:04:10 +00:00
|
|
|
import net.minecraft.src.ModLoader;
|
|
|
|
import net.minecraft.src.RenderBlocks;
|
2012-07-11 00:02:13 +00:00
|
|
|
import net.minecraft.src.World;
|
2012-04-10 05:57:52 +00:00
|
|
|
import net.minecraft.src.forge.IItemRenderer.ItemRenderType;
|
2011-07-15 23:04:10 +00:00
|
|
|
|
2012-02-25 06:07:58 +00:00
|
|
|
public class MinecraftForgeClient
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Registers a new block highlight handler.
|
|
|
|
*/
|
|
|
|
public static void registerHighlightHandler(IHighlightHandler handler)
|
|
|
|
{
|
|
|
|
ForgeHooksClient.highlightHandlers.add(handler);
|
|
|
|
}
|
2011-08-20 10:35:14 +00:00
|
|
|
|
2012-02-25 06:07:58 +00:00
|
|
|
/** Register a new render context handler. A render context is a block
|
|
|
|
* of rendering performed with similar OpenGL modes, for example,
|
|
|
|
* texture name.
|
|
|
|
* @param texture The name of the texture for this render context.
|
|
|
|
* @param subid The subid of this render context. 0 is the default pass
|
|
|
|
* for normal rendering, higher subids render later. All subids of 0
|
|
|
|
* will render before all subids of 1, etc.
|
|
|
|
* @param handler The handler to register.
|
|
|
|
*/
|
|
|
|
public static void registerRenderContextHandler(String texture, int subid, IRenderContextHandler handler)
|
|
|
|
{
|
|
|
|
ForgeHooksClient.registerRenderContextHandler(texture, subid, handler);
|
|
|
|
}
|
2012-04-07 06:01:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a Texture Load Handler
|
|
|
|
* @param handler The handler
|
|
|
|
*/
|
|
|
|
public static void registerTextureLoadHandler(ITextureLoadHandler handler)
|
|
|
|
{
|
|
|
|
ForgeHooksClient.textureLoadHandlers.add(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a Render Last Handler
|
|
|
|
* @param handler The handler
|
|
|
|
*/
|
|
|
|
public static void registerRenderLastHandler(IRenderWorldLastHandler handler)
|
|
|
|
{
|
|
|
|
ForgeHooksClient.renderWorldLastHandlers.add(handler);
|
|
|
|
}
|
2012-04-23 02:52:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a Sound Handler
|
|
|
|
* @param handler The handler
|
|
|
|
*/
|
|
|
|
public static void registerSoundHandler(ISoundHandler handler)
|
|
|
|
{
|
|
|
|
ForgeHooksClient.soundHandlers.add(handler);
|
2012-06-14 04:09:00 +00:00
|
|
|
checkMinecraftVersion("Minecraft Minecraft 1.2.5", "Interface check in registerSoundHandler, remove it Mods should be updated");
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (handler.getClass().getDeclaredMethod("onPlaySoundAtEntity", Entity.class, String.class, float.class, float.class) != null)
|
|
|
|
{
|
|
|
|
ForgeHooksClient.soundHandlers2.add(handler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2012-07-11 00:02:13 +00:00
|
|
|
if (World.class.getName().contains("World"))
|
2012-06-14 04:09:00 +00:00
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2012-04-23 02:52:09 +00:00
|
|
|
}
|
2011-12-21 09:01:45 +00:00
|
|
|
|
2012-02-25 06:07:58 +00:00
|
|
|
/** Bind a texture. This is used to bind a texture file when
|
|
|
|
* performing your own rendering, rather than using ITextureProvider.
|
|
|
|
*
|
|
|
|
* This variation is reserved for future expansion.
|
|
|
|
*/
|
|
|
|
public static void bindTexture(String texture, int subid)
|
|
|
|
{
|
|
|
|
ForgeHooksClient.bindTexture(texture, subid);
|
|
|
|
}
|
2011-07-15 23:04:10 +00:00
|
|
|
|
2012-02-25 06:07:58 +00:00
|
|
|
/** Bind a texture. This is used to bind a texture file when
|
|
|
|
* performing your own rendering, rather than using ITextureProvider.
|
|
|
|
*/
|
|
|
|
public static void bindTexture(String texture)
|
|
|
|
{
|
|
|
|
ForgeHooksClient.bindTexture(texture, 0);
|
|
|
|
}
|
2011-07-15 23:04:10 +00:00
|
|
|
|
2012-02-25 06:07:58 +00:00
|
|
|
/** Unbind a texture. This binds the default texture, when you are
|
|
|
|
* finished performing custom rendering.
|
|
|
|
*/
|
|
|
|
public static void unbindTexture()
|
|
|
|
{
|
|
|
|
ForgeHooksClient.unbindTexture();
|
|
|
|
}
|
2011-08-05 11:58:14 +00:00
|
|
|
|
2012-02-25 06:07:58 +00:00
|
|
|
/** Preload a texture. Textures must be preloaded before the first
|
|
|
|
* use, or they will cause visual anomalies.
|
|
|
|
*/
|
|
|
|
public static void preloadTexture(String texture)
|
|
|
|
{
|
|
|
|
ModLoader.getMinecraftInstance().renderEngine.getTexture(texture);
|
|
|
|
}
|
2011-08-12 23:53:30 +00:00
|
|
|
|
2012-02-25 06:07:58 +00:00
|
|
|
/** Render a block. Render a block which may have a custom texture.
|
|
|
|
*/
|
|
|
|
public static void renderBlock(RenderBlocks render, Block block, int X, int Y, int Z)
|
|
|
|
{
|
|
|
|
ForgeHooksClient.beforeBlockRender(block, render);
|
|
|
|
render.renderBlockByRenderType(block, X, Y, Z);
|
|
|
|
ForgeHooksClient.afterBlockRender(block, render);
|
|
|
|
}
|
2011-08-17 10:23:10 +00:00
|
|
|
|
2012-02-25 06:07:58 +00:00
|
|
|
/** Get the current render pass.
|
|
|
|
*/
|
|
|
|
public static int getRenderPass()
|
|
|
|
{
|
|
|
|
return ForgeHooksClient.renderPass;
|
|
|
|
}
|
2012-03-20 13:43:05 +00:00
|
|
|
|
2012-03-17 18:46:15 +00:00
|
|
|
private static IItemRenderer[] customItemRenderers = new IItemRenderer[Item.itemsList.length];
|
|
|
|
|
|
|
|
/** Register a custom renderer for a specific item. This can be used to
|
|
|
|
* render the item in-world as an EntityItem, when the item is equipped, or
|
|
|
|
* when the item is in an inventory slot.
|
|
|
|
* @param itemID The item ID (shifted index) to handle rendering.
|
|
|
|
* @param renderer The IItemRenderer interface that handles rendering for
|
|
|
|
* this item.
|
2012-03-16 04:26:09 +00:00
|
|
|
*/
|
2012-03-17 18:46:15 +00:00
|
|
|
public static void registerItemRenderer(int itemID, IItemRenderer renderer)
|
2012-03-16 04:26:09 +00:00
|
|
|
{
|
2012-03-17 18:46:15 +00:00
|
|
|
customItemRenderers[itemID] = renderer;
|
2012-03-16 04:26:09 +00:00
|
|
|
}
|
|
|
|
|
2012-03-19 18:37:51 +00:00
|
|
|
public static IItemRenderer getItemRenderer(ItemStack item, ItemRenderType type)
|
2012-03-16 04:26:09 +00:00
|
|
|
{
|
2012-03-19 18:37:51 +00:00
|
|
|
IItemRenderer renderer = customItemRenderers[item.itemID];
|
2012-03-23 02:46:36 +00:00
|
|
|
if (renderer != null && renderer.handleRenderType(item, type))
|
|
|
|
{
|
2012-03-19 18:37:51 +00:00
|
|
|
return customItemRenderers[item.itemID];
|
2012-03-17 18:46:15 +00:00
|
|
|
}
|
|
|
|
return null;
|
2012-02-25 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean hasInit = false;
|
|
|
|
public static void init()
|
|
|
|
{
|
|
|
|
if (hasInit)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hasInit = true;
|
|
|
|
ForgeHooks.setPacketHandler(new PacketHandlerClient());
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
2012-03-20 13:43:05 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
* This is a function that is used to enforce deprecation of code.
|
|
|
|
* It checks the current Display's title against the passed in argument.
|
|
|
|
* If they do not match (such is the case in different versionf of MC) it exits the process with a error
|
|
|
|
*
|
|
|
|
* @param version The version to find, usually "Minecraft Minecraft 1.2.3"
|
2012-03-23 02:46:36 +00:00
|
|
|
* @param message The error message to display in the crash log
|
2012-03-20 13:43:05 +00:00
|
|
|
*/
|
|
|
|
public static void checkMinecraftVersion(String version, String message)
|
|
|
|
{
|
|
|
|
if (!Display.getTitle().equals(version))
|
|
|
|
{
|
|
|
|
MinecraftForge.killMinecraft("Minecraft Forge", message.replaceAll("%version%", Display.getTitle()));
|
|
|
|
}
|
|
|
|
}
|
2011-07-15 23:04:10 +00:00
|
|
|
}
|