Jump to content

[1.8] [SOLVED] Help with placing custom lily pad on top of water


skyfir3

Recommended Posts

I need help with placing a custom lily pad on top of water.

Ive looked in the original lilypad classes: BlockLilyPad/ItemLilyPad, but i cant seen to make it work.

This code seems interesting:

 

 

public class ItemLilyPad extends ItemColored

{

    private static final String __OBFID = "CL_00000074";

 

    public ItemLilyPad(Block block)

    {

        super(block, false);

    }

 

    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, Blocks.waterlily.getDefaultState());

                    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;

        }

    }

 

 

Copied the code and made a ItemBlock but still can't make it work  :P

Link to comment
Share on other sites

I found out ;D

I had to add something from the BlockBush.class

 

BlockBush.class

 

 

    @Override

    public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos)

    {

        if (this == Blocks.wheat)          return net.minecraftforge.common.EnumPlantType.Crop;

        if (this == Blocks.carrots)        return net.minecraftforge.common.EnumPlantType.Crop;

        if (this == Blocks.potatoes)      return net.minecraftforge.common.EnumPlantType.Crop;

        if (this == Blocks.melon_stem)    return net.minecraftforge.common.EnumPlantType.Crop;

        if (this == Blocks.pumpkin_stem)  return net.minecraftforge.common.EnumPlantType.Crop;

        if (this == Blocks.deadbush)      return net.minecraftforge.common.EnumPlantType.Desert;

        if (this == Blocks.waterlily)      return net.minecraftforge.common.EnumPlantType.Water;

        if (this == Blocks.red_mushroom)  return net.minecraftforge.common.EnumPlantType.Cave;

        if (this == Blocks.brown_mushroom) return net.minecraftforge.common.EnumPlantType.Cave;

        if (this == Blocks.nether_wart)    return net.minecraftforge.common.EnumPlantType.Nether;

        if (this == Blocks.sapling)        return net.minecraftforge.common.EnumPlantType.Plains;

        if (this == Blocks.tallgrass)      return net.minecraftforge.common.EnumPlantType.Plains;

        if (this == Blocks.double_plant)  return net.minecraftforge.common.EnumPlantType.Plains;

        if (this == Blocks.red_flower)    return net.minecraftforge.common.EnumPlantType.Plains;

        if (this == Blocks.yellow_flower)  return net.minecraftforge.common.EnumPlantType.Plains;

        return net.minecraftforge.common.EnumPlantType.Plains;

    }

 

 

 

MyBlock.class

 

 

    @Override

    public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos)

    {

        if (this == BlockManager.BushLotus)      return net.minecraftforge.common.EnumPlantType.Water;

        return net.minecraftforge.common.EnumPlantType.Plains;

    }

 

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.