Branders Posted April 16, 2019 Posted April 16, 2019 (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 April 16, 2019 by Branders fixed title Quote
Cadiboo Posted April 16, 2019 Posted April 16, 2019 Post your code Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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)
Branders Posted April 17, 2019 Author Posted April 17, 2019 // 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 Quote
treebranch Posted April 17, 2019 Posted April 17, 2019 (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 April 17, 2019 by treebranch Quote
loordgek Posted April 17, 2019 Posted April 17, 2019 when your class has @Mod.EventBusSubscriber your event methods must be static Quote
Branders Posted April 17, 2019 Author Posted April 17, 2019 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 Quote
Recommended Posts
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.