Remove all references to ModLoader

This commit is contained in:
Christian 2012-09-09 10:02:21 -04:00
parent 03b3017e51
commit 66b60bc85e
4 changed files with 81 additions and 72 deletions

View file

@ -7,6 +7,8 @@ import java.util.TreeSet;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import cpw.mods.fml.client.FMLClientHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.src.Block;
import net.minecraft.src.EntityItem;
@ -16,7 +18,6 @@ import net.minecraft.src.Item;
import net.minecraft.src.ItemBlock;
import net.minecraft.src.ItemStack;
import net.minecraft.src.MathHelper;
import net.minecraft.src.ModLoader;
import net.minecraft.src.MovingObjectPosition;
import net.minecraft.src.RenderBlocks;
import net.minecraft.src.RenderEngine;
@ -41,7 +42,7 @@ public class ForgeHooksClient
texture = textureID;
subid = subID;
}
public int compareTo(TesKey key)
{
if (subid == key.subid)
@ -50,18 +51,18 @@ public class ForgeHooksClient
}
return subid - key.subid;
}
public boolean equals(Object obj)
{
return compareTo((TesKey)obj) == 0;
}
public int hashCode()
{
return texture + 31 * subid;
}
}
public static HashMap<TesKey, Tessellator> tessellators = new HashMap<TesKey, Tessellator>();
public static HashMap<String, Integer> textures = new HashMap<String, Integer>();
public static TreeSet<TesKey> renderTextures = new TreeSet<TesKey>();
@ -69,24 +70,28 @@ public class ForgeHooksClient
public static boolean inWorld = false;
public static HashMap<TesKey, IRenderContextHandler> renderHandlers = new HashMap<TesKey, IRenderContextHandler>();
public static IRenderContextHandler unbindContext = null;
protected static void registerRenderContextHandler(String texture, int subID, IRenderContextHandler handler)
{
Integer texID = textures.get(texture);
if (texID == null)
{
texID = ModLoader.getMinecraftInstance().renderEngine.getTexture(texture);
texID = engine().getTexture(texture);
textures.put(texture, texID);
}
renderHandlers.put(new TesKey(texID, subID), handler);
}
static RenderEngine engine()
{
return FMLClientHandler.instance().getClient().renderEngine;
}
public static void bindTexture(String texture, int subID)
{
Integer texID = textures.get(texture);
if (texID == null)
{
texID = ModLoader.getMinecraftInstance().renderEngine.getTexture(texture);
texID = engine().getTexture(texture);
textures.put(texture, texID);
}
if (!inWorld)
@ -132,11 +137,11 @@ public class ForgeHooksClient
}
Tessellator.instance.startDrawing(mode);
}
GL11.glBindTexture(GL11.GL_TEXTURE_2D, ModLoader.getMinecraftInstance().renderEngine.getTexture("/terrain.png"));
GL11.glBindTexture(GL11.GL_TEXTURE_2D, engine().getTexture("/terrain.png"));
return;
}
}
protected static void bindTessellator(int texture, int subID)
{
TesKey key = new TesKey(texture, subID);
@ -158,14 +163,14 @@ public class ForgeHooksClient
Tessellator.instance = tess;
}
static int renderPass = -1;
public static void beforeRenderPass(int pass)
{
renderPass = pass;
defaultTessellator = Tessellator.instance;
Tessellator.renderingWorldRenderer = true;
GL11.glBindTexture(GL11.GL_TEXTURE_2D, ModLoader.getMinecraftInstance().renderEngine.getTexture("/terrain.png"));
GL11.glBindTexture(GL11.GL_TEXTURE_2D, engine().getTexture("/terrain.png"));
renderTextures.clear();
inWorld = true;
}
@ -191,7 +196,7 @@ public class ForgeHooksClient
handler.afterRenderContext();
}
}
GL11.glBindTexture(GL11.GL_TEXTURE_2D, ModLoader.getMinecraftInstance().renderEngine.getTexture("/terrain.png"));
GL11.glBindTexture(GL11.GL_TEXTURE_2D, engine().getTexture("/terrain.png"));
Tessellator.renderingWorldRenderer = false;
Tessellator.instance = defaultTessellator;
}
@ -211,7 +216,7 @@ public class ForgeHooksClient
unbindTexture();
}
}
public static String getArmorTexture(ItemStack armor, String _default)
{
if (armor.getItem() instanceof IArmorTextureProvider)
@ -248,7 +253,7 @@ public class ForgeHooksClient
GL11.glScalef(scale, scale, scale);
int size = entity.item.stackSize;
int count = (size > 20 ? 4 : (size > 5 ? 3 : (size > 1 ? 2 : 1)));
for(int j = 0; j < size; j++)
{
GL11.glPushMatrix();
@ -271,7 +276,7 @@ public class ForgeHooksClient
}
return true;
}
public static boolean renderInventoryItem(RenderBlocks renderBlocks, RenderEngine engine, ItemStack item, boolean inColor, float zLevel, float x, float y)
{
IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item, INVENTORY);
@ -327,7 +332,7 @@ public class ForgeHooksClient
}
return true;
}
public static void renderEquippedItem(IItemRenderer customRenderer, RenderBlocks renderBlocks, EntityLiving entity, ItemStack item)
{
if (customRenderer.shouldUseRenderHelper(EQUIPPED, item, EQUIPPED_BLOCK))
@ -398,7 +403,7 @@ public class ForgeHooksClient
{
if (Tessellator.class.getPackage().equals("net.minecraft.src"))
{
Minecraft mc = ModLoader.getMinecraftInstance();
Minecraft mc = FMLClientHandler.instance().getClient();
if (mc.ingameGUI != null)
{
mc.ingameGUI.getChatGUI().printChatMessage(msg);

View file

@ -11,7 +11,6 @@ import net.minecraft.src.Block;
import net.minecraft.src.Entity;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.ModLoader;
import net.minecraft.src.RenderBlocks;
import net.minecraft.src.World;
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
@ -33,13 +32,13 @@ public class MinecraftForgeClient
ForgeHooksClient.registerRenderContextHandler(texture, subid, handler);
}
/**
/**
* 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);
ForgeHooksClient.engine().getTexture(texture);
}
/** Render a block. Render a block which may have a custom texture.
@ -51,17 +50,17 @@ public class MinecraftForgeClient
ForgeHooksClient.afterBlockRender(block, render);
}
/**
/**
* Get the current render pass.
*/
public static int getRenderPass()
{
return ForgeHooksClient.renderPass;
}
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.
@ -77,7 +76,7 @@ public class MinecraftForgeClient
public static IItemRenderer getItemRenderer(ItemStack item, ItemRenderType type)
{
IItemRenderer renderer = customItemRenderers[item.itemID];
if (renderer != null && renderer.handleRenderType(item, type))
if (renderer != null && renderer.handleRenderType(item, type))
{
return customItemRenderers[item.itemID];
}

View file

@ -3,6 +3,10 @@ package net.minecraftforge.client;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.logging.Level;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLLog;
import paulscode.sound.SoundSystemConfig;
import paulscode.sound.codecs.CodecIBXM;
@ -10,19 +14,19 @@ import paulscode.sound.codecs.CodecIBXM;
import net.minecraft.client.Minecraft;
import net.minecraft.src.*;
public class ModCompatibilityClient
public class ModCompatibilityClient
{
/**
* Trys to get the class for the specified name, will also try the
* Trys to get the class for the specified name, will also try the
* net.minecraft.src package in case we are in MCP
* Returns null if not found.
*
*
* @param name The class name
* @return The Class, or null if not found
*/
private static Class getClass(String name)
{
try
try
{
return Class.forName(name);
}
@ -38,23 +42,23 @@ public class ModCompatibilityClient
}
}
}
/************************************************************************************************
* Risugami's AudioMod Compatibility
* http://www.minecraftforum.net/topic/75440-
*
*
* AudioMod adds a few extra codecs, loads audio from /resources/mods/*,
* introduces the concept of 'cave' sounds, which are determined by if
* introduces the concept of 'cave' sounds, which are determined by if
* the player is underneath a solid block.
*
*
* It also lowers the interval between background music songs to 6000
*/
public static SoundPool audioModSoundPoolCave;
/**
* Populates the sound pools with with sounds from the /resources/mods folder
* And sets the interval between background music to 6000
*
*
* @param mngr The SoundManager instance
*/
public static void audioModLoad(SoundManager mngr)
@ -64,13 +68,13 @@ public class ModCompatibilityClient
audioModLoadModAudio("resources/mod/streaming", mngr.soundPoolStreaming);
audioModLoadModAudio("resources/mod/music", mngr.soundPoolMusic);
audioModLoadModAudio("resources/mod/cavemusic", audioModSoundPoolCave);
if (mngr.MUSIC_INTERVAL == 12000)
{
mngr.MUSIC_INTERVAL = 6000;
}
}
/**
* Walks the given path in the Minecraft app directory and adds audio to the SoundPool
* @param path The path to walk
@ -86,15 +90,14 @@ public class ModCompatibilityClient
}
catch (IOException ex)
{
ModLoader.getLogger().fine("Loading Mod audio failed for folder: " + path);
ModLoader.getLogger().fine(ex.toString());
FMLLog.log(Level.FINE, ex, "Loading Mod audio failed for folder: %s", path);
ex.printStackTrace();
}
}
/**
* Walks the folder path recursively and calls pool.addSound on any file it finds.
*
*
* @param base The base path for the folder, determines the name when calling addSound
* @param folder The current folder
* @param pool The SoundPool to add the sound to
@ -105,7 +108,7 @@ public class ModCompatibilityClient
if (folder.exists() || folder.mkdirs())
{
for (File file : folder.listFiles())
{
{
if (!file.getName().startsWith("."))
{
if (file.isDirectory())
@ -125,7 +128,7 @@ public class ModCompatibilityClient
/**
* Adds the IBXM codec and associates it with .xm, .s3m, and .mod
*/
public static void audioModAddCodecs()
public static void audioModAddCodecs()
{
SoundSystemConfig.setCodec("xm", CodecIBXM.class);
SoundSystemConfig.setCodec("s3m", CodecIBXM.class);
@ -135,14 +138,14 @@ public class ModCompatibilityClient
/**
* If the current player is underground, it picks a random song from the cave sound pool,
* if they are not it returns the passed in entry.
*
*
* @param soundManager The SoundManager instance
* @param current The currently selected entry
* @return A soundPool entry to be played as the background music
*/
public static SoundPoolEntry audioModPickBackgroundMusic(SoundManager soundManager, SoundPoolEntry current)
public static SoundPoolEntry audioModPickBackgroundMusic(SoundManager soundManager, SoundPoolEntry current)
{
Minecraft mc = ModLoader.getMinecraftInstance();
Minecraft mc = FMLClientHandler.instance().getClient();
if (mc != null && mc.theWorld != null && audioModSoundPoolCave != null)
{
Entity ent = mc.renderViewEntity;
@ -153,19 +156,19 @@ public class ModCompatibilityClient
}
return current;
}
/***********************************************************************************************************
* SDK's ModLoaderMP
* http://www.minecraftforum.net/topic/86765-
*
* ModLoaderMP was supposed to be a reliable server side version of ModLoader, however it has
*
* ModLoaderMP was supposed to be a reliable server side version of ModLoader, however it has
* gotten the reputation of being really slow to update. Never having bugfixes, breaking compatibility
* with the client side ModLoader.
*
*
* So we have replaced it with our own system called FML (Forge ModLoader)
* it is a stand alone mod, that Forge relies on, and that is open source/community driven.
* https://github.com/cpw/FML
*
*
* However, for compatibilities sake, we provide the ModLoaderMP's hooks so that the end user
* does not need to make a choice between the two on the client side.
**/
@ -185,9 +188,9 @@ public class ModCompatibilityClient
}
/**
* Attempts to spawn a vehicle using ModLoaderMP's vehicle spawn registry, if MLMP is not installed
* Attempts to spawn a vehicle using ModLoaderMP's vehicle spawn registry, if MLMP is not installed
* it returns the passed in currentEntity
*
*
* @param type The Type ID of the vehicle
* @param world The current world
* @param x The spawn X position
@ -200,18 +203,18 @@ public class ModCompatibilityClient
*/
public static Object mlmpVehicleSpawn(int type, World world, double x, double y, double z, Entity thrower, Object currentEntity) throws Exception
{
Class mlmp = getClass("ModLoaderMp");
Class mlmp = getClass("ModLoaderMp");
if (!isMLMPInstalled() || mlmp == null)
{
return currentEntity;
}
Object entry = mlmp.getDeclaredMethod("handleNetClientHandlerEntities", int.class).invoke(null, type);
if (entry == null)
{
return currentEntity;
}
Class entityClass = (Class)entry.getClass().getDeclaredField("entityClass").get(entry);
Object ret = (Entity)entityClass.getConstructor(World.class, Double.TYPE, Double.TYPE, Double.TYPE).newInstance(world, x, y, z);
@ -227,7 +230,7 @@ public class ModCompatibilityClient
if (thrower == null)
{
System.out.println("Received spawn packet for entity with owner, but owner was not found.");
ModLoader.getLogger().fine("Received spawn packet for entity with owner, but owner was not found.");
FMLLog.fine("Received spawn packet for entity with owner, but owner was not found.");
}
else
{
@ -241,26 +244,26 @@ public class ModCompatibilityClient
}
return ret;
}
/**
* Attempts to invoke ModLoaderMp.handleGUI if ModLoaderMP is installed.
* If not, it does nothing
*
*
* @param pkt The open window packet
*/
public static void mlmpOpenWindow(Packet100OpenWindow pkt)
public static void mlmpOpenWindow(Packet100OpenWindow pkt)
{
Class mlmp = getClass("ModLoaderMp");
Class mlmp = getClass("ModLoaderMp");
if (!isMLMPInstalled() || mlmp == null)
{
return;
}
try
try
{
mlmp.getDeclaredMethod("handleGUI", Packet100OpenWindow.class).invoke(null, pkt);
}
catch (Exception e)
}
catch (Exception e)
{
e.printStackTrace();
}

View file

@ -2,6 +2,8 @@ package net.minecraftforge.common;
import java.util.*;
import cpw.mods.fml.common.FMLLog;
import net.minecraft.src.*;
import net.minecraftforge.event.entity.living.*;
import net.minecraftforge.event.entity.living.LivingEvent.*;
@ -19,7 +21,7 @@ public class ForgeHooks
this.metadata = meta;
}
}
static class SeedEntry extends WeightedRandomItem
{
public final ItemStack seed;
@ -31,7 +33,7 @@ public class ForgeHooks
}
static final List<GrassEntry> grassList = new ArrayList<GrassEntry>();
static final List<SeedEntry> seedList = new ArrayList<SeedEntry>();
public static void plantGrass(World world, int x, int y, int z)
{
GrassEntry grass = (GrassEntry)WeightedRandom.getRandomItem(world.rand, grassList);
@ -51,12 +53,12 @@ public class ForgeHooks
}
return entry.seed.copy();
}
private static boolean toolInit = false;
static HashMap<Item, List> toolClasses = new HashMap<Item, List>();
static HashMap<List, Integer> toolHarvestLevels = new HashMap<List, Integer>();
static HashSet<List> toolEffectiveness = new HashSet<List>();
public static boolean canHarvestBlock(Block block, EntityPlayer player, int metadata)
{
if (block.blockMaterial.isHarvestable())
@ -121,7 +123,7 @@ public class ForgeHooks
}
return toolEffectiveness.contains(Arrays.asList(block, metadata, (String)toolClass.get(0)));
}
static void initTools()
{
if (toolInit)
@ -213,7 +215,7 @@ public class ForgeHooks
}
return ret;
}
static
{
grassList.add(new GrassEntry(Block.plantYellow, 0, 20));
@ -221,7 +223,7 @@ public class ForgeHooks
seedList.add(new SeedEntry(new ItemStack(Item.seeds), 10));
initTools();
System.out.printf("MinecraftForge v%s Initialized\n", ForgeVersion.getVersion());
ModLoader.getLogger().info(String.format("MinecraftForge v%s Initialized", ForgeVersion.getVersion()));
FMLLog.info("MinecraftForge v%s Initialized", ForgeVersion.getVersion());
}
/**