Jump to content

Recommended Posts

Posted

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

Posted
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.

Posted
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.

Posted

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

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.