Separate sprite handling, fix worldtype

This commit is contained in:
Christian Weeks 2012-05-07 01:26:21 -04:00
parent b6b5955404
commit 56e7270dee
4 changed files with 184 additions and 110 deletions

View file

@ -0,0 +1,111 @@
/*
* The FML Forge Mod Loader suite.
* Copyright (C) 2012 cpw
*
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package cpw.mods.fml.client;
import java.util.BitSet;
import java.util.HashMap;
import net.minecraft.src.ModLoader;
import cpw.mods.fml.common.Loader;
/**
* @author cpw
*
*/
public class SpriteHelper
{
private static HashMap<String, BitSet> spriteInfo = new HashMap<String, BitSet>();
public static int getUniqueSpriteIndex(String path)
{
BitSet slots = spriteInfo.get(path);
if (slots == null)
{
if (path.equals("/terrain.png"))
{
slots = SpriteHelper.toBitSet(
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000011111100" +
"0000000011111111" +
"0000000011111000" +
"0000000111111100" +
"0000000111111000" +
"0000000000000000");
spriteInfo.put("/terrain.png", slots);
}
else if (path.equals("/gui/items.png"))
{
slots = SpriteHelper.toBitSet(
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000001000000000" +
"0000001110000000" +
"0000001000000000" +
"1111111010000000" +
"1111111010100000" +
"1111111111111100" +
"1111111111111111" +
"1111111111111111" +
"1111111111111111" +
"0000000000000000");
spriteInfo.put("/gui/items.png", slots);
}
else
{
Exception ex = new Exception(String.format("Invalid getUniqueSpriteIndex call for texture: %s", path));
Loader.log.throwing("ModLoader", "getUniqueSpriteIndex", ex);
ModLoader.throwException(ex);
return 0;
}
}
int ret = SpriteHelper.getFreeSlot(slots);
if (ret == -1)
{
Exception ex = new Exception(String.format("No more sprite indicies left for: %s", path));
Loader.log.throwing("ModLoader", "getUniqueSpriteIndex", ex);
ModLoader.throwException(ex);
}
return ret;
}
public static BitSet toBitSet(String data)
{
BitSet ret = new BitSet(data.length());
for (int x = 0; x < data.length(); x++)
{
ret.set(x, data.charAt(x) == '1');
}
return ret;
}
public static int getFreeSlot(BitSet slots)
{
return slots.nextSetBit(0);
}
}

View file

