Jump to content

Recommended Posts

Posted (edited)

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
Posted

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.

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

Posted

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.

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.