Fix that the dummy registry entries don't allow clients connecting to servers. Also fix that it repeatedly nags about missing stuff in the world.

This commit is contained in:
cpw 2015-12-31 17:58:30 -05:00
parent 50f235c81b
commit 6e90348dc5
5 changed files with 89 additions and 4 deletions

View File

@ -154,6 +154,14 @@ public class FMLContainer extends DummyModContainer implements WorldAccessContai
blocked[idx++] = i;
}
data.setIntArray("blocked", blocked);
NBTTagList dummied = new NBTTagList();
for (ResourceLocation entry : e.getValue().dummied)
{
NBTTagCompound tag = new NBTTagCompound();
tag.setString("K", entry.toString());
dummied.appendTag(tag);
}
data.setTag("dummied", dummied);
}
return fmlData;
}
@ -297,6 +305,14 @@ public class FMLContainer extends DummyModContainer implements WorldAccessContai
{
entry.blocked.add(i);
}
// save doesn't have dummied list
if (!regs.getCompoundTag(key).hasKey("dummied")) return;
list = regs.getCompoundTag(key).getTagList("dummied",10);
for (int x = 0; x < list.tagCount(); x++)
{
NBTTagCompound e = list.getCompoundTagAt(x);
entry.dummied.add(new ResourceLocation(e.getString("K")));
}
}
failedElements = PersistentRegistryManager.injectSnapshot(snapshot, true, true);
}

View File

@ -105,11 +105,12 @@ enum FMLHandshakeClientState implements IHandshakeState<FMLHandshakeClientState>
PersistentRegistryManager.GameDataSnapshot.Entry entry = new PersistentRegistryManager.GameDataSnapshot.Entry();
entry.ids.putAll(pkt.getIdMap());
entry.substitutions.addAll(pkt.getSubstitutions());
entry.dummied.addAll(pkt.getDummied());
snap.entries.put(pkt.getName(), entry);
if (pkt.hasMore())
{
FMLLog.fine("Received Mod Registry mapping for %s: %d IDs %d subs", pkt.getName(), entry.ids.size(), entry.substitutions.size());
FMLLog.fine("Received Mod Registry mapping for %s: %d IDs %d subs %d dummied", pkt.getName(), entry.ids.size(), entry.substitutions.size(), entry.dummied.size());
return WAITINGSERVERCOMPLETE;
}

View File

