mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-16 18:45:09 +00:00
Merge branch 'PotionRegistry2' of https://github.com/bonii-xx/MinecraftForge into bonii-xx-PotionRegistry2
This commit is contained in:
commit
0af45cbf25
6 files changed
+176
-1
No files matched your search
@@ -19,6 +19,7 @@ import com.google.common.collect.Maps;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.util.ObjectIntIdentityMap;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
@@ -31,6 +32,8 @@ public class GameData
|
||||
static final int MAX_BLOCK_ID = 4095;
|
||||
static final int MIN_ITEM_ID = 4096;
|
||||
static final int MAX_ITEM_ID = 31999;
|
||||
public static final int MIN_POTION_ID = 32; // 0-31 are vanilla, forge start at 32
|
||||
public static final int MAX_POTION_ID = 255; // S1DPacketEntityEffect sends bytes, we can only use 255
|
||||
|
||||
private static final GameData mainData = new GameData();
|
||||
// public api
|
||||
@@ -55,6 +58,16 @@ public class GameData
|
||||
return getMain().iItemRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently active potion registry.
|
||||
*
|
||||
* @return Potion Registry.
|
||||
*/
|
||||
public static FMLControlledNamespacedRegistry<Potion> getPotionRegistry() {
|
||||
return getMain().iPotionRegistry;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************
|
||||
* INTERNAL CODE FROM HERE ON DO NOT USE!
|
||||
***************************************************/
|
||||
@@ -98,6 +111,7 @@ public class GameData
|
||||
// internal registry objects
|
||||
private final FMLControlledNamespacedRegistry<Block> iBlockRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.BLOCKS, Block.class, new ResourceLocation("minecraft:air"), MAX_BLOCK_ID, MIN_BLOCK_ID, true, BlockStateCapture.INSTANCE);
|
||||
private final FMLControlledNamespacedRegistry<Item> iItemRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.ITEMS, Item.class, null, MAX_ITEM_ID, MIN_ITEM_ID, true);
|
||||
private final FMLControlledNamespacedRegistry<Potion> iPotionRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.POTIONS, Potion.class, null, MAX_POTION_ID, MIN_POTION_ID, false, PotionArrayCapture.INSTANCE);
|
||||
|
||||
int registerItem(Item item, String name) // from GameRegistry
|
||||
{
|
||||
@@ -133,6 +147,13 @@ public class GameData
|
||||
return iBlockRegistry.add(idHint, name, block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from GameRegistry, which is called from Potion-Constructor
|
||||
*/
|
||||
int registerPotion(Potion potion, ResourceLocation name, int id) {
|
||||
return iPotionRegistry.add(id, name, potion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefix the supplied name with the current mod id.
|
||||
* <p/>
|
||||
@@ -228,4 +249,16 @@ public class GameData
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class PotionArrayCapture implements FMLControlledNamespacedRegistry.AddCallback<Potion>
|
||||
{
|
||||
static final PotionArrayCapture INSTANCE = new PotionArrayCapture();
|
||||
|
||||
@Override
|
||||
public void onAdd(Potion potion, int id) {
|
||||
// fix the data in the potion and the potions-array
|
||||
potion.id = id;
|
||||
Potion.potionTypes[id] = potion;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
@@ -235,6 +236,11 @@ public class GameRegistry
|
||||
}
|
||||
}
|
||||
|
||||
/** Called from Potion Constructor */
|
||||
public static int registerPotion(Potion potion, ResourceLocation name, int potionID) {
|
||||
return GameData.getMain().registerPotion(potion, name, potionID);
|
||||
}
|
||||
|
||||
public static void addRecipe(ItemStack output, Object... params)
|
||||
{
|
||||
addShapedRecipe(output, params);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.minecraftforge.fml.common.registry;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -20,6 +21,7 @@ import com.google.common.collect.Sets.SetView;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
@@ -122,6 +124,7 @@ public class PersistentRegistryManager
|
||||
|
||||
public static final ResourceLocation BLOCKS = new ResourceLocation("minecraft:blocks");
|
||||
public static final ResourceLocation ITEMS = new ResourceLocation("minecraft:items");
|
||||
public static final ResourceLocation POTIONS = new ResourceLocation("minecraft:potions");
|
||||
|
||||
public static <T> FMLControlledNamespacedRegistry<T> createRegistry(ResourceLocation registryName, Class<T> registryType, ResourceLocation optionalDefaultKey, int maxId, int minId, boolean hasDelegates, FMLControlledNamespacedRegistry.AddCallback<T> addCallback)
|
||||
{
|
||||
@@ -145,6 +148,8 @@ public class PersistentRegistryManager
|
||||
|
||||
// Empty the blockstate map before loading
|
||||
GameData.getBlockStateIDMap().clear();
|
||||
// Clean up potion array before reloading it from the snapshot
|
||||
Arrays.fill(Potion.potionTypes, null);
|
||||
|
||||
// Load the snapshot into the "STAGING" registry
|
||||
for (Map.Entry<ResourceLocation, GameDataSnapshot.Entry> snapshotEntry : snapshot.entries.entrySet())
|
||||
|
||||
Reference in new issue
Block a user