Jump to content

Help with events (minecraft 1.15.2)


Aes123

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.