Jump to content

Recommended Posts

Posted (edited)

Hello guys. Basically I maded a custom recipe with the subscribe event RightClickBlock event.

The main recipe class:

Spoiler

@Mod.EventBusSubscriber
public class GroundDiggingProcessing {
	
	public static List<DiggingRecipe> RECIPES = new ArrayList<>();
	
	public static void initializeRecipes() {
		registerRecipe(new DiggingRecipe("grass_ball_recipe", Blocks.GRASS, ModItems.GRASS_BALL, Blocks.DIRT));
	}
	
	@SubscribeEvent
	public static void onBlockRightClick(PlayerInteractEvent.RightClickBlock e) {
		Block b = e.getWorld().getBlockState(e.getPos()).getBlock();
		ItemStack i = e.getItemStack();
		
		
		for(DiggingRecipe r : RECIPES) {
			if(e.getEntityPlayer() != null) {
				if(!(e.getWorld().isRemote)) {
					if(b == r.getMainBlock() && i.getItem() instanceof ItemMiniShovel) {
						if(e.getEntityPlayer().isSneaking()) {
						    e.getEntityPlayer().dropItem(new ItemStack(r.getBallOutput(), 1), false);
						    e.getEntityLiving().getHeldItemMainhand().damageItem(1, e.getEntityPlayer());
							e.getWorld().playSound(null, e.getPos(), b.getSoundType().getBreakSound(), SoundCategory.BLOCKS, b.getSoundType().getVolume() * 0.4F, b.getSoundType().getPitch() + (float) (Math.random() * 0.2 - 0.1));
						}
					}
				}
			}
		}
	}
	
	public static void registerRecipe(DiggingRecipe recipe) {
		RECIPES.add(recipe);
	}

}

 

The "DiggingRecipe" class, the recipe used:

Spoiler

public String recipeName;
	
	public Block mainBlock;
	public Item ballOutput;
	public Block outputBlock;
	
	public DiggingRecipe(String recipeName, Block block, Item item, Block blockOutput) {
		this.setRecipeName(recipeName);
		this.setMainBlock(block);
		this.setBallOutput(item);
		this.setOutputBlock(blockOutput);
	}
	
	public String getRecipeName() {
		return recipeName;
	}
	
	public Block getOutputBlock() {
		return outputBlock;
	}
	
	public void setOutputBlock(Block outputBlock) {
		this.outputBlock = outputBlock;
	}
	
	public Block getMainBlock() {
		return mainBlock;
	}
	
	public Item getBallOutput() {
		return ballOutput;
	}
	
	public void setRecipeName(String recipeName) {
		this.recipeName = recipeName;
	}
	
	public void setMainBlock(Block mainBlock) {
		this.mainBlock = mainBlock;
	}
	
	public void setBallOutput(Item ballOutput) {
		this.ballOutput = ballOutput;
	}

 

In the main class seems that in the subscribe event the game does not give the itemstack to the player.

And also it does not damage the item. I dont understand why.

Thanks for the help.

Edited by nov4e
Posted
for(DiggingRecipe r : RECIPES) {
	if(e.getEntityPlayer() != null) {
		if(!(e.getWorld().isRemote)) {
			if(b == r.getMainBlock() && i.getItem() instanceof ItemMiniShovel) {
				if(e.getEntityPlayer().isSneaking()) {
				    e.getEntityPlayer().dropItem(new ItemStack(r.getBallOutput(), 1), false);
				    e.getEntityLiving().getHeldItemMainhand().damageItem(1, e.getEntityPlayer());
					e.getWorld().playSound(null, e.getPos(), b.getSoundType().getBreakSound(),  SoundCategory.BLOCKS,b.getSoundType().getVolume() * 0.4F, b.getSoundType().getPitch() + (float) (Math.random() * 0.2 - 0.1));
				}
			}
		}
	}
}

nooooo

dont do it like this first check if the player is null and if the world if remote and then loop over your recipes

 

and now on topic:

have you placed a breakpoint on it ??

Posted
13 hours ago, loordgek said:

dont do it like this first check if the player is null and if the world if remote and then loop over your recipes

So I do have to do this checks after checking if the player is sneaking? 

 

13 hours ago, loordgek said:

have you placed a breakpoint on it ??

What do you mean with breakpoint?

Posted
19 hours ago, nov4e said:

I actually registered it with a @EventBusSubscriber. Maybe do I have to register it via MinecraftForge.EVENT_BUS.register(listener); ???

3B2E2A9F-819E-417E-B3D8-0D32E67BCB18.jpeg.881d80c8f78d314ccee491fed26a77f0.jpeg

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

got it working.

 

the problem was you set the recipe to early and your grass_ball was null

move https://github.com/nov4e/Exa/blob/master/src/main/java/exa_resources/forge/ExaResources.java#L38 to init.

 

the way you register your items and blocks is wrong

https://github.com/nov4e/Exa/blob/master/src/main/java/exa_resources/forge/features/ModItems.java#L81

dont do that let forge do that for you, that is why @ObjectHolder exist

 

https://github.com/nov4e/Exa/blob/master/src/main/java/exa_resources/forge/base/ItemMiniShovel.java#L70

dont compare strings like that, read this https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java

 

  • Thanks 1
Posted (edited)

Thank you @loordgek for your reply!! I finally fixed it. I will fix the item registry and i will give a look to string comparing. Thank you?

 

Can I ask 1 more thing? How can I set a block to another block?

Edited by nov4e

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.