Some small code cleanups.

This commit is contained in:
LexManos committed 2013-01-01 20:57:45 -08:00
1 parent c96b923e1c
commit 170585960b
13 files changed
+230 -249

No files matched your search

@@ -402,7 +402,7 @@ public class ForgeHooksClient
System.out.println(msg);
if (Tessellator.class.getPackage() != null)
{
if (Tessellator.class.getPackage().equals("net.minecraft.src"))
if (Tessellator.class.getPackage().getName().startsWith("net.minecraft."))
{
Minecraft mc = FMLClientHandler.instance().getClient();
if (mc.ingameGUI != null)
@@ -46,7 +46,7 @@ public class DimensionManager
public static boolean registerProviderType(int id, Class<? extends WorldProvider> provider, boolean keepLoaded)
{
if (providers.containsValue(id))
if (providers.containsKey(id))
{
return false;
}
@@ -61,6 +61,9 @@ public class DimensionManager
{
return;
}
hasInit = true;
registerProviderType( 0, WorldProviderSurface.class, true);
registerProviderType(-1, WorldProviderHell.class, true);
registerProviderType( 1, WorldProviderEnd.class, false);
@@ -147,7 +150,7 @@ public class DimensionManager
tmp.add(entry.getValue());
}
MinecraftServer.getServer().worldServers = tmp.toArray(new WorldServer[0]);
MinecraftServer.getServer().worldServers = tmp.toArray(new WorldServer[tmp.size()]);
}
public static void initDimension(int dim) {
@@ -183,7 +186,7 @@ public class DimensionManager
public static WorldServer[] getWorlds()
{
return worlds.values().toArray(new WorldServer[0]);
return worlds.values().toArray(new WorldServer[worlds.size()]);
}
public static boolean shouldLoadSpawn(int dim)
@@ -95,11 +95,7 @@ public class DungeonHooks
@Override
public boolean equals(Object target)
{
if (target instanceof DungeonMob)
{
return this.type.equals(((DungeonMob)target).type);
}
return false;
return target instanceof DungeonMob && type.equals(((DungeonMob)target).type);
}
}
@@ -94,7 +94,7 @@ public class ForgeHooks
return player.canHarvestBlock(block);
}
List info = (List)toolClasses.get(stack.getItem());
List info = toolClasses.get(stack.getItem());
if (info == null)
{
return player.canHarvestBlock(block);
@@ -104,7 +104,7 @@ public class ForgeHooks
String toolClass = (String)tmp[0];
int harvestLevel = (Integer)tmp[1];
Integer blockHarvestLevel = (Integer)toolHarvestLevels.get(Arrays.asList(block, metadata, toolClass));
Integer blockHarvestLevel = toolHarvestLevels.get(Arrays.asList(block, metadata, toolClass));
if (blockHarvestLevel == null)
{
return player.canHarvestBlock(block);
@@ -120,14 +120,14 @@ public class ForgeHooks
public static boolean canToolHarvestBlock(Block block, int metadata, ItemStack stack)
{
if (stack == null) return false;
List info = (List)toolClasses.get(stack.getItem());
List info = toolClasses.get(stack.getItem());
if (info == null) return false;
Object[] tmp = info.toArray();
String toolClass = (String)tmp[0];
int harvestLevel = (Integer)tmp[1];
Integer blockHarvestLevel = (Integer)toolHarvestLevels.get(Arrays.asList(block, metadata, toolClass));
Integer blockHarvestLevel = toolHarvestLevels.get(Arrays.asList(block, metadata, toolClass));
return !(blockHarvestLevel == null || blockHarvestLevel > harvestLevel);
}
@@ -153,12 +153,8 @@ public class ForgeHooks
public static boolean isToolEffective(ItemStack stack, Block block, int metadata)
{
List toolClass = (List)toolClasses.get(stack.getItem());
if (toolClass == null)
{
return false;
}
return toolEffectiveness.contains(Arrays.asList(block, metadata, (String)toolClass.get(0)));
List toolClass = toolClasses.get(stack.getItem());
return toolClass != null && toolEffectiveness.contains(Arrays.asList(block, metadata, toolClass.get(0)));
}
static void initTools()
@@ -32,7 +32,7 @@ public class ForgeInternalHandler
Entity entity = event.entity;
if (entity.getClass().equals(EntityItem.class))
{
ItemStack stack = ((EntityItem)entity).getDataWatcher().getWatchableObjectItemStack(10);
ItemStack stack = entity.getDataWatcher().getWatchableObjectItemStack(10);
if (stack == null)
{
@@ -124,7 +124,7 @@ public interface ISpecialArmor
}
if (dmgVals.size() > 0)
{
ArmorProperties[] props = dmgVals.toArray(new ArmorProperties[0]);
ArmorProperties[] props = dmgVals.toArray(new ArmorProperties[dmgVals.size()]);
StandardizeList(props, damage);
int level = props[0].Priority;
double ratio = 0;
@@ -262,7 +262,7 @@ public interface ISpecialArmor
total -= armor[y].AbsorbRatio;
if (damage * armor[y].AbsorbRatio > armor[y].AbsorbMax)
{
armor[y].AbsorbRatio = (double)armor[y].AbsorbMax / (double)damage;
armor[y].AbsorbRatio = (double)armor[y].AbsorbMax / damage;
}
total += armor[y].AbsorbRatio;
}
@@ -150,12 +150,8 @@ public class MinecraftForge
{
ForgeHooks.initTools();
List key = Arrays.asList(block, metadata, toolClass);
Integer harvestLevel = (Integer)ForgeHooks.toolHarvestLevels.get(key);
if(harvestLevel == null)
{
return -1;
}
return harvestLevel;
Integer harvestLevel = ForgeHooks.toolHarvestLevels.get(key);
return (harvestLevel == null ? -1 : harvestLevel);
}
/**
@@ -200,10 +196,7 @@ public class MinecraftForge
}
boolean[] temp = new boolean[4096];
for (int x = 0; x < EntityEnderman.carriableBlocks.length; x++)
{
temp[x] = EntityEnderman.carriableBlocks[x];
}
System.arraycopy(EntityEnderman.carriableBlocks, 0, temp, 0, EntityEnderman.carriableBlocks.length);
EntityEnderman.carriableBlocks = temp;
EVENT_BUS.register(INTERNAL_HANDLER);
@@ -195,7 +195,7 @@ public class ListenerList
{
ret.addAll(getListeners(value));
}
listeners = ret.toArray(new IEventListener[0]);
listeners = ret.toArray(new IEventListener[ret.size()]);
rebuild = false;
}
@@ -13,8 +13,8 @@ import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class LiquidContainerRegistry {
public class LiquidContainerRegistry
{
public static final int BUCKET_VOLUME = 1000;
public static final ItemStack EMPTY_BUCKET = new ItemStack(Item.bucketEmpty);
@@ -27,7 +27,8 @@ public class LiquidContainerRegistry {
/**
* Default registrations
*/
static {
static
{
registerLiquid(new LiquidContainerData(new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack(Item.bucketWater), new ItemStack(Item.bucketEmpty)));
registerLiquid(new LiquidContainerData(new LiquidStack(Block.lavaStill, LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack(Item.bucketLava), new ItemStack(Item.bucketEmpty)));
registerLiquid(new LiquidContainerData(new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack(Item.potion), new ItemStack(Item.glassBottle)));
@@ -37,8 +38,8 @@ public class LiquidContainerRegistry {
/**
* To register a container with a non-bucket size, the LiquidContainerData entry simply needs to use a size other than LiquidManager.BUCKET_VOLUME
*/
public static void registerLiquid(LiquidContainerData data) {
public static void registerLiquid(LiquidContainerData data)
{
mapFilledItemFromLiquid.put(Arrays.asList(data.container.itemID, data.container.getItemDamage(), data.stillLiquid.itemID, data.stillLiquid.itemMeta), data);
mapLiquidFromFilledItem.put(Arrays.asList(data.filled.itemID, data.filled.getItemDamage()), data);
setContainerValidation.add(Arrays.asList(data.container.itemID, data.container.getItemDamage()));
@@ -47,92 +48,84 @@ public class LiquidContainerRegistry {
liquids.add(data);
}
public static LiquidStack getLiquidForFilledItem(ItemStack filledContainer) {
if (filledContainer == null) {
public static LiquidStack getLiquidForFilledItem(ItemStack filledContainer)
{
if (filledContainer == null)
{
return null;
}
LiquidContainerData ret = mapLiquidFromFilledItem.get(Arrays.asList(filledContainer.itemID, filledContainer.getItemDamage()));
if (ret != null) {
return ret.stillLiquid.copy();
}
return null;
return ret == null ? null : ret.stillLiquid.copy();
}
public static ItemStack fillLiquidContainer(LiquidStack liquid, ItemStack emptyContainer) {
if (emptyContainer == null || liquid == null) {
public static ItemStack fillLiquidContainer(LiquidStack liquid, ItemStack emptyContainer)
{
if (emptyContainer == null || liquid == null)
{
return null;
}
LiquidContainerData ret = mapFilledItemFromLiquid.get(Arrays.asList(emptyContainer.itemID, emptyContainer.getItemDamage(), liquid.itemID, liquid.itemMeta));
if (ret != null) {
if (liquid.amount >= ret.stillLiquid.amount) {
return ret.filled.copy();
}
if (ret != null && liquid.amount >= ret.stillLiquid.amount)
{
return ret.filled.copy();
}
return null;
}
public static boolean containsLiquid(ItemStack filledContainer, LiquidStack liquid) {
if (filledContainer == null || liquid == null) {
public static boolean containsLiquid(ItemStack filledContainer, LiquidStack liquid)
{
if (filledContainer == null || liquid == null)
{
return false;
}
LiquidContainerData ret = mapLiquidFromFilledItem.get(Arrays.asList(filledContainer.itemID, filledContainer.getItemDamage()));
if (ret != null) {
return ret.stillLiquid.isLiquidEqual(liquid);
}
return false;
return ret != null && ret.stillLiquid.isLiquidEqual(liquid);
}
public static boolean isBucket(ItemStack container) {
if (container == null) {
public static boolean isBucket(ItemStack container)
{
if (container == null)
{
return false;
}
if (container.isItemEqual(EMPTY_BUCKET)) {
if (container.isItemEqual(EMPTY_BUCKET))
{
return true;
}
LiquidContainerData ret = mapLiquidFromFilledItem.get(Arrays.asList(container.itemID, container.getItemDamage()));
if (ret != null) {
return ret.container.isItemEqual(EMPTY_BUCKET);
}
return false;
return ret != null && ret.container.isItemEqual(EMPTY_BUCKET);
}
public static boolean isContainer(ItemStack container) {
public static boolean isContainer(ItemStack container)
{
return isEmptyContainer(container) || isFilledContainer(container);
}
public static boolean isEmptyContainer(ItemStack emptyContainer) {
if (emptyContainer == null) {
return false;
}
return setContainerValidation.contains(Arrays.asList(emptyContainer.itemID, emptyContainer.getItemDamage()));
public static boolean isEmptyContainer(ItemStack emptyContainer)
{
return emptyContainer != null && setContainerValidation.contains(Arrays.asList(emptyContainer.itemID, emptyContainer.getItemDamage()));
}
public static boolean isFilledContainer(ItemStack filledContainer) {
if (filledContainer == null) {
return false;
}
return getLiquidForFilledItem(filledContainer) != null;
public static boolean isFilledContainer(ItemStack filledContainer)
{
return filledContainer != null && getLiquidForFilledItem(filledContainer) != null;
}
public static boolean isLiquid(ItemStack item) {
if (item == null) {
return false;
}
return setLiquidValidation.contains(Arrays.asList(item.itemID, item.getItemDamage()));
public static boolean isLiquid(ItemStack item)
{
return item != null && setLiquidValidation.contains(Arrays.asList(item.itemID, item.getItemDamage()));
}
public static LiquidContainerData[] getRegisteredLiquidContainerData() {
return liquids.toArray(new LiquidContainerData[0]);
public static LiquidContainerData[] getRegisteredLiquidContainerData()
{
return liquids.toArray(new LiquidContainerData[liquids.size()]);
}
}
@@ -6,82 +6,91 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event;
public class LiquidEvent extends Event {
public final LiquidStack liquid;
public final int x;
public final int y;
public final int z;
public final World world;
public final LiquidStack liquid;
public final int x;
public final int y;
public final int z;
public final World world;
public LiquidEvent(LiquidStack liquid, World world, int x, int y, int z)
{
this.liquid = liquid;
this.world = world;
this.x = x;
this.y = y;
this.z = z;
}
public LiquidEvent(LiquidStack liquid, World world, int x, int y, int z)
{
this.liquid = liquid;
this.world = world;
this.x = x;
this.y = y;
this.z = z;
}
/**
* Mods should fire this event when they move liquids around (pipe networks etc)
*
* @author cpw
*
*/
public static class LiquidMotionEvent extends LiquidEvent {
public LiquidMotionEvent(LiquidStack liquid, World world, int x, int y, int z) {
super(liquid, world, x, y, z);
}
}
/**
* Mods should fire this event when they move liquids around (pipe networks etc)
*
* @author cpw
*
*/
public static class LiquidMotionEvent extends LiquidEvent
{
public LiquidMotionEvent(LiquidStack liquid, World world, int x, int y, int z)
{
super(liquid, world, x, y, z);
}
}
/**
* Mods should fire this event when a liquid is {@link ILiquidTank#fill(LiquidStack, boolean)} their tank implementation.
* {@link LiquidTank} does.
*
* @author cpw
*
*/
public static class LiquidFillingEvent extends LiquidEvent {
public final ILiquidTank tank;
/**
* Mods should fire this event when a liquid is {@link ILiquidTank#fill(LiquidStack, boolean)} their tank implementation.
* {@link LiquidTank} does.
*
* @author cpw
*
*/
public static class LiquidFillingEvent extends LiquidEvent
{
public final ILiquidTank tank;
public LiquidFillingEvent(LiquidStack liquid, World world, int x, int y, int z, ILiquidTank tank) {
super(liquid, world, x, y, z);
this.tank = tank;
}
}
public LiquidFillingEvent(LiquidStack liquid, World world, int x, int y, int z, ILiquidTank tank)
{
super(liquid, world, x, y, z);
this.tank = tank;
}
}
/**
* Mods should fire this event when a liquid is {@link ILiquidTank#drain(int, boolean)} from their tank.
* @author cpw
*
*/
public static class LiquidDrainingEvent extends LiquidEvent {
public final ILiquidTank tank;
/**
* Mods should fire this event when a liquid is {@link ILiquidTank#drain(int, boolean)} from their tank.
* @author cpw
*
*/
public static class LiquidDrainingEvent extends LiquidEvent
{
public final ILiquidTank tank;
public LiquidDrainingEvent(LiquidStack liquid, World world, int x, int y, int z, ILiquidTank tank) {
super(liquid, world, x, y, z);
this.tank = tank;
}
}
public LiquidDrainingEvent(LiquidStack liquid, World world, int x, int y, int z, ILiquidTank tank)
{
super(liquid, world, x, y, z);
this.tank = tank;
}
}
/**
* Mods should fire this event when a liquid "spills", for example, if a block containing liquid is broken.
*
* @author cpw
*
*/
public static class LiquidSpilledEvent extends LiquidEvent {
public LiquidSpilledEvent(LiquidStack liquid, World world, int x, int y, int z) {
super(liquid, world, x, y, z);
}
}
/**
* Mods should fire this event when a liquid "spills", for example, if a block containing liquid is broken.
*
* @author cpw
*
*/
public static class LiquidSpilledEvent extends LiquidEvent
{
public LiquidSpilledEvent(LiquidStack liquid, World world, int x, int y, int z)
{
super(liquid, world, x, y, z);
}
}
/**
* A handy shortcut for firing the various liquid events
*
* @param event
*/
public static final void fireEvent(LiquidEvent event) {
MinecraftForge.EVENT_BUS.post(event);
}
/**
* A handy shortcut for firing the various liquid events
*
* @param event
*/
public static final void fireEvent(LiquidEvent event)
{
MinecraftForge.EVENT_BUS.post(event);
}
}
@@ -9,101 +9,93 @@ import net.minecraft.nbt.NBTTagCompound;
* ItemStack substitute for liquids
* @author SirSengir
*/
public class LiquidStack {
public int itemID;
public int amount;
public int itemMeta;
public class LiquidStack
{
public int itemID;
public int amount;
public int itemMeta;
private LiquidStack() {
}
private LiquidStack(){}
public LiquidStack(int itemID, int amount) {
this(itemID, amount, 0);
}
public LiquidStack(int itemID, int amount) { this(itemID, amount, 0); }
public LiquidStack(Item item, int amount) { this(item.itemID, amount, 0); }
public LiquidStack(Block block, int amount) { this(block.blockID, amount, 0); }
public LiquidStack(Item item, int amount) {
this(item.itemID, amount, 0);
}
public LiquidStack(int itemID, int amount, int itemDamage)
{
this.itemID = itemID;
this.amount = amount;
this.itemMeta = itemDamage;
}
public LiquidStack(Block block, int amount) {
this(block.blockID, amount, 0);
}
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
nbt.setShort("Id", (short)itemID);
nbt.setInteger("Amount", amount);
nbt.setShort("Meta", (short)itemMeta);
return nbt;
}
public LiquidStack(int itemID, int amount, int itemDamage) {
this.itemID = itemID;
this.amount = amount;
this.itemMeta = itemDamage;
}
public void readFromNBT(NBTTagCompound nbt)
{
itemID = nbt.getShort("Id");
amount = nbt.getInteger("Amount");
itemMeta = nbt.getShort("Meta");
}
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setShort("Id", (short) itemID);
nbttagcompound.setInteger("Amount", amount);
nbttagcompound.setShort("Meta", (short) itemMeta);
return nbttagcompound;
}
/**
* @return A copy of this LiquidStack
*/
public LiquidStack copy()
{
return new LiquidStack(itemID, amount, itemMeta);
}
public void readFromNBT(NBTTagCompound nbttagcompound) {
itemID = nbttagcompound.getShort("Id");
amount = nbttagcompound.getInteger("Amount");
itemMeta = nbttagcompound.getShort("Meta");
}
/**
* @param other
* @return true if this LiquidStack contains the same liquid as the one passed in.
*/
public boolean isLiquidEqual(LiquidStack other)
{
return other != null && itemID == other.itemID && itemMeta == other.itemMeta;
}
/**
* @return A copy of this LiquidStack
*/
public LiquidStack copy() {
return new LiquidStack(itemID, amount, itemMeta);
}
/**
* @param other
* @return true if this LiquidStack contains the other liquid (liquids are equal and amount >= other.amount).
*/
public boolean containsLiquid(LiquidStack other)
{
return isLiquidEqual(other) && amount >= other.amount;
}
/**
* @param other
* @return true if this LiquidStack contains the same liquid as the one passed in.
*/
public boolean isLiquidEqual(LiquidStack other) {
if(other == null)
return false;
/**
* @param other ItemStack containing liquids.
* @return true if this LiquidStack contains the same liquid as the one passed in.
*/
public boolean isLiquidEqual(ItemStack other)
{
return other != null && itemID == other.itemID && itemMeta == other.getItemDamage();
}
return itemID == other.itemID && itemMeta == other.itemMeta;
}
/**
* @return ItemStack representation of this LiquidStack
*/
public ItemStack asItemStack()
{
return new ItemStack(itemID, 1, itemMeta);
}
/**
* @param other
* @return true if this LiquidStack contains the other liquid (liquids are equal and amount >= other.amount).
*/
public boolean containsLiquid(LiquidStack other) {
if(!isLiquidEqual(other))
return false;
return amount >= other.amount;
}
/**
* @param other ItemStack containing liquids.
* @return true if this LiquidStack contains the same liquid as the one passed in.
*/
public boolean isLiquidEqual(ItemStack other) {
if(other == null)
return false;
return itemID == other.itemID && itemMeta == other.getItemDamage();
}
/**
* @return ItemStack representation of this LiquidStack
*/
public ItemStack asItemStack() {
return new ItemStack(itemID, 1, itemMeta);
}
/**
* Reads a liquid stack from the passed nbttagcompound and returns it.
*
* @param nbttagcompound
* @return
*/
public static LiquidStack loadLiquidStackFromNBT(NBTTagCompound nbttagcompound) {
LiquidStack liquidstack = new LiquidStack();
liquidstack.readFromNBT(nbttagcompound);
return liquidstack.itemID == 0 ? null : liquidstack;
}
/**
* Reads a liquid stack from the passed nbttagcompound and returns it.
*
* @param nbt
* @return
*/
public static LiquidStack loadLiquidStackFromNBT(NBTTagCompound nbt)
{
LiquidStack liquidstack = new LiquidStack();
liquidstack.readFromNBT(nbt);
return liquidstack.itemID == 0 ? null : liquidstack;
}
}
@@ -81,7 +81,7 @@ public class OreDictionary
}
hasInit = true;
ItemStack[] replaceStacks = replacements.keySet().toArray(new ItemStack[0]);
ItemStack[] replaceStacks = replacements.keySet().toArray(new ItemStack[replacements.keySet().size()]);
// Ignore recipes for the following items
ItemStack[] exclusions = new ItemStack[]
@@ -121,7 +121,7 @@ public class OreDictionary
continue;
}
if(containsMatch(true, (ItemStack[])recipe.recipeItems.toArray(new ItemStack[0]), replaceStacks))
if(containsMatch(true, (ItemStack[])recipe.recipeItems.toArray(new ItemStack[recipe.recipeItems.size()]), replaceStacks))
{
recipesToRemove.add((IRecipe)obj);
IRecipe newRecipe = new ShapelessOreRecipe(recipe, replacements);
@@ -217,7 +217,7 @@ public class OreDictionary
*/
public static String[] getOreNames()
{
return oreIDs.keySet().toArray(new String[0]);
return oreIDs.keySet().toArray(new String[oreIDs.keySet().size()]);
}
/**
@@ -87,7 +87,6 @@ public class ShapedOreRecipe implements IRecipe
{
Character chr = (Character)recipe[idx];
Object in = recipe[idx + 1];
Object val = null;
if (in instanceof ItemStack)
{