Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [Solved] Place Crops on Water
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
Rhayzan

[Solved] Place Crops on Water

By Rhayzan, January 21 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Rhayzan    0

Rhayzan

Rhayzan    0

  • Tree Puncher
  • Rhayzan
  • Members
  • 0
  • 4 posts
Posted January 21 (edited)

Hello guys,

 

I started modding yesterday and I would like to know how to let a crop be planted on water.

public class BelladonnaCrop extends CropsBlock {

    private static final VoxelShape[] SHAPES =
            new VoxelShape[]{Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D),
                    Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 4.0D, 16.0D),
                    Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 6.0D, 16.0D),
                    Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D),
                    Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 10.0D, 16.0D),
                    Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 12.0D, 16.0D),
                    Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 14.0D, 16.0D),
                    Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D)};

    public BelladonnaCrop(Properties builder) {
        super(builder);
    }

    @Override
    protected IItemProvider getSeedsItem() {
        return ItemRegister.BELLADONNA_SEEDS.get();
    }

    @Override
    public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
        return SHAPES[state.get(this.getAgeProperty())];
    }

    @Override
    public boolean canSustainPlant(BlockState state, IBlockReader world, BlockPos pos, Direction facing, IPlantable plantable) {
        if(state.isIn(Blocks.WATER)){
            return true;
        }else{
            return false;
        }
    }

    @Override
    protected boolean isValidGround(BlockState state, IBlockReader worldIn, BlockPos pos) {
        return state.isIn(Blocks.WATER);
    }
}

 

I started out with this and got it all working on Farmland.

So the only question is how to change the block I can plant it on.

 

Thanks in advace! 😄

Edited January 21 by Rhayzan
  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16010 posts
Posted January 21
22 minutes ago, Rhayzan said:

state.isIn

I don't think this gives you water as a below block but rather a block that is waterlogged.

Check how lily pads work.

  • Thanks 1
  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

Turtledove    4

Turtledove

Turtledove    4

  • Creeper Killer
  • Turtledove
  • Members
  • 4
  • 135 posts
Posted January 21

After you have your crop block, then look into how the lilypad item works.

  • Thanks 1
  • Quote

Share this post


Link to post
Share on other sites

Rhayzan    0

Rhayzan

Rhayzan    0

  • Tree Puncher
  • Rhayzan
  • Members
  • 0
  • 4 posts
Posted January 21

First, thanks for your help! 😃

 

The reason why I used isIn() was because nether warts use this to check if it is soulsand:

   protected boolean isValidGround(BlockState state, IBlockReader worldIn, BlockPos pos) {
      return state.isIn(Blocks.SOUL_SAND);
   }

 

I checked how it is done with lilypads before and that didn't do anything either.

 

So checking if the State at the position is water and the position above is empty would be:

 

public class BelladonnaCrop extends CropsBlock {

    private static final VoxelShape[] SHAPES =
            new VoxelShape[]{Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D),
                    Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 4.0D, 16.0D),
                    Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 6.0D, 16.0D),
                    Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D),
                    Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 10.0D, 16.0D),
                    Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 12.0D, 16.0D),
                    Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 14.0D, 16.0D),
                    Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D)};

    public BelladonnaCrop(Properties builder) {
        super(builder);
    }

    @Override
    protected IItemProvider getSeedsItem() {
        return ItemRegister.BELLADONNA_SEEDS.get();
    }

    @Override
    public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
        return SHAPES[state.get(this.getAgeProperty())];
    }

    @Override
    public boolean canSustainPlant(BlockState state, IBlockReader world, BlockPos pos, Direction facing, IPlantable plantable) {
        return super.canSustainPlant(state, world, pos, facing, plantable);
    }

    @Override
    protected boolean isValidGround(BlockState state, IBlockReader worldIn, BlockPos pos) {
        FluidState fluidstate = worldIn.getFluidState(pos);
        FluidState fluidstate1 = worldIn.getFluidState(pos.up());
        return (fluidstate.getFluid() == Fluids.WATER || state.getMaterial() == Material.ICE) && fluidstate1.getFluid() == Fluids.EMPTY;
    }
}

 

Weird thing about it is that it still works on farmland even though I have overridden the isValidGround function. 😅

 

Could it be that I need to create a custom event for rightclicking with the seeds as soon as I dont use farmland?

 

 

  • Quote

Share this post


Link to post
Share on other sites

Rhayzan    0

Rhayzan

Rhayzan    0

  • Tree Puncher
  • Rhayzan
  • Members
  • 0
  • 4 posts
