Aes123 Posted April 27, 2020 Posted April 27, 2020 Having trouble understanding why this piece of code doesnt work. It's meant to replace the ruby_ore when mined by player to stone. Note : it doesnt throw any errors. package com.aes123.atomicrevolution.events; import com.aes123.atomicrevolution.AtomicRevolution; import com.aes123.atomicrevolution.util.BlockInit; import net.minecraft.block.Blocks; import net.minecraft.entity.player.PlayerEntity; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.entity.living.LivingDestroyBlockEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent @Mod.EventBusSubscriber(modid = AtomicRevolution.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class PlayerBrokeIronEvent { @SubscribeEvent public static void playerBrokeRubyOre(LivingDestroyBlockEvent e) { if(e.getEntityLiving() instanceof PlayerEntity){ PlayerEntity player = (PlayerEntity) e.getEntityLiving(); if(e.getState().getBlock() == BlockInit.ruby_ore){ player.getEntityWorld().setBlockState(e.getPos(), Blocks.STONE.getDefaultState()); } } } } Thanks in advance Quote
Ugdhar Posted April 27, 2020 Posted April 27, 2020 5 minutes ago, Aes123 said: value = Dist.CLIENT I don't think you can handle stuff like blocks breaking on the client, probably only on the server. Quote
Aes123 Posted April 27, 2020 Author Posted April 27, 2020 Quote I don't think you can handle stuff like blocks breaking on the client, probably only on the server. I just tried that but it didnt work. Quote
Ugdhar Posted April 27, 2020 Posted April 27, 2020 Just tried what? And what didn't work? Did you set a breakpoint to see if you reach the event? Quote
Aes123 Posted April 27, 2020 Author Posted April 27, 2020 player.getEntityWorld().setBlockState(e.getPos(), Blocks.STONE.getDefaultState()); This part doesnt work. Quote
Ugdhar Posted April 27, 2020 Posted April 27, 2020 2 minutes ago, Aes123 said: player.getEntityWorld().setBlockState(e.getPos(), Blocks.STONE.getDefaultState()); This part doesnt work. Did you change your code to not run the event on the client? Is the event being fired? Did you set breakpoints? Please be more detailed, I can't see your entire project, so it's impossible to see the big picture. Quote
Aes123 Posted April 27, 2020 Author Posted April 27, 2020 Nevermind, i changed the event to BreakEvent and i modified this line to be like this player.getEntityWorld().setBlockState(e.getPos().add(0,0,0), Blocks.STONE.getDefaultState()); and it works fine. Thanks anyways Quote
ZDoctor Posted April 27, 2020 Posted April 27, 2020 You should still get rid of the "value = Dist.CLIENT" pretty sure it will cause a ghost item if someone tried to use it on a server. 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.