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

I am trying to make a specific class for one of my blocks but for some reason the overridden methods are not called, however the constructor is called and gets added to the registry as it still shows up in game.

public class MudBlock extends Block {
	public MudBlock(Properties properties) {
		super(properties);
		FunMod.log.info("Mud Block created!");
	}

	@Override
	public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
		FunMod.log.info("Entity collided with a Mud Block!");
	}
	
	@Override
	public void onBlockClicked(BlockState state, World worldIn, BlockPos pos, PlayerEntity player) {
		FunMod.log.info("Block was clicked on!");
	}
}

That is the class I create.

I register it like this:

@Mod.EventBusSubscriber(modid = FunMod.MOD_ID, bus = Bus.MOD)
@ObjectHolder(FunMod.MOD_ID)
public class BlockInit {

	/* Blocks to be registered */
	public static MudBlock mud_block = null;

	private static void register_block(final RegistryEvent.Register<Block> event, Block block, String name) {
		block.setRegistryName(name);
		event.getRegistry().register(block);
	}
	
	private static void register_block_item(final RegistryEvent.Register<Item> event, Block block, Item.Properties properties, String name) {
		event.getRegistry().register(new BlockItem(block, properties).setRegistryName(name));
	}
	
	@SubscribeEvent
	public static void register_blocks(final RegistryEvent.Register<Block> event) {
		/* Create block objects */
		mud_block = new MudBlock(Block.Properties.create(Material.SAND).hardnessAndResistance(10f, 0f).harvestTool(ToolType.SHOVEL).slipperiness(5f).sound(SoundType.GROUND));
		
		/* Register blocks */
		FunMod.log.info("Registering blocks.");
		register_block(event, mud_block, "mud_block");
		FunMod.log.info("Done.");
	}
	
	@SubscribeEvent
	public static void register_block_items(final RegistryEvent.Register<Item> event) {
		/* Register block items */
		register_block_item(event, mud_block, new Item.Properties().maxStackSize(64).group(ItemGroup.BUILDING_BLOCKS), "mud_block");
	}
}

Does anyone see anything I am doing wrong?

 

Also I'm using 1.15.2

 

EDIT: Sometimes the onEntityCollision works, but not all the time. It seems to only trigger when an Entity is actually inside one of the blocks and not just touching it.

Edited by mrcobalt124

I suspect the methods work, but that you are mistaken about when they should trigger. onEntityCollision is supposed to only trigger when the entity is inside, and onBlockClicked only triggers for left click, use onBlockActivated for right click.

  • Author

Hm, overriding onBlockClicked still lets me break the block, and doesn't trigger the function. Should I be testing in survival mode?

3 minutes ago, mrcobalt124 said:

Should I be testing in survival mode?

Yes. Creative mode bypasses a lot of things. In this case, hijacking left-click and immediately setting the block to air.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Yeah I figured that out cool. Another thing, is there a way I can get control of some code when an entity is touching my block? I'm trying to make a conveyor belt, don't be mistaken by the Mud Block name, that's just a block i'm messing around with.

  • Author
1 minute ago, vemerion said:

onEntityWalk detects when an entity is on top of a block, if that is what you need.

Thanks! That should work to my needs.

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.