Posted January 21 (edited)

 

 

15 minutes ago, Turtledove said:

After you have your crop block, then look into how the lilypad item works.

 

Alright after checking the lilypad item I finally got it working.

Thanks so much guys.

 

And for everyone who has the same question:

 

This was the right solution for the CustomCrop class:

    @Override
    protected boolean isValidGround(BlockState state, IBlockReader worldIn, BlockPos pos) {
        FluidState fluidstate = worldIn.getFluidState(pos);
        FluidState fluidstate1 = worldIn.getFluidState(pos.up());
        return (fluidstate.getFluid() == Fluids.WATER || state.getMaterial() == Material.ICE) && fluidstate1.getFluid() == Fluids.EMPTY;
    }

 

And this for the CustomSeed class:


    /**
     * Called when this item is used when targetting a Block
     */
    public ActionResultType onItemUse(ItemUseContext context) {
        return ActionResultType.PASS;
    }

    /**
     * Called to trigger the item's "innate" right click behavior. To handle when this item is used on a Block, see
     * {@link #onItemUse}.
     */
    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
        BlockRayTraceResult blockraytraceresult = rayTrace(worldIn, playerIn, RayTraceContext.FluidMode.SOURCE_ONLY);
        BlockRayTraceResult blockraytraceresult1 = blockraytraceresult.withPosition(blockraytraceresult.getPos().up());
        ActionResultType actionresulttype = super.onItemUse(new ItemUseContext(playerIn, handIn, blockraytraceresult1));
        return new ActionResult<>(actionresulttype, playerIn.getHeldItem(handIn));
    }

 

Edited January 21 by Rhayzan
  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • chaskuchar
      is there any release i can play past 1.16.4

      By chaskuchar · Posted 13 minutes ago

      i was trying to play 21w0b8 and started it without the controller i use with forge helping me for the controller.  i can start using the lancher a new game like 21w0b8 and the save it after i start.  then i quit and restart the launcher and start forge.  i choose the new game which has 21w0b8 at the link and get a message that it might not be compatible but it starts and the controller is working ok.  now my question is, i think the game only loads for 1.16.4.  i can't find the copper or anything special for the new snapshot.  am i chasing a dead horse trying to play with a controller on a new release???  thanks.  chas
    • Herobrine510
      modded server problems

      By Herobrine510 · Posted 17 minutes ago

      so i just made a modded minecraft server yesterday but i've been getting multiple issues with it like yesterday it was java.lang.nullpointerexception and java.noclassdefounderror. i linked that crash report. and i wanted to link my mods folder but that didnt work so yeah. and now today it's been saying that it can't bind to the port and then it's like "Is there another server running?" when there isnt. i linked that crash report too and i would really appreciate some help.crash-2021-03-03_19.28.04-server.txt crash-2021-03-04_12.22.51-server.txt Oh it says "the state engine was in incorrect state POSTINITIIALIZATION and forced into state SERVER_STOPPED." At least that's what the run.bat file says.run.bat i linked that too but i dont know if it'll help much. crash-2021-03-04_12.22.51-server.txt
    • diesieben07
      java.lang.ExeptionInInitializerError: null

      By diesieben07 · Posted 45 minutes ago

      Show your code.
    • heavengel
      error minecraft this server has mod that requires forge to be installed on client

      By heavengel · Posted 51 minutes ago

      Hello   When I try to get in the server there's this message appearing : error minecraft this server has mod that requires forge to be installed on client But it happens that there is NO mod installed on the server, how is this message appearing then ?  Can someone help me please
    • diesieben07
      Can't launch Forge because of spongepowered.[...].MixinTweaker

      By diesieben07 · Posted 1 hour ago

      1.12 is no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
  • Topics

    • chaskuchar
      0
      is there any release i can play past 1.16.4

      By chaskuchar
      Started 13 minutes ago

    • Herobrine510
      0
      modded server problems

      By Herobrine510
      Started 17 minutes ago

    • We Random
      1
      java.lang.ExeptionInInitializerError: null

      By We Random
      Started 1 hour ago

    • heavengel
      0
      error minecraft this server has mod that requires forge to be installed on client

      By heavengel
      Started 51 minutes ago

    • Leetram_519
      1
      Can't launch Forge because of spongepowered.[...].MixinTweaker

      By Leetram_519
      Started 1 hour ago

  • Who's Online (See full list)

    • hammy3502
    • chaskuchar
    • Ommina
    • ivanbj
    • Herobrine510
    • elpanzas
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [Solved] Place Crops on Water
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community