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

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

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 need to know what mod is doing this crash, i mean the mod xenon is doing the crash but i want to know who mod is incompatible with xenon, but please i need to know a solution if i need to replace xenon, i cant use optifine anymore and all the other mods i tried(sodium, lithium, vulkan, etc) doesn't work, it crash the game.
    • I have been trying to solve a consistent crashing issue on my brother's computer where it will crash during the "Scanning Mod Candidates" phase of the loading process that starts when you click the play button on the Minecraft launcher. The issue seems to stem from a missing library that it mentions in the log file I provide below. I might I'm missing the bigger issue here for a smaller one but hopefully someone can find what I'm missing. Here's all of the stuff that I've been able to figure out so far: 1. It has nothing to do with mods, the crash happened with a real modpack, and even when I made a custom modpack and launched it without putting ANY mods into it (That is where the log file comes from by the way). 2. I have tried to find this class like a file in the Minecraft folders, but I've had no luck finding it (I don't think it works like that, but since I really don't understand how it works, I just figured I'd try). 3. I haven't seen anyone else have this issue before. 4. I know that my modpack (with mods) does work since I've run it on my computer, and it works fantastic. For some reason my brother's computer can't seem to run anything through curseforge. 5. This is for Minecraft version 1.20.1, Minecraft launcher version 3.4.50-2.1.3, forge 47.3.0, and curseforge app version 1.256.0.21056 6. My brother is using a Dell laptop from 6 years ago running Windows 10 (If you think more info on this would help, please ask as I do have it. I'm just choosing not to put it here for now). 7. I have reinstalled the curseforge app and installed Minecraft version 1.20.1. I have not reinstalled Minecraft or forge 47.3.0 but I didn't know if that would help. 8. I had an error code of 1 Please let me know if there is anything else that I am missing that you would like me to add to this post/add in a comment! Lastly, many thanks in advance to whoever can help! ------------- LOG FILE (latest.log) ------------- (from /Users/<NAME OF USER>/cursforge/minecraft/Instances/<THE NAME OF MY EMPTY MODPACK>/logs/latest.log) (This was made after running an empty modpack with same versions for all apps) ("[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/hxXvGGEK ------------- DEBUG.LOG (I realized that I should have put this here first after I had done all of the work on putting latest.log in) -------------------- (again, "[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/Fmh8GHYs
    • Pastebin... https://pastebin.com/Y3iZ85L5   Brand new profile, does not point to a mod as far as I can tell, my fatal message just has something about mixins. Don't know much about reading logs like this, but am genuinely stuck, please help. Java updated, pc restarted.
    • I was playing minecraft, forge 47.3.0 and 1.20.1, but when i tried to play minecraft now only crashes, i need help please. here is the crash report: https://securelogger.net/files/e6640a4f-9ed0-4acc-8d06-2e500c77aaaf.txt
  • Topics

×
×
  • Create New...

Important Information

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