Jump to content

Recommended Posts

Posted

Ok I got my mod working in singleplayer mode as i wanted it to. I was hopin it to run the same when joinin a server as it's a client side only simple mod... ..but no ;(

 

Sry guys if it sounds like an obvious thing i'm really new to forge ^^

 

here's my code

 

Main.java

(imports)

@Mod(modid = Main.MODID, name = Main.MODNAME, version=Main.VERSION, clientSideOnly=true)

public class Main {

 

public static final String MODID = "mymod";

public static final String MODNAME = "MyMod";

public static final String VERSION = "1.8.9-0.1";

PlayerWatcherHandler playerHandler = new PlayerWatcherHandler();

 

@Instance(value = Main.MODID)

public static Main instance;

 

 

@EventHandler

public void preInit(FMLPreInitializationEvent e) {

MinecraftForge.EVENT_BUS.register(playerHandler);

}

 

@EventHandler

public void init(FMLInitializationEvent e) {

 

}

 

@EventHandler

public void postInit(FMLPostInitializationEvent e) {

 

}

}

 

//////////////////////////////////////////////////////////////////////////////////////////////////

 

playerwatcherhandler.java

(imports)

public class PlayerWatcherHandler {

 

public PlayerWatcherHandler() {}

 

        @SubscribeEvent

public void speedy(PlayerEvent evt){

if (evt.entityPlayer.isSprinting())

System.out.println("Gonzales");

        }

}

 

 

 

This code print out gonzales when i run in singleplayer game but doesn't in multipleplayer... Why ? how to solve that ?

Posted

First of all, you don't want to use PlayerEvent. For what you're doing you should probably either use LivingEvent.LivingUpdateEvent, or TickEvent.PlayerTickEvent (the latter must be registered to the FML bus, not the Event bus).

 

Obviously since your mod is client side only, it's not going to print in the server log... but did you check the client log (fml-client-latest.log in the .minecraft/logs folder)?

Posted

I'm not speakin of logs but of the stdout I run it in Eclipse .

(And i use --username and --password args for being able to join a server (even try with my own server to be sure it wasn't some kind of protection on the server i was connectin too.. but same result))

 

Btw i also tried with breakpoints in debug mode and playerEvent is triggered only once in mp (right after the world loading event; then it will not be triggered anymore unlike in singleplayer where it's systematicaly triggered...)

 

I will try with the events you suggested and let u know

Posted

Ty so much !!! with TickEvent.PlayerTickEvent it works !! didn't try the livingEvent as my target is the player the Player seemed more appropriate.

 

But how do you guess which event to use or not to use ? like how can one guesses a method named "isEating" means "isRightClicking" ^^ ?

Posted
  On 4/10/2016 at 2:18 AM, AndrewFM said:

First of all, you don't want to use PlayerEvent. For what you're doing you should probably either use LivingEvent.LivingUpdateEvent, or TickEvent.PlayerTickEvent (the latter must be registered to the FML bus, not the Event bus).

 

The OP is using 1.8.9, where the Forge and FML event buses have been merged. Anything that was fired on the FML bus is now fired on the Forge bus.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

ty guys ^^

 

that last event is makin me struggling

 

@SubscribeEvent

public void fightin(LivingAttackEvent evt){

if (((evt.entityLiving instanceof EntityPlayer) && (evt.source.getEntity() instanceof IMob)) ||

((evt.entityLiving instanceof IMob) && (evt.source.getEntity() instanceof EntityPlayer))){

system.out.println(FIGHT);

}

}

 

I need to detect when the player is in fight but in multiplayer mode. So Other players would be considered as hostile living entity

Posted

If DamageSource#getEntity is not null, then you are pretty much guaranteed to be in a fight. Either a mob or player hit you directly, or some sort of projectile struck you.

 

However, you should be aware that many events such as LivingHurtEvent and LivingAttackEvent are typically posted only on the server*  - you are only aware of them during single-player because the server is integrated with the client.

 

* Unless you (the client player) triggered the event, e.g. when you attack something LivingAttackEvent will be posted for you on your client as well as on the server, but not necessarily when something attacks you. You can find out by printing to the console during the events and then triggering them in single- and multi-player.

Posted

Yes ty, that explains a lot ^^

as i wasn't even able to detect attack even from IMob when on server...

So there is no simple way to know what did the dmg to my player when connected on server ? (as when it gets attacked it's only fired on server side ?)

Posted
  On 4/10/2016 at 5:35 AM, yetanothermodder said:

Yes ty, that explains a lot ^^

as i wasn't even able to detect attack even from IMob when on server...

So there is no simple way to know what did the dmg to my player when connected on server ? (as when it gets attacked it's only fired on server side ?)

Not if you insist on making a client-side only mod.

Posted

OK ty for  all that info  dude  :)

It makes sense on one hand as it's not cause u get hurt that u know the dmg source (I mean IRL)...

So the paradigm is logical

And yes I insist ^^ as I really want my mod to be able to operate on any server

 

I think i will just go for if u lose health your in fight when in MP mode... won't be wrong so often as u mostly get hurt when in fight (it's more rare to get hurt cause starvin, suffocatin or burnin... than cause in fight when in MP mode) might be enough occurate for my use

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I can't figure out if you're looking for help trying to steal someone elses work, or cheat at the game....
    • Title: Why Is It So Hard to Rename and Restructure Mods Like Xray or AntiXray? 🤔 Post text: Hey everyone! I’ve been digging into Minecraft modding for a while and have one big question that I can’t figure out on my own. Maybe someone with more experience could help or give me some advice. Here’s the issue: When I take a “normal” Minecraft mod — for example, one that just adds some blocks or new items — I can easily change its structure, package names, or even rebrand it entirely. It’s straightforward. But as soon as I try this with cheat-type mods like XrayMod or AntiXray, everything falls apart. Even if I just rename the classes, refactor the packages, or hide its identity somehow, the mod either breaks or stops working properly. XrayMod in particular is proving to be a nightmare to modify without losing its core function. So my question is — why is this so much harder with cheat mods like Xray? Is there something fundamentally different about how they’re coded, loaded, or protected that prevents simple renaming or restructuring? And if so, how can I actually learn to understand someone else’s cheat mod enough to safely refactor it without breaking the core features? I’ve already been spending over two months trying to figure this out and haven’t gotten anywhere. It feels like there must be some trick or knowledge I’m missing. Would really appreciate any thoughts, tips, or references — maybe there are guides or techniques for understanding cheat-mod internals? Or if you’ve successfully “disguised” a cheat mod like Xray before, I’d love to hear how you did it. Thanks in advance for any help or discussion. ✌️
    • just started making cinamatic contect check it out on my channel or check out my facebook page    Humbug City Minecraft Youtube https://www.youtube.com/watch?v=v2N6OveKwno https://www.facebook.com/profile.php?id=61575866982337  
    • Where did you get the schematic? Source/Link? And do use an own modpack or a pre-configured from curseforge? If yes, which one On a later time, I can make some tests on my own - but I need the schematic and the modpack name
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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