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
  On 10/14/2018 at 9:18 PM, Uhoh said:

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

Expand  

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

  On 10/14/2018 at 9:18 PM, Uhoh said:

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

Expand  

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
  On 10/15/2018 at 12:06 AM, Uhoh said:

Any ideas why?

Expand  

Did you register the event class as I said above?

 

  On 10/15/2018 at 12:06 AM, Uhoh said:

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

Expand  

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
  On 10/15/2018 at 12:06 AM, Uhoh said:

if (newblock == Blocks.sand) {

Expand  

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

  On 10/15/2018 at 12:06 AM, Uhoh said:

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

Expand  

We don't support modding on versions below 1.9

About Me

  Reveal hidden contents

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
  On 10/15/2018 at 12:06 AM, Uhoh said:

int blockY = MathHelper.floor_double(parEntity.boundingBox.minY)-1;

Expand  

This isn't the correct value, the player has a posY field.

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

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • One fateful day, my life took an unexpected turn when I received a phone call that would change everything. The voice on the other end claimed to be from my bank, delivering alarming news: my account had been frozen due to suspicious activity. Panic surged through me as I listened, my heart racing at the thought of losing my hard-earned savings. At that moment, I had about 130,000 USD in my bank, equivalent to around 2 BTC. The caller spoke with such authority and urgency that I felt compelled to act immediately. They insisted that the only way to protect my funds was to transfer Bitcoin BTC to them for "safekeeping. In my fear and confusion, I believed I was making a wise decision to secure my finances. Without fully grasping the implications, I complied and transferred the equivalent of my savings in Bitcoin, convinced I was safeguarding my money. It wasn’t until later that the reality of my situation hit me like a ton of bricks. I had been duped, and the weight of my mistake was unbearable. Shame and disbelief washed over me as I realized how easily I had been manipulated. How could I have let this happen? The feeling of vulnerability was overwhelming, and I was left grappling with the consequences of my actions. I learned about a recovery expert named RAPID DIGITAL RECOVERY. Desperate to reclaim what I had lost, I reached out for help. RAPID DIGITAL RECOVERY was knowledgeable and reassuring, explaining that there was a chance to trace the Bitcoin I had sent. With their expertise, they tracked the stolen funds to a peer-to-peer (P2P) exchanger based in the United Kingdom. This revelation sparked a glimmer of hope within me, a sense that perhaps justice could be served. RAPID DIGITAL RECOVERY collaborated with Action Fraud, the UK's national reporting center for fraud and cybercrime, to take decisive action against the scammers. Knowing that law enforcement was involved provided me with a sense of relief. The thought that the culprits behind my suffering could be brought to justice was comforting. In an incredible turn of events, RAPID DIGITAL RECOVERY successfully recovered all my funds, restoring my faith in the possibility of justice and recovery.
    • My game crashed in 1.12.2 here is the crash log https://pastebin.com/6MYu4mGy
    • I created a Modpack Forge in 1.20.1 for my friend and I. There are 135 mods including "Essential". I was able to play an 8 hour session without problem but when I relaunch my world, I crashed when I opened the menu of the game "ESC" or after about 15 minutes of session. I can't find the source of the problem. Latest.log and Debug.log : https://paste.ee/p/B0npvlRw
    • Hello! Faced with the same problem. Can you please describe in more detail how you rewrote the toNetwork and fromNetwork methods?
    • Why not?   Please explain what you have tried, in detail. Step by step is installing the server, placing mod .jar files in the mods folder within the folder you installed the server, and running the run.bat file. If this is not working for you, please post the debug.log from the logs folder to a site like https://mclo.gs and post the link to it here.
  • Topics

×
×
  • Create New...

Important Information

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