Add waterlily variants

This commit is contained in:
Cheeserolls 2015-03-26 14:40:42 +00:00
parent e34ff058be
commit f55f08680c
14 changed files with 408 additions and 0 deletions

View file

@ -32,4 +32,5 @@ public class BOPBlocks
public static Block turnip_block;
public static Block flesh;
public static Block grass;
public static Block waterlily;
}

View file

@ -0,0 +1,194 @@
/*******************************************************************************
* Copyright 2014, 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.block;
import java.util.List;
import biomesoplenty.api.block.BOPPlant;
import biomesoplenty.common.item.ItemBOPLilypad;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityBoat;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.IStringSerializable;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockBOPLilypad extends BOPPlant implements IPlantable
{
public static final PropertyEnum VARIANT_PROP = PropertyEnum.create("variant", LilypadType.class);
public BlockBOPLilypad()
{
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, LilypadType.MEDIUM));
float f = 0.5F;
float f1 = 0.015625F;
this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f);
}
// need to use a custom item class because of the unique way lilies are placed
@Override
public Class<? extends ItemBlock> getItemClass() {
return ItemBOPLilypad.class;
}
// lilies should always be in the centre of the water block
@Override
public Block.EnumOffsetType getOffsetType()
{
return Block.EnumOffsetType.NONE;
}
@Override
public IBlockState getStateFromMeta(int meta)
{
// only one property to worry about, the variant, so just map [0 => MEDIUM, 1 => SMALL, 2 => TINY]
return this.getDefaultState().withProperty(VARIANT_PROP, LilypadType.values()[meta]);
}
@Override
public int getMetaFromState(IBlockState state)
{
// only one property to worry about, the variant, so just map [0 => MEDIUM, 1 => SMALL, 2 => TINY]
return ((LilypadType) state.getValue(VARIANT_PROP)).ordinal();
}
@Override
protected BlockState createBlockState()
{
return new BlockState(this, new IProperty[] { VARIANT_PROP });
}
@Override
public IProperty[] getPresetProperties()
{
return new IProperty[] { VARIANT_PROP };
}
@Override
public String getStateName(IBlockState state, boolean fullName)
{
return ((LilypadType) state.getValue(VARIANT_PROP)).getName();
}
// copied from vanilla BlockLilyPad
// boats can go through lily pads
@Override
public void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List list, Entity collidingEntity)
{
if (collidingEntity == null || !(collidingEntity instanceof EntityBoat))
{
super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
}
}
// copied from vanilla BlockLilyPad
@Override
public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
{
return new AxisAlignedBB((double)pos.getX() + this.minX, (double)pos.getY() + this.minY, (double)pos.getZ() + this.minZ, (double)pos.getX() + this.maxX, (double)pos.getY() + this.maxY, (double)pos.getZ() + this.maxZ);
}
// copied from vanilla BlockLilyPad
@Override
@SideOnly(Side.CLIENT)
public int getBlockColor()
{
return 7455580;
}
// copied from vanilla BlockLilyPad
@Override
@SideOnly(Side.CLIENT)
public int getRenderColor(IBlockState state)
{
return 7455580;
}
// copied from vanilla BlockLilyPad
@Override
@SideOnly(Side.CLIENT)
public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
{
return 2129968;
}
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
Boolean y1 = super.canPlaceBlockAt(worldIn, pos);
Boolean y2 = worldIn.getBlockState(pos.down()).getBlock().canSustainPlant(worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
return y1 && y2;
//return super.canPlaceBlockAt(worldIn, pos) && worldIn.getBlockState(pos.down()).getBlock().canSustainPlant(worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
}
@Override
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
{
if (pos.getY() >= 0 && pos.getY() < 256)
{
IBlockState iblockstate1 = worldIn.getBlockState(pos.down());
return iblockstate1.getBlock().getMaterial() == Material.water && ((Integer)iblockstate1.getValue(BlockLiquid.LEVEL)).intValue() == 0;
}
else
{
return false;
}
}
@Override
// This will stop it being placed on anything except water
public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos) {
return EnumPlantType.Water;
}
// enum representing the 3 variants of lily
public static enum LilypadType implements IStringSerializable
{
MEDIUM, SMALL, TINY;
@Override
public String getName()
{
return "lily_" + this.name().toLowerCase();
}
@Override
public String toString()
{
return getName();
}
}
// TODO: copied from BlockBush - not sure exactly what this does... investigate further - possibly put into base class
@Override
public IBlockState getPlant(net.minecraft.world.IBlockAccess world, BlockPos pos)
{
IBlockState state = world.getBlockState(pos);
if (state.getBlock() != this) return getDefaultState();
return state;
}
}

View file

@ -19,6 +19,7 @@ import biomesoplenty.common.block.BlockAsh;
import biomesoplenty.common.block.BlockBOPFlower;
import biomesoplenty.common.block.BlockBOPFlower2;
import biomesoplenty.common.block.BlockBOPGrass;
import biomesoplenty.common.block.BlockBOPLilypad;
import biomesoplenty.common.block.BlockBOPLog;
import biomesoplenty.common.block.BlockBOPLog2;
import biomesoplenty.common.block.BlockBOPLog3;
@ -63,6 +64,7 @@ public class ModBlocks
turnip_block = registerBlock(new BlockTurnip(), "turnip_block");
flesh = registerBlock(new BlockFlesh(), "flesh");
grass = registerBlock(new BlockBOPGrass(), "grass");
waterlily = registerBlock(new BlockBOPLilypad(), "waterlily");
}
private static Block registerBlock(BOPBlock block, String name)

View file

@ -0,0 +1,87 @@
/*******************************************************************************
* Copyright 2014, 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.item;
import biomesoplenty.api.block.BOPBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.BlockPos;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public class ItemBOPLilypad extends ItemBlockWithVariants {
public ItemBOPLilypad(Block block) {
super(block);
}
// The code for right clicking needs to be overridden to handle the unique way lilies are placed - on top of the water
// (usually when you point the cursor at water the picked block is whatever is underneath the water - when placing lilies the water itself has to be picked)
// The below is copied from vanille BlockLilyPad
@Override
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true);
if (movingobjectposition == null)
{
return itemStackIn;
}
else
{
if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
{
BlockPos blockpos = movingobjectposition.getBlockPos();
if (!worldIn.isBlockModifiable(playerIn, blockpos))
{
return itemStackIn;
}
if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.sideHit), movingobjectposition.sideHit, itemStackIn))
{
return itemStackIn;
}
BlockPos blockpos1 = blockpos.up();
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (iblockstate.getBlock().getMaterial() == Material.water && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0 && worldIn.isAirBlock(blockpos1))
{
// special case for handling block placement with water lilies
net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(worldIn, blockpos1);
worldIn.setBlockState(blockpos1, BOPBlocks.waterlily.getStateFromMeta(itemStackIn.getMetadata()));
if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(playerIn, blocksnapshot, net.minecraft.util.EnumFacing.UP).isCanceled())
{
blocksnapshot.restore(true, false);
return itemStackIn;
}
if (!playerIn.capabilities.isCreativeMode)
{
--itemStackIn.stackSize;
}
playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
}
}
return itemStackIn;
}
}
}

View file

@ -0,0 +1,22 @@
{
"variants": {
"variant=lily_medium": [
{ "model": "biomesoplenty:lily_medium" },
{ "model": "biomesoplenty:lily_medium", "y": 90 },
{ "model": "biomesoplenty:lily_medium", "y": 180 },
{ "model": "biomesoplenty:lily_medium", "y": 270 }
],
"variant=lily_small": [
{ "model": "biomesoplenty:lily_small" },
{ "model": "biomesoplenty:lily_small", "y": 90 },
{ "model": "biomesoplenty:lily_small", "y": 180 },
{ "model": "biomesoplenty:lily_small", "y": 270 }
],
"variant=lily_tiny": [
{ "model": "biomesoplenty:lily_tiny" },
{ "model": "biomesoplenty:lily_tiny", "y": 90 },
{ "model": "biomesoplenty:lily_tiny", "y": 180 },
{ "model": "biomesoplenty:lily_tiny", "y": 270 }
]
}
}

View file

@ -0,0 +1,16 @@
{
"ambientocclusion": false,
"textures": {
"particle": "blocks/waterlily",
"texture": "biomesoplenty:blocks/lily_medium"
},
"elements": [
{ "from": [ 0, 0.25, 0 ],
"to": [ 16, 0.25, 16 ],
"faces": {
"down": { "uv": [ 16, 16, 0, 0 ], "texture": "#texture", "tintindex": 0 },
"up": { "uv": [ 16, 0, 0, 16 ], "texture": "#texture", "tintindex": 0 }
}
}
]
}

View file

@ -0,0 +1,16 @@
{
"ambientocclusion": false,
"textures": {
"particle": "blocks/waterlily",
"texture": "biomesoplenty:blocks/lily_small"
},
"elements": [
{ "from": [ 0, 0.25, 0 ],
"to": [ 16, 0.25, 16 ],
"faces": {
"down": { "uv": [ 16, 16, 0, 0 ], "texture": "#texture", "tintindex": 0 },
"up": { "uv": [ 16, 0, 0, 16 ], "texture": "#texture", "tintindex": 0 }
}
}
]
}

View file

@ -0,0 +1,16 @@
{
"ambientocclusion": false,
"textures": {
"particle": "blocks/waterlily",
"texture": "biomesoplenty:blocks/lily_tiny"
},
"elements": [
{ "from": [ 0, 0.25, 0 ],
"to": [ 16, 0.25, 16 ],
"faces": {
"down": { "uv": [ 16, 16, 0, 0 ], "texture": "#texture", "tintindex": 0 },
"up": { "uv": [ 16, 0, 0, 16 ], "texture": "#texture", "tintindex": 0 }
}
}
]
}

View file

@ -0,0 +1,18 @@
{
"parent": "builtin/generated",
"textures": {
"layer0": "biomesoplenty:blocks/lily_medium"
},
"display": {
"thirdperson": {
"rotation": [ -90, 0, 0 ],
"translation": [ 0, 1, -3 ],
"scale": [ 0.55, 0.55, 0.55 ]
},
"firstperson": {
"rotation": [ 0, -135, 25 ],
"translation": [ 0, 4, 2 ],
"scale": [ 1.7, 1.7, 1.7 ]
}
}
}

View file

@ -0,0 +1,18 @@
{
"parent": "builtin/generated",
"textures": {
"layer0": "biomesoplenty:blocks/lily_small"
},
"display": {
"thirdperson": {
"rotation": [ -90, 0, 0 ],
"translation": [ 0, 1, -3 ],
"scale": [ 0.55, 0.55, 0.55 ]
},
"firstperson": {
"rotation": [ 0, -135, 25 ],
"translation": [ 0, 4, 2 ],
"scale": [ 1.7, 1.7, 1.7 ]
}
}
}

View file

@ -0,0 +1,18 @@
{
"parent": "builtin/generated",
"textures": {
"layer0": "biomesoplenty:blocks/lily_tiny"
},
"display": {
"thirdperson": {
"rotation": [ -90, 0, 0 ],
"translation": [ 0, 1, -3 ],
"scale": [ 0.55, 0.55, 0.55 ]
},
"firstperson": {
"rotation": [ 0, -135, 25 ],
"translation": [ 0, 4, 2 ],
"scale": [ 1.7, 1.7, 1.7 ]
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B