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

    • Looking for unbeatable savings on Temu in 2025? Our exclusive Temu code [ald244107] is your key to unlocking a $100 OFF discount, plus much more! This verified promo code works for both new and existing customers, giving you up to 50% off your next order and even bigger savings on clearance items. With Temu coupon code [ald244107], you'll get a flat $100 discount on top of existing sales. First-time users can enjoy an extra 100% off select items, while returning shoppers automatically qualify for the $100 OFF when applying the code at checkout. Imagine saving up to 90% on your favorite products across the USA, Canada, UK, and many other countries! 🔥 Temu Coupon Highlights with Code [ald244107]:  * Temu New User Offer: Use ald244107 for 50% off your first order + $100 OFF.  * Temu Existing Customer Promo: Apply ald244107 to get an instant $100 OFF.  * Global Reach: Valid in the USA, UK, Canada, Germany, France, Japan, Chile, Colombia, Malaysia, Mexico, South Korea, Philippines, Saudi Arabia, Qatar, Pakistan, and more.  * Top 2025 Deal: Secure $200 OFF plus 100% bonus discounts with ald244107. Maximize Your Savings: Top Temu Deals for 2025 (Code: ald244107)  * ✅ Temu Memorial Day Sale: Save $100 with ald244107  * ✅ Temu First Order Special: Use ald244107 for 50% + $100 OFF  * ✅ Temu USA Exclusive: Get $100 off instantly with ald244107  * ✅ International Temu Codes: ald244107 works in Japan, Germany, Chile, and many others.  * ✅ Temu Reddit Discount: Enjoy $100 OFF for both new and old users.  * ✅ Temu Coupon Bundle 2025: Combine $100 OFF with up to 50% slash deals.  * ✅ 100% OFF Free Gift Code: Use ald244107 – no invitation needed!  * ✅ Temu Sign-Up Bonus: Instantly get a welcome $100 OFF.  * ✅ Free Temu Code for New Users: Apply ald244107 – no referral required.  * ✅ Temu Clearance Codes 2025: Use ald244107 for 85–100% discounts. This Temu code [ald244107] is more than just a discount; it's your ticket to free shipping, exclusive first-order deals, and stackable coupon bundles across electronics, fashion, home goods, and beauty products. You can truly unlock up to 90% OFF plus an additional $100 OFF on qualified orders. 💡 Pro Tip: Don't forget to apply ald244107 during checkout on the Temu app or website to activate your instant $100 discount, even if you’re a returning customer! Temu $100 OFF Code by Country (All Use ald244107):  * 🇺🇸 Temu USA – ald244107  * 🇯🇵 Temu Japan – ald244107  * 🇲🇽 Temu Mexico – ald244107  * 🇨🇱 Temu Chile – ald244107  * 🇨🇴 Temu Colombia – ald244107  * 🇲🇾 Temu Malaysia – ald244107  * 🇵🇭 Temu Philippines – ald244107  * 🇰🇷 Temu Korea – ald244107  * 🇵🇰 Temu Pakistan – ald244107  * 🇫🇮 Temu Finland – ald244107  * 🇸🇦 Temu Saudi Arabia – ald244107  * 🇶🇦 Temu Qatar – ald244107  * 🇫🇷 Temu France – ald244107  * 🇩🇪 Temu Germany – ald244107 Real Shoppers, Real Savings: User Reviews We love hearing about your experiences! Here’s what some happy shoppers are saying about using the Temu code [ald244107]:  * Alice W., USA ⭐️⭐️⭐️⭐️⭐️ (5/5) "Great experience! Temu's promo code {ald244107} saved me a lot on my first order. Highly recommend this offer!"  * James T., UK ⭐️⭐️⭐️⭐️ (4/5) "Very happy with the quality and prices on Temu. The $100 credits offer was a nice bonus using {ald244107}. Will shop again."  * Sara M., Canada ⭐️⭐️⭐️ (3/5) "Got some decent deals with the {ald244107} code, though shipping took a bit longer than expected. Overall satisfied with the credits."
    • Thank you so much! I didnt see it in the log😭😭  
    • So im completely new to modding in general, i have some experience in Behavior packs in minecraft bedrock and i would like to modify entities stats and attributes like in a behavior pack (health, damage, speed, xp drop...). The problem is that i cant find any information online on how to do that, and I have no clue on what to do and where to start. I am currently modding in 1.20.4 with IntelliJ if that helps. My final objective is to buff mobs health and damage (double it for exemple), but since there is no entity file anywhere i don't know how to change it... 😢
    • Hey there, nothing to do with the code, I am just suggesting you use Intelij IDEA. Trust me, it is the best.
    • Hey there, nothing to do with the code, I am just suggesting you use Intelij IDEA. Trust me, it is the best.
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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