Flowering leaves no longer render as white boxes. Closes #696
This commit is contained in:
parent
0be9d68225
commit
c05ba789f5
6 changed files with 82 additions and 138 deletions
|
@ -1,87 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright 2014-2016, the Biomes O' Plenty Team
|
|
||||||
*
|
|
||||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
|
||||||
*
|
|
||||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
package biomesoplenty.client.model;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
|
|
||||||
import biomesoplenty.client.util.ModelUtils;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
|
||||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
|
||||||
import net.minecraft.client.renderer.block.model.ItemOverride;
|
|
||||||
import net.minecraft.client.renderer.block.model.ItemOverrideList;
|
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.client.model.IModel;
|
|
||||||
|
|
||||||
public class ModelBiomeFinder extends ItemOverrideList
|
|
||||||
{
|
|
||||||
private IBakedModel[] frames;
|
|
||||||
|
|
||||||
public ModelBiomeFinder(IModel defaultModel, TextureAtlasSprite[] frameTextures)
|
|
||||||
{
|
|
||||||
super(ImmutableList.<ItemOverride>of());
|
|
||||||
|
|
||||||
this.frames = ModelUtils.generateModelsForTextures(defaultModel, frameTextures);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity)
|
|
||||||
{
|
|
||||||
EntityPlayerSP player = Minecraft.getMinecraft().player;
|
|
||||||
if (player == null) {return this.frames[0];}
|
|
||||||
|
|
||||||
NBTTagCompound nbt = stack.getTagCompound();
|
|
||||||
if (nbt != null && nbt.hasKey("biomeIDToFind"))
|
|
||||||
{
|
|
||||||
if (nbt.hasKey("searchStarted"))
|
|
||||||
{
|
|
||||||
// searching for biome, but not yet found indicate searching by flashing
|
|
||||||
return this.getFlashingFrame(player);
|
|
||||||
}
|
|
||||||
else if (nbt.getBoolean("found"))
|
|
||||||
{
|
|
||||||
// if the biome has been found, point at it
|
|
||||||
int posX = nbt.getInteger("posX");
|
|
||||||
int posZ = nbt.getInteger("posZ");
|
|
||||||
return getFrameForPositionRelativeToPlayer(player, posX, posZ);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// the search has not yet been started, show all sectors lit
|
|
||||||
return this.frames[9];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// if we've got here, the biome finder has not been bound to a biome yet - show no sectors lit
|
|
||||||
return this.frames[8];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IBakedModel getFlashingFrame(EntityPlayerSP player)
|
|
||||||
{
|
|
||||||
return (player.getRNG().nextInt(2) == 0 ? this.frames[10] : this.frames[11]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IBakedModel getFrameForPositionRelativeToPlayer(EntityPlayer player, int biomePosX, int biomePosZ)
|
|
||||||
{
|
|
||||||
double xDiff = (double)biomePosX - player.posX;
|
|
||||||
double zDiff = (double)biomePosZ - player.posZ;
|
|
||||||
// angle (in degrees) of direction from player to biome (relative to player rotation)
|
|
||||||
double angleDiff = (Math.atan2(zDiff, xDiff) * 180.0D / Math.PI) + 270.0D - player.rotationYaw;
|
|
||||||
// there are 8 sectors on the biome finder, so 45 degrees each (offset by 22.5 to center the angle in the middle of the sector)
|
|
||||||
int sector = (int)Math.floor((angleDiff + 22.5D) / 45.0D);
|
|
||||||
return this.frames[((sector % 8) + 8) % 8];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright 2016, the Biomes O' Plenty Team
|
|
||||||
*
|
|
||||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
|
||||||
*
|
|
||||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
package biomesoplenty.client.model;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
|
|
||||||
import biomesoplenty.common.inventory.InventoryFlowerBasket;
|
|
||||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
|
||||||
import net.minecraft.client.renderer.block.model.ItemOverride;
|
|
||||||
import net.minecraft.client.renderer.block.model.ItemOverrideList;
|
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
public class ModelFlowerBasket extends ItemOverrideList
|
|
||||||
{
|
|
||||||
private IBakedModel emptyBakedModel;
|
|
||||||
private IBakedModel filledBakedModel;
|
|
||||||
|
|
||||||
public ModelFlowerBasket(IBakedModel emptyModel, IBakedModel filledModel)
|
|
||||||
{
|
|
||||||
super(ImmutableList.<ItemOverride>of());
|
|
||||||
|
|
||||||
this.emptyBakedModel = emptyModel;
|
|
||||||
this.filledBakedModel = filledModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity)
|
|
||||||
{
|
|
||||||
InventoryFlowerBasket inventory = new InventoryFlowerBasket(stack, null);
|
|
||||||
boolean filled = false;
|
|
||||||
|
|
||||||
for (int index = 0; index < inventory.getSizeInventory(); ++index)
|
|
||||||
{
|
|
||||||
if (inventory.getStackInSlot(index) != null)
|
|
||||||
{
|
|
||||||
filled = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return filled ? this.filledBakedModel : this.emptyBakedModel;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright 2016, the Biomes O' Plenty Team
|
||||||
|
*
|
||||||
|
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||||
|
*
|
||||||
|
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||||
|
******************************************************************************/
|
||||||
|
package biomesoplenty.common.handler;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||||
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||||
|
import net.minecraft.client.renderer.block.model.SimpleBakedModel;
|
||||||
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.registry.IRegistry;
|
||||||
|
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||||
|
import net.minecraftforge.client.model.IModel;
|
||||||
|
import net.minecraftforge.client.model.ModelLoader;
|
||||||
|
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class LeavesModelHandler
|
||||||
|
{
|
||||||
|
private static final ModelResourceLocation LEAVES_LOC = new ModelResourceLocation("biomesoplenty:leaves_3", "variant=flowering");
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onModelBake(ModelBakeEvent event) throws Exception
|
||||||
|
{
|
||||||
|
ModelLoader loader = event.getModelLoader();
|
||||||
|
IRegistry<ModelResourceLocation, IBakedModel> registry = event.getModelRegistry();
|
||||||
|
IBakedModel originalBakedModel = registry.getObject(LEAVES_LOC);
|
||||||
|
|
||||||
|
// Load and bake the fast flowering leaves model
|
||||||
|
IModel fastModel = ModelLoaderRegistry.getModel(new ResourceLocation("biomesoplenty:block/flowering_leaves_fast"));
|
||||||
|
IBakedModel bakedFastModel = fastModel.bake(fastModel.getDefaultState(), DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter());
|
||||||
|
|
||||||
|
registry.putObject(LEAVES_LOC, new ModelLeaves(originalBakedModel, bakedFastModel));
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ModelLeaves extends SimpleBakedModel
|
||||||
|
{
|
||||||
|
private IBakedModel fastModel;
|
||||||
|
|
||||||
|
public ModelLeaves(IBakedModel fancyModel, IBakedModel fastModel)
|
||||||
|
{
|
||||||
|
super(fancyModel.getQuads(null, null, 0), generateFacingQuads(fancyModel), fancyModel.isAmbientOcclusion(), fancyModel.isGui3d(), fancyModel.getParticleTexture(), fancyModel.getItemCameraTransforms(), fancyModel.getOverrides());
|
||||||
|
this.fastModel = fastModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
|
||||||
|
{
|
||||||
|
return Blocks.LEAVES.isOpaqueCube(null) ? fastModel.getQuads(state, side, rand) : super.getQuads(state, side, rand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<EnumFacing, List<BakedQuad>> generateFacingQuads(IBakedModel model)
|
||||||
|
{
|
||||||
|
Map<EnumFacing, List<BakedQuad>> faceQuads = Maps.newEnumMap(EnumFacing.class);
|
||||||
|
for (EnumFacing facing : EnumFacing.values())
|
||||||
|
{
|
||||||
|
faceQuads.put(facing, model.getQuads(null, facing, 0));
|
||||||
|
}
|
||||||
|
return faceQuads;
|
||||||
|
}
|
||||||
|
}
|
|
@ -53,5 +53,6 @@ public class ModHandlers
|
||||||
{
|
{
|
||||||
MinecraftForge.EVENT_BUS.register(new GuiEventHandler());
|
MinecraftForge.EVENT_BUS.register(new GuiEventHandler());
|
||||||
MinecraftForge.EVENT_BUS.register(new TrailsEventHandler());
|
MinecraftForge.EVENT_BUS.register(new TrailsEventHandler());
|
||||||
|
MinecraftForge.EVENT_BUS.register(new LeavesModelHandler());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "block/leaves",
|
||||||
|
"textures": {
|
||||||
|
"all": "biomesoplenty:blocks/leaves_flowering_fast"
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 632 B |
Loading…
Reference in a new issue