Started by
Fox_trot
on
Topic category: Help with Minecraft modding (Java Edition)
I'm back again!
I'm making a plant that is similar to that of the sweet berry bush. I want the sweet berry to have the same affect where it is both edible and the seed for the bush. As of right now there is no variable that I know of on a food for when it is right-clicked on a block, right now I have it as when it is right-clicked which spawns the plant right where the player is standing but also is edible at the same time.
Maybe the developers could add a right-clicked on block event to the food item.
Thanks
I suggest you check our tutorials collection playlist on our YouTube channel which contains many examples and tutorials that can help you get started with MCreator: https://www.youtube.com/playlist?list=PLAeL-oIFIEngE6jRgFYeFMfuj8WQsO3Ei
Hi Klemen,
I have looked at the tutorials and they've helped me a lot with other elements, however because I have my seed as a food and not an item there is no right clicked on block event. Is there a procedure saying, if player is looking at grass block, place plant at that block.
Thanks
If you want your food to be plantable, you can create an item element that triggers the "Right-clicked on block" procedure, then copy the code from that item to your food element. The code you'll have to copy should look like this:
After copying the code, you should press ctrl+w to add the required imports (or you'll get compilation errors), lock the food element and delete the item element.
Thanks for the help!
Unfortunately, after following your steps it still doesn't work when I right click.
try replacing this:
with this, after pasting the code:
*sorry, replace it with this:
I've tried again both ways but now it still doesn't work. Here is the code:
public class MCreatorSwampBerries extends Elementsoxenfox_mod.ModElement {
@GameRegistry.ObjectHolder("oxenfox_mod:swampberries")
public static final Item block = null;
public MCreatorSwampBerries(Elementsoxenfox_mod instance) {
super(instance, 1);
}
@Override
public void initElements() {
elements.items.add(() -> new ItemFoodCustom());
}
@SideOnly(Side.CLIENT)
@Override
public void registerModels(ModelRegistryEvent event) {
ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation("oxenfox_mod:swampberries", "inventory"));
}
public static class ItemFoodCustom extends ItemFood {
public ItemFoodCustom() {
super(2, 0.3F, false);
setUnlocalizedName("swampberries");
setRegistryName("swampberries");
setCreativeTab(CreativeTabs.FOOD);
setMaxStackSize(64);
}
@Override
public int getMaxItemUseDuration(ItemStack stack) {
return 16;
}
@Override
public EnumAction getItemUseAction(ItemStack par1ItemStack) {
return EnumAction.EAT;
}
@Override
public EnumActionResult onItemUseFirst(EntityPlayer entity, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ,
EnumHand hand) {
ItemStack itemstack = entity.getHeldItem(hand);
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
{
java.util.HashMap<String, Object> $_dependencies = new java.util.HashMap<>();
$_dependencies.put("x", x);
$_dependencies.put("y", y);
$_dependencies.put("z", z);
$_dependencies.put("world", world);
MCreatorSpawnBerryBush.executeProcedure($_dependencies);
}
@Override
protected void onFoodEaten(ItemStack itemStack, World world, EntityPlayer entity) {
super.onFoodEaten(itemStack, world, entity);
int x = (int) entity.posX;
int y = (int) entity.posY;
int z = (int) entity.posZ;
{
java.util.HashMap<String, Object> $_dependencies = new java.util.HashMap<>();
$_dependencies.put("entity", entity);
MCreatorSwampBerryEaten.executeProcedure($_dependencies);
}
}
}
}
I'm getting compilations errors so what do you mean by ctr+w. I;ve done it in the code and it add boxes with negative signs in them, is that what you mean?
you're missing a } after MCreatorSpawnBerryBush.executeProcedure($_dependencies);
I've added a } but it still doesn't compile :(
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer entity, EnumHand hand) {
ActionResult<ItemStack> ar = super.onItemRightClick(world, entity, hand);
ItemStack itemstack = ar.getResult();
int x = (int) entity.posX;
int y = (int) entity.posY;
int z = (int) entity.posZ;
{
java.util.HashMap<String, Object> $_dependencies = new java.util.HashMap<>();
$_dependencies.put("x", x);
$_dependencies.put("y", y);
$_dependencies.put("z", z);
$_dependencies.put("world", world);
MCreatorSpawnBerryBush.executeProcedure($_dependencies); }
}
}
@Override
protected void onFoodEaten(ItemStack itemStack, World world, EntityPlayer entity) {
super.onFoodEaten(itemStack, world, entity);
int x = (int) entity.posX;
int y = (int) entity.posY;
int z = (int) entity.posZ;
{
java.util.HashMap<String, Object> $_dependencies = new java.util.HashMap<>();
$_dependencies.put("entity", entity);
MCreatorSwampBerryEaten.executeProcedure($_dependencies);
}
}
}
}
now there's one too many. It wasn't there in the code you posted before
It's still not compiling, I've decided to share the workspace with you as I clearly have no clue what's going on.http://www.mediafire.com/file/9820zrjzbo5h893/modtest.jar/file
hm, that's the mod file, not the workspace.
Try again by:
with
Whoops I am such a cluts sometimes...
Anyway, IT WORKED!
I had to make it y + 1 as it was replacing the block but other than that it's perfect!
I forgot to do step 2 so I presume that's why it wouldn't compile for all those attempts.
But nonetheless, thank you very very much for helping me out, very much appreciated!