Jump to content

[1.15.1] Putting modded flowers in a modded flower pot


Peerius

Recommended Posts

Hello,

 

I wanted to be able to put a flower created by me in a flower pot. After realising I have to add a new flower pot with my modded flower and change the onItemUse method I got some issues.

Here is my code of the new onItemUse method:

public ActionResultType onItemUse(ItemUseContext context) {
		ItemStack stack = context.getItem();
		World world = context.getWorld();
		if(stack.getItem()==ItemList.censored_flower) {
			BlockState state = world.getBlockState(context.getPos());
			if(state.getProperties().equals(Blocks.FLOWER_POT.getDefaultState().getProperties())) {
				world.setBlockState(context.getPos(), BlockList.censored_flower_pot.getDefaultState());
				stack.setCount(stack.getCount()-1);
				return ActionResultType.SUCCESS;
			}
			if(state.getBlock()==Blocks.GRASS_BLOCK||state.getBlock()==Blocks.DIRT) {
				BlockPos pos = new BlockPos(context.getHitVec());
				if(world.getBlockState(pos).getBlock()==Blocks.AIR) {
					world.setBlockState(pos, BlockList.censored_flower.getDefaultState());
					stack.setCount(stack.getCount()-1);
					return ActionResultType.SUCCESS;
				}
			}
		}
		logger.info("Fail.");
		return ActionResultType.FAIL;
	}

 

So my problem is that the method doesn't seem to register when I rightclick on an empty flower pot while holding my flower. I also tried it with state.getBlock()==Blocks.FLOWER_POT but that didn't work either. The placement on grass and dirt blocks works perfectly.

I believe the solution will be easy but I can't find it.

 

Thank you very much in advance.

Link to comment
Share on other sites

Okay thank you, that worked.

 

Now I have a new problem...

 

 

I obviously don't exactly know how to add a flower pot containing my flower. When the flower pot gets replaced there appears the "texture not available" texture. Here is the models json I used:

{
    "parent": "block/flower_pot_cross",
    "textures": {
        "plant": "censored_id:block/censored_flower"
    }
}

 

 

Thanks in advance again :) 

Edited by Peerius
New knowledge
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.



×
×
  • Create New...

Important Information

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