Updated to the new Forge registry setup. Closes #1015

This commit is contained in:
Adubbz 2017-06-24 13:22:34 +10:00
parent f32d655af2
commit a5563eec33
10 changed files with 42 additions and 37 deletions

View file

@ -47,6 +47,7 @@ minecraft {
//set a full version string with appended build number to be used in mod registration //set a full version string with appended build number to be used in mod registration
def buildnum = (config.build_number!="") ? '.' + config.build_number : "" def buildnum = (config.build_number!="") ? '.' + config.build_number : ""
replace '@MOD_VERSION@', config.mod_version + buildnum replace '@MOD_VERSION@', config.mod_version + buildnum
replace '1.0.0.0', config.forge_version
replaceIn 'BiomesOPlenty.java' replaceIn 'BiomesOPlenty.java'
} }

View file

@ -1,4 +1,4 @@
minecraft_version=1.12 minecraft_version=1.12
forge_version=14.21.0.2340 forge_version=14.21.0.2349
mod_version=7.0.0 mod_version=7.0.0
mappings_version=snapshot_nodoc_20170619 mappings_version=snapshot_nodoc_20170619

View file

@ -17,7 +17,7 @@ import net.minecraft.util.NonNullList;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.oredict.RecipeSorter; import net.minecraftforge.oredict.RecipeSorter;
public class BiomeEssenceRecipe extends net.minecraftforge.fml.common.registry.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe public class BiomeEssenceRecipe extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{ {
static { static {
RecipeSorter.register("biomesoplenty:biomeessenceRecipe", BiomeEssenceRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless"); RecipeSorter.register("biomesoplenty:biomeessenceRecipe", BiomeEssenceRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless");

View file

@ -20,6 +20,7 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import com.google.common.base.Optional; import com.google.common.base.Optional;
@ -619,7 +620,8 @@ public class ModBiomes implements BOPBiomes.IBiomeRegistry
BOPCommand.biomeCount++; BOPCommand.biomeCount++;
BOPBiomes.REG_INSTANCE.registerBiome(biome, idName); BOPBiomes.REG_INSTANCE.registerBiome(biome, idName);
Biome.registerBiome(id, biome.getResourceLocation().toString(), biome); biome.setRegistryName(biome.getResourceLocation());
ForgeRegistries.BIOMES.register(biome);
//Enable spwning and village generation in the biome //Enable spwning and village generation in the biome
if (biome.canSpawnInBiome) if (biome.canSpawnInBiome)
@ -647,7 +649,8 @@ public class ModBiomes implements BOPBiomes.IBiomeRegistry
BOPCommand.biomeCount++; BOPCommand.biomeCount++;
BOPBiomes.REG_INSTANCE.registerBiome(biome, idName); BOPBiomes.REG_INSTANCE.registerBiome(biome, idName);
Biome.registerBiome(id, biome.getResourceLocation().toString(), biome); biome.setRegistryName(biome.getResourceLocation());
ForgeRegistries.BIOMES.register(biome);
return Optional.of((Biome)biome); return Optional.of((Biome)biome);

View file

@ -87,6 +87,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.EnumPlantType; import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
public class ModBlocks public class ModBlocks
@ -314,10 +315,11 @@ public class ModBlocks
public static Block registerFluidBlock(Fluid fluid, Block fluidBlock, String name) public static Block registerFluidBlock(Fluid fluid, Block fluidBlock, String name)
{ {
Block block = GameRegistry.register(fluidBlock, new ResourceLocation(BiomesOPlenty.MOD_ID, name)); fluidBlock.setRegistryName(new ResourceLocation(BiomesOPlenty.MOD_ID, name));
BiomesOPlenty.proxy.registerFluidBlockRendering(block, name); ForgeRegistries.BLOCKS.register(fluidBlock);
BiomesOPlenty.proxy.registerFluidBlockRendering(fluidBlock, name);
fluid.setBlock(fluidBlock); fluid.setBlock(fluidBlock);
return block; return fluidBlock;
} }
@ -410,12 +412,18 @@ public class ModBlocks
Item itemBlock = clazz != null ? (Item)clazz.getConstructor(Block.class).newInstance(block) : null; Item itemBlock = clazz != null ? (Item)clazz.getConstructor(Block.class).newInstance(block) : null;
ResourceLocation location = new ResourceLocation(BiomesOPlenty.MOD_ID, blockName); ResourceLocation location = new ResourceLocation(BiomesOPlenty.MOD_ID, blockName);
GameRegistry.register(block, location); block.setRegistryName(new ResourceLocation(BiomesOPlenty.MOD_ID, blockName));
if (itemBlock != null) GameRegistry.register(itemBlock, location);
ForgeRegistries.BLOCKS.register(block);
if (itemBlock != null)
{
itemBlock.setRegistryName(new ResourceLocation(BiomesOPlenty.MOD_ID, blockName));
ForgeRegistries.ITEMS.register(itemBlock);
}
} }
catch (Exception e) catch (Exception e)
{ {
throw new RuntimeException("An error occurred associating an item block during registration...", e); throw new RuntimeException("An error occurred associating an item block during registration of " + blockName, e);
} }
} }

