mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 03:39:17 +00:00
Fix petal burying #274
This commit is contained in:
1 file changed
+49
-7
@@ -10,12 +10,17 @@
|
||||
*/
|
||||
package vazkii.botania.common.item.material;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.api.item.IPetalApothecary;
|
||||
import vazkii.botania.api.recipe.IFlowerComponent;
|
||||
@@ -30,16 +35,53 @@ public class ItemPetal extends Item16Colors implements IFlowerComponent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumActionResult onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, BlockPos pos, EnumHand hand, EnumFacing side, float par8, float par9, float par10) {
|
||||
ItemStack stackToPlace = new ItemStack(ModBlocks.buriedPetals, 1, par1ItemStack.getItemDamage());
|
||||
stackToPlace.onItemUse(par2EntityPlayer, par3World, pos, hand, side, par8, par9, par10);
|
||||
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||
// Copy of ItemBlock.onItemUse
|
||||
IBlockState iblockstate = world.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if(stackToPlace.stackSize == 0) {
|
||||
if(!par2EntityPlayer.capabilities.isCreativeMode)
|
||||
par1ItemStack.stackSize--;
|
||||
if (!block.isReplaceable(world, pos))
|
||||
{
|
||||
pos = pos.offset(facing);
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
if (stack.stackSize != 0 && player.canPlayerEdit(pos, facing, stack) && world.canBlockBePlaced(ModBlocks.buriedPetals, pos, false, facing, null, stack))
|
||||
{
|
||||
int i = this.getMetadata(stack.getMetadata());
|
||||
IBlockState iblockstate1 = ModBlocks.buriedPetals.onBlockPlaced(world, pos, facing, hitX, hitY, hitZ, i, player);
|
||||
|
||||
if (placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, iblockstate1))
|
||||
{
|
||||
SoundType soundtype = ModBlocks.buriedPetals.getSoundType();
|
||||
world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
|
||||
--stack.stackSize;
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
// Direct copy of ItemBlock.placeBlockAt
|
||||
private boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) {
|
||||
if (!world.setBlockState(pos, newState, 3)) return false;
|
||||
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
if (state.getBlock() == ModBlocks.buriedPetals)
|
||||
{
|
||||
// setTileEntityNBT(world, player, pos, stack);
|
||||
ModBlocks.buriedPetals.onBlockPlacedBy(world, pos, state, player, stack);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(int stackMeta) {
|
||||
return MathHelper.clamp_int(stackMeta, 0, 15);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user