From f4ea60ba2c85e7ccbf6beecbcd55a679fe675922 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Thu, 24 Dec 2015 03:04:16 -0600 Subject: [PATCH] IT WORKS --- MC18_notes.txt | 2 + .../api/render/SpecialFlowerModel.java | 47 ++++++++++--------- .../client/core/handler/ModelHandler.java | 9 +++- .../client/core/proxy/ClientProxy.java | 1 - .../common/block/BlockSpecialFlower.java | 19 ++++++++ .../assets/botania/blockstates/daybloom.json | 11 +++++ .../botania/blockstates/specialFlower.json | 2 +- 7 files changed, 66 insertions(+), 25 deletions(-) create mode 100644 src/main/resources/assets/botania/blockstates/daybloom.json diff --git a/MC18_notes.txt b/MC18_notes.txt index e08825fe5..3127dac58 100644 --- a/MC18_notes.txt +++ b/MC18_notes.txt @@ -9,6 +9,8 @@ Anyways, vanilla removed it from their method so we follow suit. * SubTileEntity's methods that are copied from block (onBlockadded, etc.) updated to match vanilla counterparts * Multiblock system reworked to use states and blockposes * Magnet blacklist still uses metas instead of states because they need to support the short maxvalue wildcard. +* Now includes a way for addons to pass the Botania loader the models they want to use to render their subtile with + * todo: possibly make the unlisted properties use the subtile string name instead of class. Will be much easier. -- Other -- * Most things left untouched to make patches from upstream easier diff --git a/src/main/java/vazkii/botania/api/render/SpecialFlowerModel.java b/src/main/java/vazkii/botania/api/render/SpecialFlowerModel.java index 5db3c3abe..98eaf22ed 100644 --- a/src/main/java/vazkii/botania/api/render/SpecialFlowerModel.java +++ b/src/main/java/vazkii/botania/api/render/SpecialFlowerModel.java @@ -42,20 +42,6 @@ import java.util.Map; public class SpecialFlowerModel implements IModelCustomData { - /** - * Internal implementation - **/ - // SpecialFlowerModel for when there are no models registered for a subtile - public static final SpecialFlowerModel INSTANCE = new SpecialFlowerModel(ImmutableMap.>, ModelResourceLocation>of()); - // Models registered from the externel API thus far - private static final Map, ModelResourceLocation> queuedModels = Maps.newHashMap(); - private final ImmutableMap>, ModelResourceLocation> models; - - - public SpecialFlowerModel(ImmutableMap>, ModelResourceLocation> models) { - this.models = models; - } - /** * Register your model for the given subtile class here. * Call this DURING PREINIT. Calling it anytime after models have already baked does not guarantee that your model will work. @@ -70,6 +56,21 @@ public class SpecialFlowerModel implements IModelCustomData { queuedModels.put(subTileClass, model); } + /** + * Internal implementation + **/ + // SpecialFlowerModel for when there are no models registered for a subtile + public static final SpecialFlowerModel INSTANCE = new SpecialFlowerModel(ImmutableMap.>, ModelResourceLocation>of()); + // Models registered from the externel API thus far + private static final Map, ModelResourceLocation> queuedModels = Maps.newHashMap(); + + + private final ImmutableMap>, ModelResourceLocation> models; + + public SpecialFlowerModel(ImmutableMap>, ModelResourceLocation> models) { + this.models = models; + } + @Override public Collection getDependencies() { return ImmutableList.copyOf(models.values()); @@ -125,8 +126,10 @@ public class SpecialFlowerModel implements IModelCustomData { @Override public boolean accepts(ResourceLocation modelLocation) { - return "botania_SPECIAL".equals(modelLocation.getResourceDomain()) - && "specialFlower".equals(modelLocation.getResourcePath()); + return modelLocation.getResourceDomain().equals("botania_special") && ( + modelLocation.getResourcePath().equals("specialFlower") || + modelLocation.getResourcePath().equals("models/block/specialFlower") || + modelLocation.getResourcePath().equals("models/item/specialFlower")); } @Override @@ -154,7 +157,8 @@ public class SpecialFlowerModel implements IModelCustomData { } private void refreshBakedModels() { - if (baseModel == null) { + System.out.println("Refreshing"); + //if (baseModel == null) { ModelManager manager = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager(); baseModel = getModel(manager, Optional.>absent()); @@ -173,11 +177,11 @@ public class SpecialFlowerModel implements IModelCustomData { quadBuilder.put(Optional.of(side), buildQuads(Optional.of(side))); } quads = quadBuilder.build(); - } + //} } - private IBakedModel getModel(ModelManager manager, Optional> layer) { - ModelResourceLocation loc = models.get(layer); + private IBakedModel getModel(ModelManager manager, Optional> optClazz) { + ModelResourceLocation loc = models.get(optClazz); if (loc == null) { loc = new ModelResourceLocation("builtin/missing", "missing"); } @@ -205,7 +209,7 @@ public class SpecialFlowerModel implements IModelCustomData { @Override public List getGeneralQuads() { refreshBakedModels(); - return quads.get(Optional.absent()); + return quads.get(Optional.absent()); } @Override @@ -239,6 +243,7 @@ public class SpecialFlowerModel implements IModelCustomData { @Override public IBakedModel handleBlockState(IBlockState state) { + refreshBakedModels(); IExtendedBlockState extendedState = ((IExtendedBlockState) state); Class clazz = extendedState.getValue(BotaniaStateProps.SUBTILE_CLASS); return bakedFlowerModels.get(clazz); diff --git a/src/main/java/vazkii/botania/client/core/handler/ModelHandler.java b/src/main/java/vazkii/botania/client/core/handler/ModelHandler.java index 6f77d006d..edfa5e407 100644 --- a/src/main/java/vazkii/botania/client/core/handler/ModelHandler.java +++ b/src/main/java/vazkii/botania/client/core/handler/ModelHandler.java @@ -11,8 +11,10 @@ import net.minecraft.item.EnumDyeColor; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.client.model.ModelLoaderRegistry; import net.minecraftforge.client.model.obj.OBJLoader; import net.minecraftforge.fml.common.registry.GameData; +import vazkii.botania.api.render.SpecialFlowerModel; import vazkii.botania.api.state.BotaniaStateProps; import vazkii.botania.api.state.enums.AltGrassVariant; import vazkii.botania.api.state.enums.LivingRockVariant; @@ -21,6 +23,7 @@ import vazkii.botania.api.state.enums.StorageVariant; import vazkii.botania.common.block.ModBlocks; import vazkii.botania.common.block.ModFluffBlocks; import vazkii.botania.common.block.decor.slabs.BlockModSlab; +import vazkii.botania.common.block.subtile.generating.SubTileDaybloom; import vazkii.botania.common.item.ItemGaiaHead; import vazkii.botania.common.lib.LibItemNames; import vazkii.botania.common.lib.LibMisc; @@ -36,8 +39,11 @@ public final class ModelHandler { // In addition, many of the jsons currently use the vanilla format (simple and verified bug-free). // Once things settle down, we'll move to forge jsons, which will drastically cut down on the number of json files public static void registerModels() { + ModelLoaderRegistry.registerLoader(SpecialFlowerModel.Loader.INSTANCE); OBJLoader.instance.addDomain(LibMisc.MOD_ID.toLowerCase(Locale.ROOT)); + SpecialFlowerModel.register(SubTileDaybloom.class, new ModelResourceLocation("botania:daybloom")); + /** Custom statemappers **/ registerStateMappers(); @@ -129,8 +135,7 @@ public final class ModelHandler { // Ignore redstone power state in some blocks ModelLoader.setCustomStateMapper(ModBlocks.starfield, (new StateMap.Builder()).ignore(BotaniaStateProps.POWERED).build()); - // Ignore color in special flower, unstable cube, mana beacon, and petals (handled by color multiplier) - ModelLoader.setCustomStateMapper(ModBlocks.specialFlower, (new StateMap.Builder()).ignore(BotaniaStateProps.COLOR).build()); + // Ignore color in unstable cube, mana beacon, and petals (handled by color multiplier) ModelLoader.setCustomStateMapper(ModBlocks.unstableBlock, (new StateMap.Builder()).ignore(BotaniaStateProps.COLOR).build()); ModelLoader.setCustomStateMapper(ModBlocks.manaBeacon, (new StateMap.Builder()).ignore(BotaniaStateProps.COLOR).build()); ModelLoader.setCustomStateMapper(ModBlocks.petalBlock, (new StateMap.Builder()).ignore(BotaniaStateProps.COLOR).build()); diff --git a/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java b/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java index 13a9aaabd..9e9c24c24 100644 --- a/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java +++ b/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java @@ -182,7 +182,6 @@ public class ClientProxy extends CommonProxy { super.preInit(event); - ModelLoaderRegistry.registerLoader(SpecialFlowerModel.Loader.INSTANCE); ModelHandler.registerModels(); } diff --git a/src/main/java/vazkii/botania/common/block/BlockSpecialFlower.java b/src/main/java/vazkii/botania/common/block/BlockSpecialFlower.java index f577bae6d..d77c7e5ca 100644 --- a/src/main/java/vazkii/botania/common/block/BlockSpecialFlower.java +++ b/src/main/java/vazkii/botania/common/block/BlockSpecialFlower.java @@ -22,6 +22,8 @@ import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.block.statemap.DefaultStateMapper; +import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -35,9 +37,14 @@ import net.minecraft.util.EnumWorldBlockLayer; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.client.event.ModelBakeEvent; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.property.ExtendedBlockState; import net.minecraftforge.common.property.IExtendedBlockState; import net.minecraftforge.common.property.IUnlistedProperty; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; import vazkii.botania.api.BotaniaAPI; import vazkii.botania.api.state.BotaniaStateProps; import vazkii.botania.api.lexicon.ILexiconable; @@ -121,6 +128,18 @@ public class BlockSpecialFlower extends BlockFlower implements ITileEntityProvid .withProperty(BotaniaStateProps.SUBTILE_CLASS, SubTileDaybloom.class) .withProperty(BotaniaStateProps.COLOR, EnumDyeColor.WHITE).withProperty(type, EnumFlowerType.POPPY) ); + MinecraftForge.EVENT_BUS.register(this); + } + + @SubscribeEvent + @SideOnly(Side.CLIENT) + public void onModelBake(ModelBakeEvent evt) { + evt.modelManager.getBlockModelShapes().registerBlockWithStateMapper(this, new DefaultStateMapper() { + @Override + public ModelResourceLocation getModelResourceLocation(IBlockState state) { + return new ModelResourceLocation("botania:specialFlower"); + } + }); } @Override diff --git a/src/main/resources/assets/botania/blockstates/daybloom.json b/src/main/resources/assets/botania/blockstates/daybloom.json new file mode 100644 index 000000000..0e618b004 --- /dev/null +++ b/src/main/resources/assets/botania/blockstates/daybloom.json @@ -0,0 +1,11 @@ +{ + "forge_marker": 1, + "variants": { + "normal": [{ + "model": "minecraft:cross", + "textures": { + "cross": "botania:blocks/daybloom" + } + }] + } +} \ No newline at end of file diff --git a/src/main/resources/assets/botania/blockstates/specialFlower.json b/src/main/resources/assets/botania/blockstates/specialFlower.json index 5ea130c75..281ffbc7c 100644 --- a/src/main/resources/assets/botania/blockstates/specialFlower.json +++ b/src/main/resources/assets/botania/blockstates/specialFlower.json @@ -1,7 +1,7 @@ { "forge_marker": 1, "defaults": { - "model": "botania_SPECIAL:specialFlower", + "model": "botania_special:specialFlower", "transform": "forge:default-block" }, "variants": {