Jump to content

Recommended Posts

Posted

So I have a test file called Evilsand that just does this:

package missing.abyssalcore.common.blocks;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.block.BlockSand;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
import net.minecraftforge.event.entity.player.*;
import net.minecraft.util.ChatComponentText;

public class Evilsand {
	@SubscribeEvent
	public void Evil(PlayerInteractEvent event) {
		System.out.println("Test");
		System.out.println(event);
	}
	@SubscribeEvent
	public void aaa(BreakEvent event) {
		if (event.block == Blocks.sand) {
			System.out.println("Breaktest");
			System.out.println(event);
		}
	}
}

When I compile my mod, nothing happens on these events. I'm assuming that it's just because it's not being called/ initialized in my main mod file:
 

package missing.abyssalcore.common;

import net.minecraft.init.Blocks;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import missing.abyssalcore.common.blocks.Evilsand;

@Mod(modid = Abyssalcore.MODID, version = Abyssalcore.VERSION)
public class Abyssalcore
{
    public static final String MODID = "Abyssalcore";
    public static final String VERSION = "1.1";
    @EventHandler
	public void preInit(FMLPreInitializationEvent event) {
    	//preinit
    }
    @EventHandler
    public void init(FMLInitializationEvent event){
		// some example code
        //System.out.println("DIRT BLOCK >> "+Blocks.dirt.getUnlocalizedName());
    }
    public void postInit(FMLPostInitializationEvent event) {
    	//postinit
    }
}

So my question is this: exactly in what part of the initialization process do I load in classes like this? It's a little more obvious more stuff like blocks and items and whatnot, but I'm not sure where/how to initialize my Evilsand class in the process.

Posted
21 minutes ago, Uhoh said:

It's a little more obvious more stuff like blocks and items and whatnot

Assuming you mean the RegistryEvents meant for those specific types...

21 minutes ago, Uhoh said:

but I'm not sure where/how to initialize my Evilsand class in the process.

If you put the @EvenBusSubscriber annotation on your class and make the methods static it will register the events or you could just put MinecraftForge.EVENT_BUS.register(newInstanceOfEventClass) in any of the events in your @Mod file.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Oh, I see. Actually testing the mod, I have another question: it seems that PlayerInteractEvent does not, like I hoped, encompass the event of the player standing on a block. If that's the case, then what does? I'm looking through Vic's list of Forge events and I don't see anything that seems to address player/entity block collision.

Posted

For something like checking whether player is standing on a block, you can handle the PlayerTickEvent and just check the block under the Player at that time. Basically there are a number of "tick" events which are useful for applying behavior that may not have an event. These give you a chance every tick (1/20 second) to run whatever code you want (like scanning inventory for specific items, scanning surrounding for certain terrain elements, and similar).

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Hmm, actually, I have another question, sorry- I changed my script so that it attempts to damage the player by 10% of their current health when they're standing on sand, but it doesn't seem to be doing anything:

package missing.abyssalcore.common.blocks;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSand;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
import net.minecraftforge.event.entity.player.*;
import net.minecraft.util.MathHelper;

public class Evilsand {
	//thanks to jabelar for code
	public Block findBlockUnderEntity(Entity parEntity)
	{
	    int blockX = MathHelper.floor_double(parEntity.posX);
	    int blockY = MathHelper.floor_double(parEntity.boundingBox.minY)-1;
	    int blockZ = MathHelper.floor_double(parEntity.posZ);
	    return parEntity.worldObj.getBlock(blockX, blockY, blockZ);
	}
	@SubscribeEvent
	public void Evil(PlayerTickEvent event) {
		if (event.player instanceof EntityPlayer) {
			//assign player to player entity
			EntityPlayer player = (EntityPlayer) event.player;
			Block newblock = findBlockUnderEntity(player);
			if (newblock == Blocks.sand) {
				float health = (float) (player.getHealth() * 0.9);
				player.setHealth(health);
				System.out.println("Oof");
			}
		}
	}
}

Any ideas why? Should I have defined the findBlockUnderEntity method elsewhere, or is my problem someplace else?

Posted
14 minutes ago, Uhoh said:

Any ideas why?

Did you register the event class as I said above?

 

14 minutes ago, Uhoh said:

Should I have defined the findBlockUnderEntity method elsewhere, or is my problem someplace else?

It doesn't matter where you define it.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)

Yeah, I did, and it worked before I added the changes to the Evilsand class. For reference:

package missing.abyssalcore.common;

import net.minecraft.init.Blocks;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import missing.abyssalcore.common.blocks.Evilsand;

@Mod(modid = Abyssalcore.MODID, version = Abyssalcore.VERSION)
public class Abyssalcore
{
    public static final String MODID = "Abyssalcore";
    public static final String VERSION = "1.1";
    @EventHandler
	public void preInit(FMLPreInitializationEvent event) {
    	//preinit
    }
    @EventHandler
    public void init(FMLInitializationEvent event){
    	//register evilsand
    	MinecraftForge.EVENT_BUS.register(new Evilsand());
    }
    public void postInit(FMLPostInitializationEvent event) {
    	//postinit
    }
}

 

Edited by Uhoh
Posted
1 hour ago, Uhoh said:

if (newblock == Blocks.sand) {

did you mean Blocks.SAND? What version are you modding on?

1 hour ago, Uhoh said:

return parEntity.worldObj.getBlock(blockX, blockY, blockZ);

We don't support modding on versions below 1.9

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Also: subtracting 1 does not neccessarily return the block the player is standing on (e.g. carpet, pressure plates, half slabs, enter frames, etc). In fact, such an operation is the source of a long-standing vanilla bug

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.

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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