Fix reed rendering placement and bounding box

This commit is contained in:
Cheeserolls 2015-04-11 22:33:13 +01:00
parent 890f009c49
commit e767ee0274
3 changed files with 154 additions and 5 deletions

View File

@ -17,6 +17,7 @@ import biomesoplenty.api.block.BOPBlocks;
import biomesoplenty.api.block.BOPPlantEnums;
import biomesoplenty.api.block.BOPPlantEnums.AllPlants;
import biomesoplenty.api.item.BOPItems;
import biomesoplenty.common.item.ItemBOPPlant;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
@ -30,6 +31,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemShears;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
@ -51,7 +53,6 @@ import net.minecraftforge.fml.relauncher.SideOnly;
// TODO: shrub needs custom item texture
// TODO: double cattail
// TODO: placing reeds
// TODO: pick block?
public abstract class BlockBOPPlant extends BlockDecoration implements IShearable
@ -120,6 +121,8 @@ public abstract class BlockBOPPlant extends BlockDecoration implements IShearabl
// implement IBOPBlock
@Override
public Class<? extends ItemBlock> getItemClass() { return ItemBOPPlant.class; }
@Override
public IProperty[] getPresetProperties() { return new IProperty[] { getMyVariantProperty() }; }
@Override
public IProperty[] getNonRenderingProperties() { return null; }
@ -357,6 +360,10 @@ public abstract class BlockBOPPlant extends BlockDecoration implements IShearabl
// roots hang from ceiling
this.setBlockBoundsByRadiusAndHeight(0.4F, 0.8F, true);
break;
case REED:
// reeds extend one block below
this.setBlockBounds(0.2F, -1.0F, 0.2F, 0.8F, 0.8F, 0.8F);
break;
default:
this.setBlockBoundsByRadiusAndHeight(0.4F, 0.8F);
break;

View File

@ -0,0 +1,103 @@
/*******************************************************************************
* 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.BOPPlantEnums.AllPlants;
import biomesoplenty.common.block.BlockBOPPlant;
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 ItemBOPPlant extends ItemBOPBlock {
public ItemBOPPlant(Block block) {
super(block);
}
// The code for right clicking needs to be overridden to handle the unique way reeds 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 reeds the water itself has to be picked)
@Override
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
if (this.block instanceof BlockBOPPlant)
{
BlockBOPPlant block = (BlockBOPPlant)this.block;
IBlockState state = block.getStateFromMeta( itemStackIn.getMetadata() );
AllPlants plant = ((AllPlants) state.getValue(block.getMyVariantProperty()));
if (plant == AllPlants.REED)
{
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 reeds
net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(worldIn, blockpos1);
worldIn.setBlockState(blockpos1, BlockBOPPlant.getVariantState(AllPlants.REED));
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;
}
}
}
// in all other cases take the default action
return super.onItemRightClick(itemStackIn, worldIn, playerIn);
}
}

View File

@ -1,6 +1,45 @@
{
"parent": "block/cross",
"ambientocclusion": false,
"textures": {
"cross": "biomesoplenty:blocks/reed"
}
}
"cross": "biomesoplenty:blocks/reed",
"particle": "biomesoplenty:blocks/reed"
},
"elements": [
{ "from": [ 0.8, 0, 8 ],
"to": [ 15.2, 16, 8 ],
"rotation": { "origin": [ 8, 8, 8 ], "axis": "y", "angle": 45, "rescale": true },
"shade": false,
"faces": {
"north": { "uv": [ 0, 0, 16, 16 ], "texture": "#cross" },
"south": { "uv": [ 0, 0, 16, 16 ], "texture": "#cross" }
}
},
{ "from": [ 8, 0, 0.8 ],
"to": [ 8, 16, 15.2 ],
"rotation": { "origin": [ 8, 8, 8 ], "axis": "y", "angle": 45, "rescale": true },
"shade": false,
"faces": {
"west": { "uv": [ 0, 0, 16, 16 ], "texture": "#cross" },
"east": { "uv": [ 0, 0, 16, 16 ], "texture": "#cross" }
}
},
{ "from": [ 0.8, -16, 8 ],
"to": [ 15.2, 0, 8 ],
"rotation": { "origin": [ 8, 8, 8 ], "axis": "y", "angle": 45, "rescale": true },
"shade": false,
"faces": {
"north": { "uv": [ 0, 0, 16, 16 ], "texture": "#cross" },
"south": { "uv": [ 0, 0, 16, 16 ], "texture": "#cross" }
}
},
{ "from": [ 8, -16, 0.8 ],
"to": [ 8, 0, 15.2 ],
"rotation": { "origin": [ 8, 8, 8 ], "axis": "y", "angle": 45, "rescale": true },
"shade": false,
"faces": {
"west": { "uv": [ 0, 0, 16, 16 ], "texture": "#cross" },
"east": { "uv": [ 0, 0, 16, 16 ], "texture": "#cross" }
}
}
]
}