Skip to content

Commit

Permalink
Some small code cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
LexManos committed Jan 2, 2013
1 parent c96b923 commit 1705859
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 260 deletions.
2 changes: 1 addition & 1 deletion client/net/minecraftforge/client/ForgeHooksClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public static void onTextureLoadPre(String texture)
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)
Expand Down
9 changes: 6 additions & 3 deletions common/net/minecraftforge/common/DimensionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -61,6 +61,9 @@ public static void init()
{
return;
}

hasInit = true;

registerProviderType( 0, WorldProviderSurface.class, true);
registerProviderType(-1, WorldProviderHell.class, true);
registerProviderType( 1, WorldProviderEnd.class, false);
Expand Down Expand Up @@ -147,7 +150,7 @@ public static void setWorld(int id, WorldServer world)
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) {
Expand Down Expand Up @@ -183,7 +186,7 @@ public static WorldServer getWorld(int id)

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)
Expand Down
6 changes: 1 addition & 5 deletions common/net/minecraftforge/common/DungeonHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ public DungeonMob(int weight, String type)
@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);
}
}

Expand Down
16 changes: 6 additions & 10 deletions common/net/minecraftforge/common/ForgeHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static boolean canHarvestBlock(Block block, EntityPlayer player, int meta
return player.canHarvestBlock(block);
}

List info = (List)toolClasses.get(stack.getItem());
List info = toolClasses.get(stack.getItem());
if (info == null)
{
return player.canHarvestBlock(block);
Expand All @@ -104,7 +104,7 @@ public static boolean canHarvestBlock(Block block, EntityPlayer player, int meta
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);
Expand All @@ -120,14 +120,14 @@ public static boolean canHarvestBlock(Block block, EntityPlayer player, int meta
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);
}

Expand All @@ -153,12 +153,8 @@ public static float blockStrength(Block block, EntityPlayer player, World world,

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()
Expand Down
2 changes: 1 addition & 1 deletion common/net/minecraftforge/common/ForgeInternalHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void onEntityJoinWorld(EntityJoinWorldEvent event)
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)
{
Expand Down
4 changes: 2 additions & 2 deletions common/net/minecraftforge/common/ISpecialArmor.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ else if (stack.getItem() instanceof ItemArmor && !source.isUnblockable())
}
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;
Expand Down Expand Up @@ -262,7 +262,7 @@ private static void StandardizeList(ArmorProperties[] armor, double damage)
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;
}
Expand Down
13 changes: 3 additions & 10 deletions common/net/minecraftforge/common/MinecraftForge.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,8 @@ public static int getBlockHarvestLevel(Block block, int metadata, String toolCla
{
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);
}

/**
Expand Down Expand Up @@ -200,10 +196,7 @@ public static void initialize()
}

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);
Expand Down
2 changes: 1 addition & 1 deletion common/net/minecraftforge/event/ListenerList.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private void buildCache()
{
ret.addAll(getListeners(value));
}
listeners = ret.toArray(new IEventListener[0]);
listeners = ret.toArray(new IEventListener[ret.size()]);
rebuild = false;
}

Expand Down
107 changes: 50 additions & 57 deletions common/net/minecraftforge/liquids/LiquidContainerRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
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);

Expand All @@ -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)));
Expand All @@ -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()));
Expand All @@ -47,92 +48,84 @@ public static void registerLiquid(LiquidContainerData data) {
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;
}

public static boolean isBucket(ItemStack container) {
return ret != null && ret.stillLiquid.isLiquidEqual(liquid);
}

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()]);
}
}
Loading

0 comments on commit 1705859

Please sign in to comment.