Prevented model/rendering registration from occurring on the server, fixes crashing

This commit is contained in:
Adubbz 2015-04-08 08:55:35 +10:00
parent 197f584c21
commit 3f8b64ec5e
4 changed files with 49 additions and 16 deletions

View file

@ -14,10 +14,6 @@ import net.minecraft.block.BlockSlab;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.statemap.IStateMapper;
import net.minecraft.client.renderer.block.statemap.StateMap;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
@ -270,10 +266,7 @@ public class ModBlocks
public static void registerBlockVariant(Block block, String stateName, int stateMeta)
{
Item item = Item.getItemFromBlock(block);
if (item != null && FMLCommonHandler.instance().getSide() == Side.CLIENT) {
ModelBakery.addVariantName(item, BiomesOPlenty.MOD_ID + ":" + stateName);
ModelLoader.setCustomModelResourceLocation(item, stateMeta, new ModelResourceLocation(BiomesOPlenty.MOD_ID + ":" + stateName, "inventory"));
}
BiomesOPlenty.proxy.registerItemVariantModel(item, stateName, stateMeta);
BOPCommand.blockCount++;
}
@ -296,13 +289,7 @@ public class ModBlocks
IBOPBlock bopBlock = (IBOPBlock)block;
GameRegistry.registerBlock(block, bopBlock.getItemClass(), blockName);
IProperty[] nonRenderingProperties = bopBlock.getNonRenderingProperties();
if (nonRenderingProperties != null)
{
// use a custom state mapper which will ignore the properties specified in the block as being non-rendering
IStateMapper custom_mapper = (new StateMap.Builder()).addPropertiesToIgnore(nonRenderingProperties).build();
ModelLoader.setCustomStateMapper(block, custom_mapper);
}
BiomesOPlenty.proxy.registerNonRenderingProperties(block);
// check for missing default states
IBlockState defaultState = block.getDefaultState();

View file

@ -77,7 +77,7 @@ public class GeneratorTypeAdaptor implements JsonSerializer<IGenerator>, JsonDes
}
catch (InstantiationException e)
{
throw new RuntimeException("Generators must have a no-args constructor!", e);
throw new RuntimeException("Generators must have a no-args constructor", e);
}
catch (IllegalAccessException e)
{
@ -85,6 +85,10 @@ public class GeneratorTypeAdaptor implements JsonSerializer<IGenerator>, JsonDes
}
}
}
else
{
throw new JsonSyntaxException("Entry missing generator property");
}
return null;
}

View file

@ -8,8 +8,17 @@
package biomesoplenty.core;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.renderer.block.statemap.IStateMapper;
import net.minecraft.client.renderer.block.statemap.StateMap;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.common.config.MiscConfigurationHandler;
@ -25,4 +34,31 @@ public class ClientProxy extends CommonProxy
//Entity rendering and other stuff will go here in future
}
@Override
public void registerItemVariantModel(Item item, String name, int metadata)
{
if (item != null)
{
ModelBakery.addVariantName(item, BiomesOPlenty.MOD_ID + ":" + name);
ModelLoader.setCustomModelResourceLocation(item, metadata, new ModelResourceLocation(BiomesOPlenty.MOD_ID + ":" + name, "inventory"));
}
}
@Override
public void registerNonRenderingProperties(Block block)
{
if (block instanceof IBOPBlock)
{
IBOPBlock bopBlock = (IBOPBlock)block;
IProperty[] nonRenderingProperties = bopBlock.getNonRenderingProperties();
if (nonRenderingProperties != null)
{
// use a custom state mapper which will ignore the properties specified in the block as being non-rendering
IStateMapper custom_mapper = (new StateMap.Builder()).addPropertiesToIgnore(nonRenderingProperties).build();
ModelLoader.setCustomStateMapper(block, custom_mapper);
}
}
}
}

View file

@ -8,8 +8,14 @@
package biomesoplenty.core;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
public class CommonProxy
{
public void registerRenderers() {}
public void registerItemVariantModel(Item item, String name, int metadata) {}
public void registerNonRenderingProperties(Block block) {}
}