View file

@ -68,6 +68,7 @@ import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemSoup; import net.minecraft.item.ItemSoup;
import net.minecraft.potion.PotionEffect; import net.minecraft.potion.PotionEffect;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
public class ModItems public class ModItems
@ -154,7 +155,8 @@ public class ModItems
item.setCreativeTab(CreativeTabBOP.instance); item.setCreativeTab(CreativeTabBOP.instance);
} }
GameRegistry.register(item, new ResourceLocation(BiomesOPlenty.MOD_ID, name)); item.setRegistryName(new ResourceLocation(BiomesOPlenty.MOD_ID, name));
ForgeRegistries.ITEMS.register(item);
BOPCommand.itemCount++; BOPCommand.itemCount++;
BiomesOPlenty.proxy.registerItemSided(item); BiomesOPlenty.proxy.registerItemSided(item);

View file

@ -16,6 +16,7 @@ import biomesoplenty.common.potion.PotionPossession;
import biomesoplenty.core.BiomesOPlenty; import biomesoplenty.core.BiomesOPlenty;
import net.minecraft.potion.Potion; import net.minecraft.potion.Potion;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
public class ModPotions public class ModPotions
{ {
@ -29,23 +30,9 @@ public class ModPotions
public static Potion registerPotion(String name, Potion potion) public static Potion registerPotion(String name, Potion potion)
{ {
Potion.REGISTRY.register(getSparePotionId(), new ResourceLocation(BiomesOPlenty.MOD_ID, name), potion); ResourceLocation location = new ResourceLocation(BiomesOPlenty.MOD_ID, name);
potion.setRegistryName(location);
ForgeRegistries.POTIONS.register(potion);
return potion; return potion;
} }
// gets the next free potion id
// will expand the potions array if necessary
// this isn't very efficient, but it only has to run once, right at the start, so clarity and simplicity are more important than speed
public static int getSparePotionId()
{
int nextId = 1;
// look for a free slot in the Potions array
// (note we start counting from 1 - vanilla MC doens't use ID 0, nor will we)
for (; Potion.REGISTRY.getObjectById(nextId) != null; nextId++) {}
return nextId;
}
} }

View file

@ -16,6 +16,7 @@ import static biomesoplenty.api.sound.BOPSounds.wasp_hurt;
import biomesoplenty.core.BiomesOPlenty; import biomesoplenty.core.BiomesOPlenty;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
public class ModSounds public class ModSounds
{ {
@ -31,7 +32,9 @@ public class ModSounds
private static SoundEvent registerSound(String soundName) private static SoundEvent registerSound(String soundName)
{ {
ResourceLocation location = new ResourceLocation(BiomesOPlenty.MOD_ID, soundName); ResourceLocation location = new ResourceLocation(BiomesOPlenty.MOD_ID, soundName);
SoundEvent.registerSound(location.toString()); SoundEvent event = new SoundEvent(location);
return SoundEvent.REGISTRY.getObject(location); event.setRegistryName(location);
ForgeRegistries.SOUND_EVENTS.register(event);
return event;
} }
} }

View file

@ -43,7 +43,7 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent; import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.NetworkRegistry;
@Mod(modid = BiomesOPlenty.MOD_ID, version = BiomesOPlenty.MOD_VERSION , name = BiomesOPlenty.MOD_NAME, dependencies = "required-after:forge@[14.21.0.2340,)", guiFactory = BiomesOPlenty.GUI_FACTORY) @Mod(modid = BiomesOPlenty.MOD_ID, version = BiomesOPlenty.MOD_VERSION , name = BiomesOPlenty.MOD_NAME, dependencies = "required-after:forge@[1.0.0.0,)", guiFactory = BiomesOPlenty.GUI_FACTORY)
public class BiomesOPlenty public class BiomesOPlenty
{ {
public static final String MOD_NAME = "Biomes O' Plenty"; public static final String MOD_NAME = "Biomes O' Plenty";

View file

@ -98,13 +98,14 @@ public class ClientProxy extends CommonProxy
registerEntityRenderer(EntityMudball.class, RenderMudball.class); registerEntityRenderer(EntityMudball.class, RenderMudball.class);
replaceForgeResources(); replaceForgeResources();
ModelLoader.registerItemVariants(ForgeModContainer.getInstance().universalBucket, bucketModelLocations);
} }
@Override @Override
public void registerColouring() public void registerColouring()
{ {
// do this here purely for timing reasons
ModelLoader.registerItemVariants(ForgeModContainer.getInstance().universalBucket, bucketModelLocations);
for (Block block : blocksToColour) for (Block block : blocksToColour)
{ {
IBOPBlock bopBlock = (IBOPBlock)block; IBOPBlock bopBlock = (IBOPBlock)block;