Jump to content

[1.13.2] BlockEvent.PlaceEvent does not get called when placing down block


Recommended Posts

Posted (edited)

Having troubles with BlockEvent.PlaceEvent not getting fired when placing blocks while other events such as BlockEvent.BreakEvent is working just fine.

 

All events is in a class called SpawnerEventHandler with @Mod.EventBusSubscriber on it and this class is registred in root mod constructor via:

SpawnerEventHandler spawnerEventHandler = new SpawnerEventHandler();
MinecraftForge.EVENT_BUS.register(spawnerEventHandler);

 

Any suggestions on how to get info when player places down a block?

Thanks in advance.

Edited by Branders
fixed title
Posted

Post your code

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
// SpawnerEventHandler.java

// All imports

@Mod.EventBusSubscriber
public class SpawnerEventHandler
{
	/**
     * 	When we harvest a block
     * 	Return spawner block when harvested with silk touch
     */
    @SubscribeEvent
    public void onBlockHarvestDrops(BlockEvent.HarvestDropsEvent event)
    {
    	if(event.getState().getBlock() == Blocks.SPAWNER)
    	{   
    		NBTTagList list = event.getHarvester().getHeldItemMainhand().getEnchantmentTagList();
    		
    		// Check if silk touch enchant is on the tool
    		if(CheckSilkTouch(list))
    			event.getDrops().add(new ItemStack(Blocks.SPAWNER, 1));

    	}
    }
    
    /**
     * 	When a block is destroyed
     * 	Prevent XP drop when spawner is harvested with silk touch
     */
    @SubscribeEvent
    public void onBlockBreakEvent(BlockEvent.BreakEvent event) 
    {
    	// Check if a spawner broke
    	if(event.getState().getBlock() == Blocks.SPAWNER)
    	{
    		NBTTagList list = event.getPlayer().getHeldItemMainhand().getEnchantmentTagList();
    		
    		// Return 0 EXP when harvested with silk touch
    		if(CheckSilkTouch(list))
    			event.setExpToDrop(0);
    	}
    }
    
    /**
     * 	Called when player places a block
     * 	
     * 	-> This does not happen
     */
    @SubscribeEvent
    public void onBlockPlaced(BlockEvent.PlaceEvent event)
    {
    	System.out.println("This does not happen");
    }
	
    /**
     * Check a tools item enchantment list contains Silk Touch enchant
     * 
     * @param NBTTagList of enchantment
     * @return true/false
     */
    private boolean CheckSilkTouch(NBTTagList list)
    {
    	// Check list string contains silk touch
		if(list.getString().indexOf("minecraft:silk_touch") != -1)
			return true;
		else
			return false;
    }
}


// SpawnerMod.java
// all imports ...

@Mod("spawnermod")
public class SpawnerMod
{	
    public SpawnerMod() 
    {	
    	SpawnerEventHandler spawnerEventHandler = new SpawnerEventHandler();
    	MinecraftForge.EVENT_BUS.register(spawnerEventHandler);
    }
}

 

This is the code for both of my files

Posted (edited)

I was having this problem with ChunkDataEvent.Load. My guess is that Forge hasn't properly implemented these things yet for 1.13, but I could be wrong.

Edited by treebranch
Posted
6 minutes ago, loordgek said:

when your class has


@Mod.EventBusSubscriber

your event methods must be static

Sadly it did not work. All other methods worked but not PlaceEvent

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.