forked from xjboss/KCauldronX
Initial commit (Forge 1291).
This commit is contained in:
@ -0,0 +1,79 @@
|
||||
--- ../src-base/minecraft/cpw/mods/fml/common/registry/EntityRegistry.java
|
||||
+++ ../src-work/minecraft/cpw/mods/fml/common/registry/EntityRegistry.java
|
||||
@@ -41,6 +41,12 @@
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.network.internal.FMLMessage.EntitySpawnMessage;
|
||||
|
||||
+// Cauldron start
|
||||
+import net.minecraftforge.common.util.EnumHelper;
|
||||
+import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
+import org.bukkit.entity.EntityType;
|
||||
+// Cauldron end
|
||||
+
|
||||
public class EntityRegistry
|
||||
{
|
||||
public class EntityRegistration
|
||||
@@ -118,6 +124,8 @@
|
||||
private ListMultimap<ModContainer, EntityRegistration> entityRegistrations = ArrayListMultimap.create();
|
||||
private Map<String,ModContainer> entityNames = Maps.newHashMap();
|
||||
private BiMap<Class<? extends Entity>, EntityRegistration> entityClassRegistrations = HashBiMap.create();
|
||||
+ public static Map<Class <? extends Entity>, String> entityTypeMap = Maps.newHashMap(); // Cauldron - used by CraftCustomEntity
|
||||
+ public static Map<String, Class <? extends Entity>> entityClassMap = Maps.newHashMap(); // Cauldron - used by CraftWorld
|
||||
public static EntityRegistry instance()
|
||||
{
|
||||
return INSTANCE;
|
||||
@@ -147,6 +155,7 @@
|
||||
public static void registerModEntity(Class<? extends Entity> entityClass, String entityName, int id, Object mod, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates)
|
||||
{
|
||||
instance().doModEntityRegistration(entityClass, entityName, id, mod, trackingRange, updateFrequency, sendsVelocityUpdates);
|
||||
+ registerBukkitType(entityClass, entityName); // Cauldron - register EntityType for Bukkit
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -197,6 +206,7 @@
|
||||
}
|
||||
id = instance().validateAndClaimId(id);
|
||||
EntityList.addMapping(entityClass, entityName, id);
|
||||
+ registerBukkitType(entityClass, entityName); // Cauldron - register EntityType for Bukkit
|
||||
}
|
||||
|
||||
private int validateAndClaimId(int id)
|
||||
@@ -249,8 +259,38 @@
|
||||
}
|
||||
instance().validateAndClaimId(id);
|
||||
EntityList.addMapping(entityClass, entityName, id, backgroundEggColour, foregroundEggColour);
|
||||
+ registerBukkitType(entityClass, entityName); // Cauldron - register EntityType for Bukkit
|
||||
}
|
||||
|
||||
+ // Cauldron start
|
||||
+ private static void registerBukkitType(Class <? extends Entity > entityClass, String entityName)
|
||||
+ {
|
||||
+ ModContainer activeModContainer = Loader.instance().activeModContainer();
|
||||
+ String modId = "unknown";
|
||||
+ // fixup bad entity names from mods
|
||||
+ if (entityName.contains("."))
|
||||
+ {
|
||||
+ if ((entityName.indexOf(".") + 1) < entityName.length())
|
||||
+ entityName = entityName.substring(entityName.indexOf(".") + 1, entityName.length());
|
||||
+ }
|
||||
+ entityName.replace("entity", "");
|
||||
+ if (entityName.startsWith("ent"))
|
||||
+ entityName.replace("ent", "");
|
||||
+ entityName = entityName.replaceAll("[^A-Za-z0-9]", ""); // remove all non-digits/alphanumeric
|
||||
+ if (activeModContainer != null)
|
||||
+ modId = activeModContainer.getModId();
|
||||
+ entityName = modId + "-" + entityName;
|
||||
+ entityTypeMap.put(entityClass, entityName);
|
||||
+ entityClassMap.put(entityName, entityClass);
|
||||
+ }
|
||||
+
|
||||
+ // used by CraftCustomEntity
|
||||
+ public static String getCustomEntityTypeName(Class <? extends Entity > entityClass)
|
||||
+ {
|
||||
+ return entityTypeMap.get(entityClass);
|
||||
+ }
|
||||
+ // Cauldron end
|
||||
+
|
||||
public static void addSpawn(Class <? extends EntityLiving > entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, BiomeGenBase... biomes)
|
||||
{
|
||||
for (BiomeGenBase biome : biomes)
|
69
patches/cpw/mods/fml/common/registry/GameData.java.patch
Normal file
69
patches/cpw/mods/fml/common/registry/GameData.java.patch
Normal file
@ -0,0 +1,69 @@
|
||||
--- ../src-base/minecraft/cpw/mods/fml/common/registry/GameData.java
|
||||
+++ ../src-work/minecraft/cpw/mods/fml/common/registry/GameData.java
|
||||
@@ -14,7 +14,9 @@
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
+import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
+import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -1024,4 +1026,56 @@
|
||||
throw new RuntimeException("WHAT?");
|
||||
}
|
||||
}
|
||||
+
|
||||
+ // Cauldron start
|
||||
+ public static void injectItemBukkitMaterials()
|
||||
+ {
|
||||
+ FMLControlledNamespacedRegistry<Item> itemRegistry = getItemRegistry();
|
||||
+ List<Integer> ids = new ArrayList<Integer>();
|
||||
+
|
||||
+ for (Item thing : itemRegistry.typeSafeIterable())
|
||||
+ {
|
||||
+ ids.add(itemRegistry.getId(thing));
|
||||
+ }
|
||||
+
|
||||
+ // sort by id
|
||||
+ Collections.sort(ids);
|
||||
+
|
||||
+ for (int id : ids)
|
||||
+ {
|
||||
+ Item item = itemRegistry.getRaw(id);
|
||||
+ // inject item materials into Bukkit for FML
|
||||
+ org.bukkit.Material material = org.bukkit.Material.addMaterial(id, itemRegistry.getNameForObject(item), false);
|
||||
+ if (material != null)
|
||||
+ {
|
||||
+ FMLLog.info("Injected new Forge item material %s with ID %d.", material.name(), material.getId());
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public static void injectBlockBukkitMaterials()
|
||||
+ {
|
||||
+ FMLControlledNamespacedRegistry<Block> blockRegistry = getBlockRegistry();
|
||||
+ List<Integer> ids = new ArrayList<Integer>();
|
||||
+
|
||||
+ for (Block block : blockRegistry.typeSafeIterable())
|
||||
+ {
|
||||
+ ids.add(blockRegistry.getId(block));
|
||||
+ }
|
||||
+
|
||||
+ // sort by id
|
||||
+ Collections.sort(ids);
|
||||
+
|
||||
+ for (int id : ids)
|
||||
+ {
|
||||
+ Block block = blockRegistry.getRaw(id);
|
||||
+ // inject block materials into Bukkit for FML
|
||||
+ org.bukkit.Material material = org.bukkit.Material.addMaterial(id, blockRegistry.getNameForObject(block), true);
|
||||
+ if (material != null)
|
||||
+ {
|
||||
+ FMLLog.info("Injected new Forge block material %s with ID %d.", material.name(), material.getId());
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ // Cauldron end
|
||||
}
|
71
patches/cpw/mods/fml/common/registry/GameRegistry.java.patch
Normal file
71
patches/cpw/mods/fml/common/registry/GameRegistry.java.patch
Normal file
@ -0,0 +1,71 @@
|
||||
--- ../src-base/minecraft/cpw/mods/fml/common/registry/GameRegistry.java
|
||||
+++ ../src-work/minecraft/cpw/mods/fml/common/registry/GameRegistry.java
|
||||
@@ -53,6 +53,7 @@
|
||||
import cpw.mods.fml.common.LoaderException;
|
||||
import cpw.mods.fml.common.LoaderState;
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
+import java.util.HashMap; // Cauldron
|
||||
|
||||
public class GameRegistry
|
||||
{
|
||||
@@ -60,6 +61,10 @@
|
||||
private static Map<IWorldGenerator, Integer> worldGeneratorIndex = Maps.newHashMap();
|
||||
private static List<IFuelHandler> fuelHandlers = Lists.newArrayList();
|
||||
private static List<IWorldGenerator> sortedGeneratorList;
|
||||
+ // Cauldron start
|
||||
+ private static Map<String, Boolean> configWorldGenCache = new HashMap<String, Boolean>();
|
||||
+ private static Map<String, String> worldGenMap = new HashMap<String, String>();
|
||||
+ // Cauldron end
|
||||
|
||||
/**
|
||||
* Register a world generator - something that inserts new block types into the world
|
||||
@@ -70,12 +75,18 @@
|
||||
*/
|
||||
public static void registerWorldGenerator(IWorldGenerator generator, int modGenerationWeight)
|
||||
{
|
||||
+ // Cauldron start - mod id's are not available during generateWorld so we must capture them here
|
||||
+ String modId = Loader.instance().activeModContainer().getModId();
|
||||
+ modId = modId.replaceAll("[^A-Za-z0-9]", ""); // remove all non-digits/alphanumeric
|
||||
+ modId.replace(" ", "_");
|
||||
worldGenerators.add(generator);
|
||||
worldGeneratorIndex.put(generator, modGenerationWeight);
|
||||
if (sortedGeneratorList != null)
|
||||
{
|
||||
sortedGeneratorList = null;
|
||||
}
|
||||
+ worldGenMap.put(generator.getClass().getName(), modId);
|
||||
+ // Cauldron end
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,11 +111,27 @@
|
||||
long zSeed = fmlRandom.nextLong() >> 2 + 1L;
|
||||
long chunkSeed = (xSeed * chunkX + zSeed * chunkZ) ^ worldSeed;
|
||||
|
||||
- for (IWorldGenerator generator : sortedGeneratorList)
|
||||
+ boolean before = ((net.minecraft.world.WorldServer) world).theChunkProviderServer.loadChunkOnProvideRequest; // Cauldron store value
|
||||
+ ((net.minecraft.world.WorldServer) world).theChunkProviderServer.loadChunkOnProvideRequest = true; // Cauldron load chunks on provide requests
|
||||
+ for (IWorldGenerator generator : worldGenerators)
|
||||
{
|
||||
- fmlRandom.setSeed(chunkSeed);
|
||||
- generator.generate(fmlRandom, chunkX, chunkZ, world, chunkGenerator, chunkProvider);
|
||||
+ // Cauldron start
|
||||
+ if (!configWorldGenCache.containsKey(generator.getClass().getName()))
|
||||
+ {
|
||||
+ String modId = worldGenMap.get(generator.getClass().getName());
|
||||
+ String generatorName = "";
|
||||
+ generatorName = modId + "-" + generator.getClass().getSimpleName();
|
||||
+ boolean generatorEnabled = world.cauldronConfig.getBoolean("worldgen-" + generatorName, true);
|
||||
+ configWorldGenCache.put(generator.getClass().getName(), generatorEnabled);
|
||||
+ }
|
||||
+ if (configWorldGenCache.get(generator.getClass().getName()))
|
||||
+ {
|
||||
+ fmlRandom.setSeed(chunkSeed);
|
||||
+ generator.generate(fmlRandom, chunkX, chunkZ, world, chunkGenerator, chunkProvider);
|
||||
+ }
|
||||
}
|
||||
+ ((net.minecraft.world.WorldServer)world).theChunkProviderServer.loadChunkOnProvideRequest = before; // reset
|
||||
+ // Cauldron end
|
||||
}
|
||||
|
||||
private static void computeSortedGeneratorList()
|
Reference in New Issue
Block a user