Registry: cleanup, fix missing id error GUI formatting
This commit is contained in:
parent
ac44af863b
commit
939a095896
5 changed files with 81 additions and 52 deletions
|
@ -627,7 +627,7 @@ public class FMLClientHandler implements IFMLSidedHandler
|
|||
catch (GameRegistryException gre)
|
||||
{
|
||||
client.func_71403_a(null);
|
||||
showGuiScreen(new GuiModItemsMissing(gre.getItems(), gre.getMessage()));
|
||||
showGuiScreen(new GuiModItemsMissing(gre.getItems()));
|
||||
}
|
||||
Thread.interrupted();
|
||||
}
|
||||
|
|
|
@ -12,7 +12,9 @@
|
|||
|
||||
package cpw.mods.fml.client;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
@ -20,19 +22,17 @@ import net.minecraft.client.resources.I18n;
|
|||
public class GuiModItemsMissing extends GuiScreen
|
||||
{
|
||||
private List<String> missingItems;
|
||||
private String message;
|
||||
|
||||
public GuiModItemsMissing(List<String> items, String message)
|
||||
public GuiModItemsMissing(List<String> items)
|
||||
{
|
||||
this.missingItems = items;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void func_73866_w_()
|
||||
{
|
||||
this.field_146292_n.add(new GuiButton(1, this.field_146294_l / 2 - 75, this.field_146295_m - 38, I18n.func_135052_a("gui.done")));
|
||||
this.field_146292_n.add(new GuiButton(1, this.field_146294_l / 2 - 100, this.field_146295_m - 38, I18n.func_135052_a("gui.done")));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -47,12 +47,38 @@ public class GuiModItemsMissing extends GuiScreen
|
|||
public void func_73863_a(int p_73863_1_, int p_73863_2_, float p_73863_3_)
|
||||
{
|
||||
this.func_146276_q_();
|
||||
int offset = 85;
|
||||
|
||||
int spaceAvailable = this.field_146295_m - 38 - 20;
|
||||
int spaceRequired = Math.min(spaceAvailable, 10 + 6 * 10 + missingItems.size());
|
||||
|
||||
int offset = 10 + (spaceAvailable - spaceRequired) / 2; // vertically centered
|
||||
this.func_73732_a(this.field_146289_q, "Forge Mod Loader could load this save", this.field_146294_l / 2, offset, 0xFFFFFF);
|
||||
offset += 10;
|
||||
offset += 20;
|
||||
this.func_73732_a(this.field_146289_q, String.format("There are %d unassigned blocks and items in this save", missingItems.size()), this.field_146294_l / 2, offset, 0xFFFFFF);
|
||||
offset += 10;
|
||||
this.func_73732_a(this.field_146289_q, "You will not be able to load until they are present again", this.field_146294_l / 2, offset, 0xFFFFFF);
|
||||
offset += 20;
|
||||
|
||||
this.func_73732_a(this.field_146289_q, "Missing Blocks/Items:", this.field_146294_l / 2, offset, 0xFFFFFF);
|
||||
offset += 10;
|
||||
|
||||
Iterator<String> it = missingItems.iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
String item = it.next();
|
||||
|
||||
this.func_73732_a(this.field_146289_q, item, this.field_146294_l / 2, offset, 0xFFFFFF);
|
||||
offset += 10;
|
||||
|
||||
if (offset >= spaceAvailable) break;
|
||||
}
|
||||
|
||||
if (it.hasNext())
|
||||
{
|
||||
this.func_73732_a(this.field_146289_q, "...", this.field_146294_l / 2, offset, 0xFFFFFF);
|
||||
}
|
||||
|
||||
super.func_73863_a(p_73863_1_, p_73863_2_, p_73863_3_);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,12 +16,9 @@ import java.io.File;
|
|||
import java.security.cert.Certificate;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
|
|
@ -3,21 +3,13 @@ package cpw.mods.fml.common.registry;
|
|||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.util.ObjectIntIdentityMap;
|
||||
import net.minecraft.util.RegistryNamespaced;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
|
@ -29,7 +21,8 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
|
|||
private int maxId;
|
||||
private int minId;
|
||||
private char discriminator;
|
||||
// aliases redirecting legacy names to the actual name, may need recursive application to find the final name
|
||||
// aliases redirecting legacy names to the actual name, may need recursive application to find the final name.
|
||||
// these need to be registry specific, it's possible to only have a loosely linked item for a block which may get renamed by itself.
|
||||
private final Map<String, String> aliases = new HashMap<String, String>();
|
||||
|
||||
FMLControlledNamespacedRegistry(String optionalDefault, int maxIdValue, int minIdValue, Class<I> type, char discriminator)
|
||||
|
@ -41,6 +34,7 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
|
|||
this.minId = minIdValue;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
void set(FMLControlledNamespacedRegistry<I> registry)
|
||||
{
|
||||
if (this.superType != registry.superType) throw new IllegalArgumentException("incompatible registry");
|
||||
|
@ -49,15 +43,14 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
|
|||
this.optionalDefaultName = registry.optionalDefaultName;
|
||||
this.maxId = registry.maxId;
|
||||
this.minId = registry.minId;
|
||||
this.aliases.clear();
|
||||
this.aliases.putAll(registry.aliases);
|
||||
field_148759_a = new ObjectIntIdentityMap();
|
||||
field_82596_a.clear();
|
||||
|
||||
for (Iterator<Object> it = registry.iterator(); it.hasNext(); )
|
||||
for (I thing : (Iterable<I>) registry)
|
||||
{
|
||||
I obj = (I) it.next();
|
||||
|
||||
super.func_148756_a(registry.getId(obj), registry.func_148750_c(obj), obj);
|
||||
super.func_148756_a(registry.getId(thing), registry.func_148750_c(thing), thing);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,7 +116,7 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
|
|||
* Usually the name should be used instead of the id, if using the Block/Item object itself is
|
||||
* not suitable for the task.
|
||||
*
|
||||
* @param think Block/Item object.
|
||||
* @param thing Block/Item object.
|
||||
* @return Block/Item id or -1 if it wasn't found.
|
||||
*/
|
||||
public int getId(I thing)
|
||||
|
@ -177,6 +170,17 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id for the specified object.
|
||||
*
|
||||
* Don't hold onto the id across the world, it's being dynamically re-mapped as needed.
|
||||
*
|
||||
* Usually the name should be used instead of the id, if using the Block/Item object itself is
|
||||
* not suitable for the task.
|
||||
*
|
||||
* @param itemName Block/Item registry name.
|
||||
* @return Block/Item id or -1 if it wasn't found.
|
||||
*/
|
||||
public int getId(String itemName)
|
||||
{
|
||||
I obj = getRaw(itemName);
|
||||
|
@ -192,11 +196,11 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
|
|||
|
||||
// internal
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void serializeInto(Map<String, Integer> idMapping)
|
||||
{
|
||||
for (Iterator<Object> it = iterator(); it.hasNext(); )
|
||||
for (I thing : (Iterable<I>) this)
|
||||
{
|
||||
I thing = (I) it.next();
|
||||
idMapping.put(discriminator+func_148750_c(thing), getId(thing));
|
||||
}
|
||||
}
|
||||
|
@ -239,26 +243,27 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
|
|||
aliases.put(from, to);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String,Integer> getEntriesNotIn(FMLControlledNamespacedRegistry<I> registry)
|
||||
{
|
||||
Map<String,Integer> ret = new HashMap<String, Integer>();
|
||||
|
||||
for (Iterator<Object> it = iterator(); it.hasNext(); )
|
||||
for (I thing : (Iterable<I>) this)
|
||||
{
|
||||
I thing = (I) it.next();
|
||||
if (!registry.field_148758_b.containsKey(thing)) ret.put(func_148750_c(thing), getId(thing));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
void dump()
|
||||
{
|
||||
List<Integer> ids = new ArrayList<Integer>();
|
||||
|
||||
for (Iterator<Object> it = iterator(); it.hasNext(); )
|
||||
for (I thing : (Iterable<I>) this)
|
||||
{
|
||||
ids.add(getId((I) it.next()));
|
||||
ids.add(getId(thing));
|
||||
}
|
||||
|
||||
// sort by id
|
||||
|
|
|
@ -17,7 +17,6 @@ import java.io.IOException;
|
|||
import java.util.BitSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -71,14 +70,28 @@ public class GameData {
|
|||
|
||||
// public api
|
||||
|
||||
/**
|
||||
* Get the currently active block registry.
|
||||
*
|
||||
* @return Block Registry.
|
||||
*/
|
||||
public static FMLControlledNamespacedRegistry<Block> getBlockRegistry() {
|
||||
return getMain().iBlockRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently active item registry.
|
||||
*
|
||||
* @return Item Registry.
|
||||
*/
|
||||
public static FMLControlledNamespacedRegistry<Item> getItemRegistry() {
|
||||
return getMain().iItemRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated no replacement planned
|
||||
*/
|
||||
@Deprecated
|
||||
public static ModContainer findModOwner(String string)
|
||||
{
|
||||
UniqueIdentifier ui = new UniqueIdentifier(string);
|
||||
|
@ -265,20 +278,9 @@ public class GameData {
|
|||
remaps.put(itemName, new Integer[] { currId, newId });
|
||||
}
|
||||
|
||||
if (isBlock)
|
||||
{
|
||||
Block block = getMain().iBlockRegistry.getRaw(itemName);
|
||||
if (block == null) throw new IllegalStateException(String.format("Can't find block for name %s, id %d", itemName, currId));
|
||||
|
||||
currId = newData.registerBlock(block, itemName, null, newId);
|
||||
}
|
||||
else
|
||||
{
|
||||
Item item = getMain().iItemRegistry.getRaw(itemName);
|
||||
if (item == null) throw new IllegalStateException(String.format("Can't find item for name %s, id %d", itemName, currId));
|
||||
|
||||
currId = newData.registerItem(item, itemName, null, newId);
|
||||
}
|
||||
// register
|
||||
FMLControlledNamespacedRegistry<?> srcRegistry = isBlock ? getMain().iBlockRegistry : getMain().iItemRegistry;
|
||||
currId = newData.register(srcRegistry.getRaw(itemName), itemName, newId);
|
||||
|
||||
if (currId != newId)
|
||||
{
|
||||
|
@ -485,15 +487,15 @@ public class GameData {
|
|||
blockedIds.addAll(data.blockedIds);
|
||||
}
|
||||
|
||||
void register(Object obj, String name, int idHint)
|
||||
int register(Object obj, String name, int idHint)
|
||||
{
|
||||
if (obj instanceof Block)
|
||||
{
|
||||
registerBlock((Block) obj, name, null, idHint);
|
||||
return registerBlock((Block) obj, name, null, idHint);
|
||||
}
|
||||
else if (obj instanceof Item)
|
||||
{
|
||||
registerItem((Item) obj, name, null, idHint);
|
||||
return registerItem((Item) obj, name, null, idHint);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -598,6 +600,7 @@ public class GameData {
|
|||
return oldValue;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void testConsistency() {
|
||||
// test if there's an entry for every set bit in availabilityMap
|
||||
for (int i = availabilityMap.nextSetBit(0); i >= 0; i = availabilityMap.nextSetBit(i+1))
|
||||
|
@ -609,9 +612,8 @@ public class GameData {
|
|||
}
|
||||
|
||||
// test if there's a bit in availabilityMap set for every entry in the block registry, make sure it's not a blocked id
|
||||
for (Iterator<Object> it = iBlockRegistry.iterator(); it.hasNext(); )
|
||||
for (Block block : (Iterable<Block>) iBlockRegistry)
|
||||
{
|
||||
Block block = (Block) it.next();
|
||||
int id = iBlockRegistry.getId(block);
|
||||
|
||||
if (!availabilityMap.get(id))
|
||||
|
@ -626,9 +628,8 @@ public class GameData {
|
|||
|
||||
// test if there's a bit in availabilityMap set for every entry in the item registry, make sure it's not a blocked id,
|
||||
// check if ItemBlocks have blocks with matching ids in the block registry
|
||||
for (Iterator<Object> it = iItemRegistry.iterator(); it.hasNext(); )
|
||||
for (Item item : (Iterable<Item>) iItemRegistry)
|
||||
{
|
||||
Item item = (Item) it.next();
|
||||
int id = iItemRegistry.getId(item);
|
||||
|
||||
if (!availabilityMap.get(id))
|
||||
|
|
Loading…
Reference in a new issue