Jump to content

[solved] some noob question


yetanothermodder

Recommended Posts

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 ?

Link to comment
Share on other sites

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)?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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