@ -165,12 +165,14 @@ public abstract class FMLHandshakeMessage {
this.name = name;
this.ids = entry.ids;
this.substitutions = entry.substitutions;
this.dummied = entry.dummied;
}
private boolean hasMore;
private ResourceLocation name;
private Map<ResourceLocation, Integer> ids;
private Set<ResourceLocation> substitutions;
private Set<ResourceLocation> dummied;
@Override
public void fromBytes(ByteBuf buffer)
@ -193,6 +195,15 @@ public abstract class FMLHandshakeMessage {
{
substitutions.add(new ResourceLocation(ByteBufUtils.readUTF8String(buffer)));
}
dummied = Sets.newHashSet();
// if the dummied list isn't present - probably an older server
if (!buffer.isReadable()) return;
length = ByteBufUtils.readVarInt(buffer, 3);
for (int i = 0; i < length; i++)
{
dummied.add(new ResourceLocation(ByteBufUtils.readUTF8String(buffer)));
}
//if (!buffer.isReadable()) return; // In case we expand
}
@ -214,6 +225,11 @@ public abstract class FMLHandshakeMessage {
{
ByteBufUtils.writeUTF8String(buffer, entry.toString());
}
ByteBufUtils.writeVarInt(buffer, dummied.size(), 3);
for (ResourceLocation entry: dummied)
{
ByteBufUtils.writeUTF8String(buffer, entry.toString());
}
}
public Map<ResourceLocation,Integer> getIdMap()
@ -224,6 +240,7 @@ public abstract class FMLHandshakeMessage {
{
return substitutions;
}
public Set<ResourceLocation> getDummied() { return dummied; }
public ResourceLocation getName()
{
return this.name;

View File

@ -54,6 +54,8 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespacedDefaul
*/
private final Set<Integer> blockedIds = Sets.newHashSet();
private final Set<ResourceLocation> dummiedLocations = Sets.newHashSet();
private final BitSet availabilityMap;
private final AddCallback<I> addCallback;
@ -164,6 +166,8 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespacedDefaul
this.persistentSubstitutions.clear();
this.persistentSubstitutions.putAll(otherRegistry.getPersistentSubstitutions());
this.activeSubstitutions.clear();
this.dummiedLocations.clear();
this.dummiedLocations.addAll(otherRegistry.dummiedLocations);
underlyingIntegerMap = new ObjectIntIdentityMap<I>();
registryObjects.clear();
@ -384,6 +388,9 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespacedDefaul
set.addAll(activeSubstitutions.keySet());
}
public void serializeDummied(Set<ResourceLocation> set) { set.addAll(this.dummiedLocations); }
/**
* Add the specified object to the registry.
*
@ -456,6 +463,8 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespacedDefaul
{
getExistingDelegate(thing).setResourceName(name);
}
this.dummiedLocations.remove(name);
if (DEBUG)
{
FMLLog.finer("Registry add: %s %d %s (req. id %d)", name, idToUse, thing, id);
@ -463,6 +472,12 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespacedDefaul
return idToUse;
}
void markDummy(ResourceLocation rl, Integer id, I thing)
{
this.dummiedLocations.add(rl);
this.addObjectRaw(id, rl, thing);
}
void addAlias(ResourceLocation from, ResourceLocation to)
{
aliases.put(from, to);
@ -688,6 +703,11 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespacedDefaul
}
}
public void loadDummied(Set<ResourceLocation> dummied)
{
this.dummiedLocations.addAll(dummied);
}
public void loadIds(Map<ResourceLocation, Integer> ids, Map<ResourceLocation, Integer> missingIds, Map<ResourceLocation, Integer[]> remappedIds, FMLControlledNamespacedRegistry<I> currentRegistry, ResourceLocation registryName)
{
for (Map.Entry<ResourceLocation, Integer> entry : ids.entrySet())

View File

@ -161,6 +161,30 @@ public class PersistentRegistryManager
loadPersistentDataToStagingRegistry(injectFrozenData, remaps, missing, snapshotEntry, PersistentRegistry.ACTIVE.registrySuperTypes.inverse().get(snapshotEntry.getKey()));
}
// Handle dummied blocks
for (ResourceLocation dummy : snapshot.entries.get(BLOCKS).dummied)
{
// Currently missing locally, we just inject and carry on
if (missing.get(BLOCKS).containsKey(dummy))
{
Integer id = missing.get(BLOCKS).remove(dummy);
// Mark this entry as a dummy
PersistentRegistry.STAGING.getRegistry(BLOCKS, Block.class).markDummy(dummy, id, new BlockDummyAir());
}
else if (isLocalWorld)
{
// Carry on, we resuscitated the block
}
else
{
Integer id = PersistentRegistry.STAGING.getRegistry(BLOCKS, Block.class).getId(dummy);
// The server believes this is a dummy block identity, but we seem to have one locally. This is likely a conflict
// in mod setup - Mark this entry as a dummy
FMLLog.log(Level.WARN, "The ID %d is currently locally mapped - it will be replaced with air for this session", id);
PersistentRegistry.STAGING.getRegistry(BLOCKS, Block.class).markDummy(dummy, id, new BlockDummyAir());
}
}
// If we have missed data, fire the missing mapping event
List<String> missedMappings = Loader.instance().fireMissingMappingEvent(missing.get(BLOCKS), missing.get(ITEMS), isLocalWorld, remaps.get(BLOCKS), remaps.get(ITEMS));
// If there's still missed mappings, we return, because that's an error
@ -178,7 +202,8 @@ public class PersistentRegistryManager
ResourceLocation rl = missingBlock.getKey();
Integer id = missingBlock.getValue();
FMLLog.log(Level.DEBUG, "Replacing id %s named as %s with air block. If the mod becomes available again later, it can reload here", id, rl);
PersistentRegistry.STAGING.getRegistry(BLOCKS, Block.class).add(id, rl, new BlockDummyAir());
// Mark this entry as a dummy
PersistentRegistry.STAGING.getRegistry(BLOCKS, Block.class).markDummy(rl, id, new BlockDummyAir());
}
}
// If we're loading up the world from disk, we want to add in the new data that might have been provisioned by mods
@ -301,6 +326,8 @@ public class PersistentRegistryManager
missing.put(registryName, Maps.<ResourceLocation, Integer>newLinkedHashMap());
remaps.put(registryName, Maps.<ResourceLocation, Integer[]>newHashMap());
newRegistry.loadIds(snapshotEntry.ids, missing.get(registryName), remaps.get(registryName), currentRegistry, registryName);
// Load current dummies AFTER the snapshot is loaded
newRegistry.loadDummied(snapshotEntry.dummied);
}
public static boolean isFrozen(FMLControlledNamespacedRegistry<?> registry)
@ -510,18 +537,20 @@ public class PersistentRegistryManager
public final Set<ResourceLocation> substitutions;
public final Map<ResourceLocation, ResourceLocation> aliases;
public final Set<Integer> blocked;
public final Set<ResourceLocation> dummied;
public Entry()
{
this(new HashMap<ResourceLocation, Integer>(), new HashSet<ResourceLocation>(), new HashMap<ResourceLocation, ResourceLocation>(), new HashSet<Integer>());
this(new HashMap<ResourceLocation, Integer>(), new HashSet<ResourceLocation>(), new HashMap<ResourceLocation, ResourceLocation>(), new HashSet<Integer>(), new HashSet<ResourceLocation>());
}
public Entry(Map<ResourceLocation, Integer> ids, Set<ResourceLocation> substitutions, Map<ResourceLocation, ResourceLocation> aliases, Set<Integer> blocked)
public Entry(Map<ResourceLocation, Integer> ids, Set<ResourceLocation> substitutions, Map<ResourceLocation, ResourceLocation> aliases, Set<Integer> blocked, Set<ResourceLocation> dummies)
{
this.ids = ids;
this.substitutions = substitutions;
this.aliases = aliases;
this.blocked = blocked;
this.dummied = dummies;
}
public Entry(FMLControlledNamespacedRegistry<?> registry)
@ -530,11 +559,13 @@ public class PersistentRegistryManager
this.substitutions = Sets.newHashSet();
this.aliases = Maps.newHashMap();
this.blocked = Sets.newHashSet();
this.dummied = Sets.newHashSet();
registry.serializeIds(this.ids);
registry.serializeSubstitutions(this.substitutions);
registry.serializeAliases(this.aliases);
registry.serializeBlockList(this.blocked);
registry.serializeDummied(this.dummied);
}
}