Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

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

  • Author
player.getEntityWorld().setBlockState(e.getPos(), Blocks.STONE.getDefaultState());

This part doesnt work.

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.

  • 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

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.

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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.