Posted April 27, 20205 yr 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
April 27, 20205 yr 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.
April 27, 20205 yr Author 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.
April 27, 20205 yr Just tried what? And what didn't work? Did you set a breakpoint to see if you reach the event?
April 27, 20205 yr Author player.getEntityWorld().setBlockState(e.getPos(), Blocks.STONE.getDefaultState()); This part doesnt work.
April 27, 20205 yr 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.
April 27, 20205 yr Author 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
April 27, 20205 yr 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.
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.