@ -24,6 +24,7 @@ import java.util.logging.Logger;
import net.minecraft.client.Minecraft;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.SpriteHelper;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer.TickType;
@ -39,7 +40,6 @@ public class ModLoader
public String override;
public int index;
}
private static HashMap<String, boolean[]> spriteInfo = new HashMap<String, boolean[]>();
private static HashMap<String, ArrayList<OverrideInfo>> overrideInfo = new HashMap<String, ArrayList<OverrideInfo>>();
/**
@ -72,11 +72,11 @@ public class ModLoader
return 0;
}
static void addAllRenderers(Map<Class<? extends Entity>, Render> renderers)
public static void addAllRenderers(Map<Class<? extends Entity>, Render> renderers)
{
}
static void addAnimation(TextureFX anim)
public static void addAnimation(TextureFX anim)
{
}
@ -169,7 +169,7 @@ public class ModLoader
*/
public static int addOverride(String fileToOverride, String fileToAdd)
{
int idx = getUniqueSpriteIndex(fileToOverride);
int idx = SpriteHelper.getUniqueSpriteIndex(fileToOverride);
addOverride(fileToOverride, fileToAdd, idx);
return idx;
}
@ -387,7 +387,7 @@ public class ModLoader
return FMLCommonHandler.instance().getFMLLogger();
}
static Minecraft getMinecraftInstance()
public static Minecraft getMinecraftInstance()
{
return FMLClientHandler.instance().getClient();
}
@ -453,93 +453,9 @@ public class ModLoader
public static int getUniqueSpriteIndex(String path)
{
boolean[] slots = spriteInfo.get(path);
if (slots == null)
{
if (path.equals("/terrain.png"))
{
slots = toBooleanArray(
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000011111100" +
"0000000011111111" +
"0000000011111000" +
"0000000111111100" +
"0000000111111000" +
"0000000000000000");
spriteInfo.put("/terrain.png", slots);
}
else if (path.equals("/gui/items.png"))
{
slots = toBooleanArray(
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000000000000000" +
"0000001000000000" +
"0000001110000000" +
"0000001000000000" +
"1111111010000000" +
"1111111010100000" +
"1111111111111100" +
"1111111111111111" +
"1111111111111111" +
"1111111111111111" +
"0000000000000000");
spriteInfo.put("/gui/items.png", slots);
}
else
{
Exception ex = new Exception(String.format("Invalid getUniqueSpriteIndex call for texture: %s", path));
Loader.log.throwing("ModLoader", "getUniqueSpriteIndex", ex);
throwException(ex);
return 0;
}
}
int ret = getFreeSlot(slots);
if (ret == -1)
{
Exception ex = new Exception(String.format("No more sprite indicies left for: %s", path));
Loader.log.throwing("ModLoader", "getUniqueSpriteIndex", ex);
throwException(ex);
return 0;
}
return ret;
return SpriteHelper.getUniqueSpriteIndex(path);
}
private static boolean[] toBooleanArray(String data)
{
boolean[] ret = new boolean[data.length()];
for (int x = 0; x < data.length(); x++)
{
ret[x] = data.charAt(x) == '1';
}
return ret;
}
private static int getFreeSlot(boolean[] slots)
{
for (int x = 0; x < slots.length; x++)
{
if (slots[x])
{
slots[x] = false;
return x;
}
}
return -1;
}
/**
* To properly implement packet 250 protocol you should always check your
* channel is active prior to sending the packet
@ -553,7 +469,7 @@ public class ModLoader
return FMLCommonHandler.instance().isChannelActive(channel, player);
}
static boolean isGUIOpen(Class<? extends GuiScreen> gui)
public static boolean isGUIOpen(Class<? extends GuiScreen> gui)
{
//TODO
return false;
@ -574,11 +490,11 @@ public class ModLoader
* Implemented elsewhere
*/
@Deprecated
static void loadConfig()
public static void loadConfig()
{
}
static BufferedImage loadImage(RenderEngine texCache, String path)
public static BufferedImage loadImage(RenderEngine texCache, String path)
{
//TODO
return null;
@ -590,16 +506,18 @@ public class ModLoader
* @param item
*/
@Deprecated
static void onItemPickup(EntityPlayer player, ItemStack item)
public static void onItemPickup(EntityPlayer player, ItemStack item)
{
}
/**
* Call in from elsewhere. Unimplemented here.
*/
@Deprecated
public static void onTick(float tick, Minecraft game)
{
}
static void onTick(float tick, Minecraft game)
{
//TODO
}
static void openGUI(EntityPlayer player, GuiScreen gui)
public static void openGUI(EntityPlayer player, GuiScreen gui)
{
//TODO
}

View file

@ -1,14 +1,55 @@
--- ../src-base/minecraft/net/minecraft/src/WorldType.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src-work/minecraft/net/minecraft/src/WorldType.java 0000-00-00 00:00:00.000000000 -0000
@@ -78,4 +78,11 @@
@@ -1,5 +1,8 @@
package net.minecraft.src;
+import java.util.Arrays;
+import java.util.List;
+
public class WorldType
{
public static final WorldType[] field_48637_a = new WorldType[16];
@@ -11,6 +14,8 @@
private boolean field_48633_g;
private boolean field_48638_h;
+ private BiomeGenBase[] biomesForWorldType;
+
private WorldType(int p_i1080_1_, String p_i1080_2_)
{
this(p_i1080_1_, p_i1080_2_, 0);
@@ -22,6 +27,13 @@
this.field_48632_f = p_i1081_3_;
this.field_48633_g = true;
field_48637_a[p_i1081_1_] = this;
+ switch (p_i1081_1_) {
+ case 8:
+ biomesForWorldType = new BiomeGenBase[] {BiomeGenBase.field_4249_h, BiomeGenBase.field_4253_d, BiomeGenBase.field_35483_e, BiomeGenBase.field_4255_b, BiomeGenBase.field_35485_c, BiomeGenBase.field_4250_g};
+ break;
+ default:
+ biomesForWorldType = new BiomeGenBase[] {BiomeGenBase.field_4249_h, BiomeGenBase.field_4253_d, BiomeGenBase.field_35483_e, BiomeGenBase.field_4255_b, BiomeGenBase.field_35485_c, BiomeGenBase.field_4250_g, BiomeGenBase.field_48416_w};
+ }
}
public String func_48628_a()
@@ -78,4 +90,20 @@
return null;
}
+
+ /**
+ * @param biome
+ */
+ public void addNewBiome(BiomeGenBase biome)
+ {
+ public BiomeGenBase[] getBiomesForWorldType() {
+ return biomesForWorldType;
+ }
+
+ public void addNewBiome(BiomeGenBase biome) {
+ List<BiomeGenBase> biomes=Arrays.asList(biomesForWorldType);
+ biomes.add(biome);
+ biomesForWorldType=biomes.toArray(new BiomeGenBase[0]);
+ }
+
+ public void removeBiome(BiomeGenBase biome) {
+ List<BiomeGenBase> biomes=Arrays.asList(biomesForWorldType);
+ biomes.remove(biome);
+ biomesForWorldType=biomes.toArray(new BiomeGenBase[0]);
+ }
}

View file

@ -9,7 +9,7 @@
public class WorldType
{
public static final WorldType[] field_48459_a = new WorldType[16];
@@ -11,9 +14,20 @@
@@ -11,6 +14,8 @@
private boolean field_48455_g;
private boolean field_48460_h;
@ -18,7 +18,11 @@
private WorldType(int p_i1025_1_, String p_i1025_2_)
{
this(p_i1025_1_, p_i1025_2_, 0);
+ switch (p_i1025_1_) {
@@ -22,6 +27,15 @@
this.field_48454_f = p_i1026_3_;
this.field_48455_g = true;
field_48459_a[p_i1026_1_] = this;
+ switch (p_i1026_1_) {
+ case 8:
+ biomesForWorldType = new BiomeGenBase[] { BiomeGenBase.field_4293_h, BiomeGenBase.field_4297_d, BiomeGenBase.field_35518_e,
+ BiomeGenBase.field_4299_b, BiomeGenBase.field_35520_c, BiomeGenBase.field_4294_g };
@ -26,10 +30,10 @@
+ default:
+ biomesForWorldType = new BiomeGenBase[] { BiomeGenBase.field_4293_h, BiomeGenBase.field_4297_d, BiomeGenBase.field_35518_e,
+ BiomeGenBase.field_4299_b, BiomeGenBase.field_35520_c, BiomeGenBase.field_4294_g, BiomeGenBase.field_48443_w };
+ }
+ }
}
private WorldType(int p_i1026_1_, String p_i1026_2_, int p_i1026_3_)
public String func_48449_a()
@@ -68,4 +82,14 @@
return null;