Done with floating flowers completely. Can't get the spinning right though.

This commit is contained in:
Vincent Lee committed 2015-12-29 14:45:50 -06:00
1 parent 3aef9efe8b
commit 5a630fbf39
6 files changed
+160 -45

No files matched your search

@@ -47,10 +47,6 @@ public class BotaniaStateProps {
// The axis directions (think quartz pillars and wood logs)
public static final PropertyEnum<EnumFacing.Axis> AXIS_FACING = BlockRotatedPillar.AXIS;
// Island type (floating flowers)
// TODO !!!! MOVE TYPE "ISLANDTYPE" INTO API
public static final PropertyEnum ISLAND_TYPE = PropertyEnum.create("islandtype", IFloatingFlower.IslandType.class);
// Extra Quartz Blocks
public static final PropertyEnum<QuartzVariant> QUARTZ_VARIANT = PropertyEnum.create("variant", QuartzVariant.class);
@@ -9,9 +9,11 @@ import net.minecraft.block.BlockRailPowered;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.BlockWall;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.statemap.StateMap;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.client.resources.IReloadableResourceManager;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
@@ -38,6 +40,7 @@ import vazkii.botania.api.state.enums.LivingWoodVariant;
import vazkii.botania.api.state.enums.PrismarineVariant;
import vazkii.botania.api.state.enums.PylonVariant;
import vazkii.botania.api.state.enums.StorageVariant;
import vazkii.botania.client.model.FloatingFlowerModel;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.block.ModFluffBlocks;
import vazkii.botania.common.block.decor.slabs.BlockModSlab;
@@ -106,6 +109,7 @@ public final class ModelHandler {
public static void registerModels() {
ModelLoaderRegistry.registerLoader(SpecialFlowerModel.Loader.INSTANCE);
OBJLoader.instance.addDomain(LibMisc.MOD_ID.toLowerCase(Locale.ROOT));
((IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()).registerReloadListener(FloatingFlowerModel.INSTANCE);
/** Subtile block models **/
registerSubtiles();
@@ -303,6 +307,8 @@ public final class ModelHandler {
registerItemModel(ModBlocks.redStringRelay);
registerItemModel(ModBlocks.floatingSpecialFlower);
registerItemModelAllMeta(Item.getItemFromBlock(ModBlocks.floatingFlower), EnumDyeColor.values().length);
// Item models which all use the same base model and recolored by render layer
registerItemModelAllMeta(Item.getItemFromBlock(ModBlocks.unstableBlock), EnumDyeColor.values().length);
@@ -529,6 +535,13 @@ public final class ModelHandler {
}
});
ModelLoader.setCustomStateMapper(ModBlocks.floatingFlower, new StateMapperBase() {
@Override
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
return new ModelResourceLocation("botania:miniIsland", "normal");
}
});
// Ignore vanilla facing, variant in double flower
ModelLoader.setCustomStateMapper(ModBlocks.doubleFlower1, (new StateMap.Builder()).ignore(BlockDoublePlant.VARIANT, BlockDoublePlant.field_181084_N).build());
ModelLoader.setCustomStateMapper(ModBlocks.doubleFlower2, (new StateMap.Builder()).ignore(BlockDoublePlant.VARIANT, BlockDoublePlant.field_181084_N).build());
@@ -1,8 +1,12 @@
package vazkii.botania.client.model;
import com.google.common.base.Function;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.Table;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
@@ -10,6 +14,8 @@ import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.resources.model.ModelResourceLocation;
@@ -22,43 +28,87 @@ import net.minecraftforge.client.model.pipeline.IVertexConsumer;
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
import net.minecraftforge.client.model.pipeline.VertexTransformer;
import net.minecraftforge.common.property.IExtendedBlockState;
import org.apache.commons.lang3.tuple.Pair;
import vazkii.botania.api.state.BotaniaStateProps;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.block.decor.BlockFloatingFlower;
import vazkii.botania.common.block.decor.IFloatingFlower;
import vazkii.botania.common.item.block.ItemBlockFloatingSpecialFlower;
import vazkii.botania.common.item.block.ItemBlockSpecialFlower;
import javax.annotation.Nullable;
import javax.vecmath.Vector3f;
import javax.vecmath.Vector4f;
import java.util.List;
import java.util.Map;
public class FloatingFlowerModel implements ISmartItemModel, ISmartBlockModel {
public class FloatingFlowerModel implements ISmartItemModel, ISmartBlockModel, IResourceManagerReloadListener {
public static final FloatingFlowerModel INSTANCE = new FloatingFlowerModel();
private static Table<IFloatingFlower.IslandType, String, CompositeBakedModel> CACHE = HashBasedTable.create();
private static final String MUNDANE_PREFIX = "botania:shimmeringFlower_";
@Override
public void onResourceManagerReload(IResourceManager resourceManager) {
CACHE.clear();
}
@Override
public IBakedModel handleItemState(ItemStack stack) {
ModelManager modelManager = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager();
// Items always have GRASS island
IFloatingFlower.IslandType islandType = IFloatingFlower.IslandType.GRASS;
String identifier;
// Item form always has island type grass.
IBakedModel islandType = modelManager.getModel(new ModelResourceLocation("botania:miniIsland", "variant=grass"));
if (Block.getBlockFromItem(stack.getItem()) == ModBlocks.floatingSpecialFlower) {
// Magic flower
identifier = ItemBlockFloatingSpecialFlower.getType(stack);
} else {
// Mundane flower
identifier = MUNDANE_PREFIX + stack.getItemDamage();
}
IBakedModel flowerModel = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(ItemBlockSpecialFlower.ofType(ItemBlockFloatingSpecialFlower.getType(stack)));
return new CompositeBakedModel(flowerModel, islandType);
return getModel(islandType, identifier);
}
@Override
public IBakedModel handleBlockState(IBlockState state) {
IExtendedBlockState realState = ((IExtendedBlockState) state);
IFloatingFlower.IslandType islandType = state.getValue(BlockFloatingFlower.ISLAND_TYPE);
String identifier;
if (state.getBlock() == ModBlocks.floatingSpecialFlower) {
// Magic flower
IExtendedBlockState realState = ((IExtendedBlockState) state);
identifier = realState.getValue(BotaniaStateProps.SUBTILE_ID);
} else {
// Mundane flower
identifier = MUNDANE_PREFIX + state.getValue(BotaniaStateProps.COLOR).getMetadata();
}
return getModel(islandType, identifier);
}
private CompositeBakedModel getModel(IFloatingFlower.IslandType islandType, String identifier) {
ModelManager modelManager = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager();
// Item form always has island type grass.
IBakedModel islandType = modelManager.getModel(new ModelResourceLocation("botania:miniIsland", "variant=" + ((IFloatingFlower.IslandType) realState.getValue(BotaniaStateProps.ISLAND_TYPE)).getName()));
if (CACHE.contains(islandType, identifier)) {
return CACHE.get(islandType, identifier);
} else {
IBakedModel islandModel = modelManager.getModel(new ModelResourceLocation("botania:miniIsland", "variant=" + islandType.getName()));
IBakedModel flowerModel;
IBakedModel flowerModel = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(ItemBlockSpecialFlower.ofType(realState.getValue(BotaniaStateProps.SUBTILE_ID)));
if (identifier.startsWith(MUNDANE_PREFIX)) {
int meta = Integer.parseInt(identifier.substring(identifier.indexOf(MUNDANE_PREFIX) + MUNDANE_PREFIX.length()));
flowerModel = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(new ItemStack(ModBlocks.shinyFlower, 1, meta));
} else {
flowerModel = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(ItemBlockSpecialFlower.ofType(identifier));
}
return new CompositeBakedModel(flowerModel, islandType);
// Enhance!
CompositeBakedModel model = new CompositeBakedModel(flowerModel, islandModel);
System.out.println("Recreated model");
CACHE.put(islandType, identifier, model);
return model;
}
}
protected static BakedQuad transform(BakedQuad quad, final TRSRTransformation transform) {
@@ -44,14 +44,15 @@ public class RenderTileFloatingFlower extends TileEntitySpecialRenderer {
IFloatingFlower flower = (IFloatingFlower) tile;
GlStateManager.pushMatrix();
GlStateManager.color(1F, 1F, 1F, 1F);
GlStateManager.translate(d0, d1, d2);
GlStateManager.translate(d0, d1, d2 + 1);
double worldTime = tile.getWorld() == null ? 0 : (double) (ClientTickHandler.ticksInGame + t);
if(tile.getWorld() != null)
worldTime += new Random(tile.getPos().hashCode()).nextInt(1000);
GlStateManager.translate(0.5F, 0F, 0.5F);
GlStateManager.rotate(-((float) worldTime * 0.5F), 0F, 1F, 0F);
// todo 1.8.8 fix spin
//GlStateManager.rotate(-((float) worldTime * 0.5F), 0F, 1F, 0F);
GlStateManager.translate(-0.5F, 0F, -0.5F);
if(tile.getWorld() != null) {
@@ -72,35 +72,14 @@ public class BlockFloatingSpecialFlower extends BlockFloatingFlower implements I
RecipeSorter.register("botania:floatingSpecialFlower", SpecialFloatingFlowerRecipe.class, Category.SHAPELESS, "");
setDefaultState(((IExtendedBlockState) blockState.getBaseState())
.withProperty(BotaniaStateProps.SUBTILE_ID, "daybloom")
.withProperty(BotaniaStateProps.ISLAND_TYPE, IFloatingFlower.IslandType.GRASS)
.withProperty(BotaniaStateProps.COLOR, EnumDyeColor.WHITE));
.withProperty(BotaniaStateProps.COLOR, EnumDyeColor.WHITE)
.withProperty(ISLAND_TYPE, IFloatingFlower.IslandType.GRASS));
MinecraftForge.EVENT_BUS.register(this);
}
@Override
public int getRenderType() {
return 2; // todo
}
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onModelBake(ModelBakeEvent evt) {
evt.modelRegistry.putObject(new ModelResourceLocation("botania:floatingSpecialFlower", "normal"), FloatingFlowerModel.INSTANCE);
evt.modelRegistry.putObject(new ModelResourceLocation("botania:floatingSpecialFlower", "inventory"), FloatingFlowerModel.INSTANCE);
}
@Override
public BlockState createBlockState() {
return new ExtendedBlockState(this, new IProperty[] {BotaniaStateProps.ISLAND_TYPE, BotaniaStateProps.COLOR}, new IUnlistedProperty[] {BotaniaStateProps.SUBTILE_ID});
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileFloatingSpecialFlower) {
state = state.withProperty(BotaniaStateProps.ISLAND_TYPE, ((TileFloatingSpecialFlower) te).getIslandType());
}
return state;
return new ExtendedBlockState(this, new IProperty[] { ISLAND_TYPE, BotaniaStateProps.COLOR }, new IUnlistedProperty[] { BotaniaStateProps.SUBTILE_ID });
}
@Override
@@ -15,9 +15,17 @@ import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.particle.EntityDiggingFX;
import net.minecraft.client.resources.FallbackResourceManager;
import net.minecraft.client.resources.IReloadableResourceManager;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
@@ -28,19 +36,27 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import thaumcraft.api.crafting.IInfusionStabiliser;
import vazkii.botania.api.internal.VanillaPacketDispatcher;
import vazkii.botania.api.lexicon.ILexiconable;
import vazkii.botania.api.lexicon.LexiconEntry;
import vazkii.botania.api.state.BotaniaStateProps;
import vazkii.botania.client.lib.LibRenderIDs;
import vazkii.botania.client.model.FloatingFlowerModel;
import vazkii.botania.common.Botania;
import vazkii.botania.common.block.BlockModContainer;
import vazkii.botania.common.block.decor.IFloatingFlower.IslandType;
import vazkii.botania.common.block.tile.TileFloatingFlower;
import vazkii.botania.common.block.tile.TileFloatingSpecialFlower;
import vazkii.botania.common.core.handler.ConfigHandler;
import vazkii.botania.common.integration.coloredlights.ColoredLightHelper;
import vazkii.botania.common.item.ItemGrassSeeds;
@@ -54,6 +70,10 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
@Optional.Interface(modid = "Thaumcraft", iface = "thaumcraft.api.crafting.IInfusionStabiliser", striprefs = true)
public class BlockFloatingFlower extends BlockModContainer implements ILexiconable, IInfusionStabiliser {
// Island type (floating flowers)
// Not in BotaniaStateProps so we don't have to bundle IslandType in the API
public static final PropertyEnum<IslandType> ISLAND_TYPE = PropertyEnum.create("islandtype", IFloatingFlower.IslandType.class);
public BlockFloatingFlower() {
this(LibBlockNames.MINI_ISLAND);
}
@@ -67,7 +87,9 @@ public class BlockFloatingFlower extends BlockModContainer implements ILexiconab
float f = 0.1F;
setBlockBounds(f, f, f, 1F - f, 1F - f, 1F - f);
setDefaultState(blockState.getBaseState().withProperty(BotaniaStateProps.COLOR, EnumDyeColor.WHITE));
setDefaultState(blockState.getBaseState()
.withProperty(BotaniaStateProps.COLOR, EnumDyeColor.WHITE)
.withProperty(ISLAND_TYPE, IFloatingFlower.IslandType.GRASS));
}
@Override
@@ -75,9 +97,18 @@ public class BlockFloatingFlower extends BlockModContainer implements ILexiconab
return 2;
}
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onModelBake(ModelBakeEvent evt) {
evt.modelRegistry.putObject(new ModelResourceLocation("botania:miniIsland", "normal"), FloatingFlowerModel.INSTANCE);
evt.modelRegistry.putObject(new ModelResourceLocation("botania:miniIsland", "inventory"), FloatingFlowerModel.INSTANCE);
evt.modelRegistry.putObject(new ModelResourceLocation("botania:floatingSpecialFlower", "normal"), FloatingFlowerModel.INSTANCE);
evt.modelRegistry.putObject(new ModelResourceLocation("botania:floatingSpecialFlower", "inventory"), FloatingFlowerModel.INSTANCE);
}
@Override
public BlockState createBlockState() {
return new BlockState(this, BotaniaStateProps.COLOR);
return new BlockState(this, BotaniaStateProps.COLOR, ISLAND_TYPE);
}
@Override
@@ -93,6 +124,51 @@ public class BlockFloatingFlower extends BlockModContainer implements ILexiconab
return getDefaultState().withProperty(BotaniaStateProps.COLOR, EnumDyeColor.byMetadata(meta));
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileFloatingFlower) {
state = state.withProperty(ISLAND_TYPE, ((TileFloatingFlower) te).getIslandType());
} else if (te instanceof TileFloatingSpecialFlower) {
state = state.withProperty(ISLAND_TYPE, ((TileFloatingSpecialFlower) te).getIslandType());
}
return state;
}
@Override
public boolean addLandingEffects(net.minecraft.world.WorldServer worldObj, BlockPos blockPosition, IBlockState iblockstate, EntityLivingBase entity, int numberOfParticles) {
float f = (float) MathHelper.ceiling_float_int(entity.fallDistance - 3.0F);
double d0 = (double)Math.min(0.2F + f / 15.0F, 10.0F);
if (d0 > 2.5D) {
d0 = 2.5D;
}
int i = (int)(150.0D * d0);
worldObj.spawnParticle(EnumParticleTypes.BLOCK_DUST, entity.posX, entity.posY, entity.posZ, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, Block.getStateId(Blocks.dirt.getDefaultState()));
return true;
}
@Override
@SideOnly(Side.CLIENT)
public boolean addDestroyEffects(World world, BlockPos pos, EffectRenderer effectRenderer) {
if (world.getBlockState(pos).getBlock() == this) {
int i = 4;
EntityDiggingFX.Factory factory = new EntityDiggingFX.Factory();
for (int j = 0; j < i; ++j) {
for (int k = 0; k < i; ++k) {
for (int l = 0; l < i; ++l) {
double d0 = (double)pos.getX() + ((double)j + 0.5D) / (double)i;
double d1 = (double)pos.getY() + ((double)k + 0.5D) / (double)i;
double d2 = (double)pos.getZ() + ((double)l + 0.5D) / (double)i;
effectRenderer.addEffect(factory.getEntityFX(-1, world, d0, d1, d2, d0 - (double)pos.getX() - 0.5D, d1 - (double)pos.getY() - 0.5D, d2 - (double)pos.getZ() - 0.5D, Block.getStateId(Blocks.dirt.getDefaultState())));
}
}
}
return true;
} else {
return false;
}
}
@Override
@Optional.Method(modid = "easycoloredlights")
public int getLightValue(IBlockAccess world, BlockPos pos) {