Jump to content

Spawning Particles on LivingHurtEvent?


jredfox

Recommended Posts

Guys you might be confused because many people will put the code for both classes in a single file. But they are still separate classes. if you think about it, the message itself gets instantiated every time it is sent, whereas there should be a single handler.

 

The general concept is:

1) Make a class that extends IMessage.

2) This class can have fields representing the payload information, and you need a constructor that takes in that information and assigns it to the field. (Note I think you also need a default constructor with no parameters as well.)

3) You need to override the toBytes() and fromBytes() methods to put your field information into the ByteBuf that is passed in. You should use ByteBufUtils for converting your information.

4) You make a separate class that extends IMessageHandler

5) In that class you need to override the onMessage() method. The message instance will be passed to you and you can access the fields and do whatever you need to do. Note that due to threaded nature, for packets that go from client to server, I think you need to encapsulate your code as a Runnable.

6) The return value for the onMessage() method should generally be null. It is possible to create a confirmation method where the receiver sends a packet back to confirm receipt and unerrored processing, but that is a more advanced topic.

 

I have an example here: https://github.com/jabelar/ExampleMod-1.12/blob/master/src/main/java/com/blogspot/jabelarminecraft/examplemod/networking/MessageSyncEntityToServer.java

Edited by jabelar

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

10 minutes ago, jabelar said:

Guys you might be confused because many people will put the code for both classes in a single file. But they are still separate classes. if you think about it, the message itself gets instantiated every time it is sent, whereas there should be a single handler.

 

The general concept is:

1) Make a class that extends IMessage.

2) This class can have fields representing the payload information, and you need a constructor that takes in that information and assigns it to the field. (Note I think you also need a default constructor with no parameters as well.)

3) You need to override the toBytes() and fromBytes() methods to put your field information into the ByteBuf that is passed in. You should use ByteBufUtils for converting your information.

4) You make a separate class that extends IMessageHandler

5) In that class you need to override the onMessage() method. The message instance will be passed to you and you can access the fields and do whatever you need to do. Note that due to threaded nature I think you need to encapsulate your code as a Runnable.

6) The return value for the onMessage() method should generally be null. It is possible to create a confirmation method where the receiver sends a packet back to confirm receipt and unerrored processing, but that is a more advanced topic.

 

I have an example here: https://github.com/jabelar/ExampleMod-1.12/blob/master/src/main/java/com/blogspot/jabelarminecraft/examplemod/networking/MessageSyncEntityToServer.java

So I debuged my code and discovered the data isn't being transferred to the client.
 

[10:16:11] [Netty Local Client IO #0/INFO] [STDOUT]: [com.evilnotch.respawnscreen.network.PacketParticle:handleClientSide:39]: idEnt:0 idParticle:0


On server side I printed the particle id during the consturctor it said "Server:42" for the id rather then both being 0. Why is this occurring I specified a specific packet constructor when sending to the client and to and from bytes looks like they should work.
 

    @Override
    public void toBytes(ByteBuf buffer){
        buffer.writeInt(this.particleId);
        buffer.writeInt(this.entid);
    }

    @Override
    public void fromBytes(ByteBuf buffer){
        this.particleId = buffer.readInt();
        this.entid = buffer.readInt();
    }


Here is my code:
https://github.com/jredfox/norespawnscreen

here is how I call the packet from the server:
NetWorkHandler.INSTANCE.sendToDimension(new PacketParticle(EnumParticleTypes.DRAGON_BREATH,player.getEntityId() ),player.dimension);

Edited by jredfox
Link to comment
Share on other sites

7 minutes ago, diesieben07 said:

Here you are accessing the fields from the message handler's instance. However you never set these to any meaningful values (how could you, it's the message handler, only the message has useful values here). You need to get the data from the message passed to the method.

This is why you do not implement IMessageHandler and IMessage on the same class (which you are still doing). It is confusing and creates weird, meaningless fields in your message handler.

 

Not to be snarky, but this is making me very happy right now. You didn't want to listen because you are oh so smart and don't need to follow conventions. And guess what, you made the exact mistake that is the reason for me recommending not to do what you did.

 

So, for the love of god: I do not say the things I say because I am bored or want to screw with you.

yeah a beginners mistake I forgot that there was the messege argument there. I was fallowing a youtube video which seemed pretty good to me.

I see why there are separate objects but, I don't see why forge just can't combine them and remove the arg of IMessege so sending to and from you don't have to worry about additional classes. Not saying it don't work just happy I was noob.

 

Edited by jredfox
Link to comment
Share on other sites

11 minutes ago, diesieben07 said:

No, that is a terrible tutorial, because he is teaching that terrible practice.

This is a holdover from pre-1.7 (I think, might be even older) networking, where SimpleNetworkWrapper was not a thing. If you do not like this separation into message handler and message then do not use SimpleMessageHandler! There are other systems available (event based, for example) from the NetworkRegistry. Do not shoe-horn your old habits into the new system in a completely broken way.

Wasn't mine was the videos. Thanks for pointing that out.

My packet handler doesn't work for anything else that isn't explosion particle do you know why this is? This is the code that executes off of the client side I know the width should have been passed from the original entity as well but, for now only testing players which will always be the same when sending the packet.

	public static void spawnParticles(Entity e,int particleId,double x, double y, double z) 
	{
        for (int k = 0; k < 20; ++k)
        {
        	Random rand = getRND(e);
            double d2 = rand.nextGaussian() * 0.02D;
            double d0 = rand.nextGaussian() * 0.02D;
            double d1 = rand.nextGaussian() * 0.02D;
            e.world.spawnParticle(EnumParticleTypes.getParticleFromId(particleId), x + (double)(rand.nextFloat() * e.width * 2.0F) - (double)e.width, y + (double)(rand.nextFloat() * e.height), e.posZ + (double)(rand.nextFloat() * e.width * 2.0F) - (double)e.width, d2, d0, d1);
        }
	}

 

Link to comment
Share on other sites

1 minute ago, jredfox said:

My packet handler doesn't work for anything else that isn't explosion particle do you know why this is?

You need to trace the execution. Like you've already done a bit of, put console statements throughout your code (or use debug mode in your IDE). It should be really obvious quickly -- what ID does it think it is getting? Does that id match what you sent? Does that id match the id for the particle you intended?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

13 minutes ago, jabelar said:

Also another problem with your packet code is that you're reaching across logical sides. You can't access Minecraft() class directly in your onMessage() method. You'll need to call a proxy method.

if you look it's only called on client side.

the particle id does change it just doesn't render anything but, the explosion.

Another issue I am having is the particle xyz double coords are no where near the death of the player.
https://github.com/jredfox/norespawnscreen

 

I could test on hurt event to but, I think the results would be the same

Edit: I printed out the coords sent to the client they are the same as sent from the server of the original player

Edited by jredfox
Link to comment
Share on other sites

5 minutes ago, jredfox said:

if you look it's only called on client side.

Dude, you're really not listening to all the good advice you're getting. We know better as we've been doing this for over a decade. We're not just making stuff up.

 

You're missing some very fundamental concepts that are very important. In this case, it has nothing to do with being called on the client side. The problem is your class is still going to load on the server side (it needs to because that is where the packet is constructed). When the class is loaded, at some point it is going to try to "understand" what the code is supposed to do and the problem is that the Minecraft class isn't loaded on the server at all. So that code is basically broken (not compilable/interpretable) on the server and will cause an error. You may not notice the error when you're testing on an integrated server because technically both client and server code is available to the same JVM, but with dedicated server it will fail.

 

What  I've noticed is that you're running around way too fast without fully understanding what you're doing. Furthermore, you're really not listening to our advice. We are giving advice because we know it is important. Why are you even asking if you are discounting our advice?

Edited by jabelar

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

6 minutes ago, jabelar said:

Dude, you're really not listening to all the good advice you're getting. We know better as we've been doing this for over a decade. We're not just making stuff up.

 

You're missing some very fundamental concepts that are very important. In this case, it has nothing to do with being called on the client side. The problem is your class is still going to load on the server side (it needs to because that is where the packet is constructed). When the class is loaded, at some point it is going to try to "understand" what the code is supposed to do and the problem is that the Minecraft class isn't loaded on the server at all. So that code is basically broken (not compilable/interpretable) on the server and will cause an error. You may not notice the error when you're testing on an integrated server because technically both client and server code is available to the same JVM, but with dedicated server it will fail.

 

What  I've noticed is that you're running around way too fast without fully understanding what you're doing. Furthermore, you're really not listening to our advice. We are giving advice because we know it is important. Why are you even asking if you are discounting our advice?

will fix it later if it crashes right now all I care about is does the particles appear and if so when and where do they appear? If it loads on the server like you say then it will crash but, it won't load on the server it should be the imports that are crashing on startup not during that event it loads into memory going into the else statement which will never happen on the server and crash. It will crash before it even gets into that statement from class not found nothing to do with going into the else statement.

Edited by jredfox
Link to comment
Share on other sites

Just now, jredfox said:

will fix it later if it crashes right now all I care about is does the particles appear?

This is sort of what I mean you you're running too fast. In programming you need to progress cautiously, making sure each piece of code works fully bug-free before moving on to the next part. 

 

Anyway, again are you tracing the execution? If you step through the execution it will be obvious -- you'll see the id, you'll step through the particle spawning code, and you'll see everything that is happening.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

6 minutes ago, diesieben07 said:

That's not how imports work. The class file has no concept of imports. What will crash is the verifier. If you don't know what that is, look it up. It's complicated.

However, if you don't want to do that, trust us please and understand that no, you cannot reference client-only classes from common code. No, even if it's "never called".

Well I didn't even execute code on startup but, had client imports and next thing I know on dedicated server it crashes I never even used them could be mistaking but, remember it in 1.12 with deving silkspawners.

jeblar I need to verify the client code works before making minor patches on server. Or I would constantly be going back and forth and forget what I need to do on the client. If it's major I fix it immediately and I always launch dedicated and test stuff before compiling. "So if anything going too fast would be not fixing client before going back to server" I copied it from a tutorial and minechess mod.

Edited by jredfox
Link to comment
Share on other sites

On 5/9/2018 at 7:24 AM, Choonster said:

 

Entity#getEntityId is completely unrelated to global entity IDs. It's a unique entity ID specifically designed to be sent over the network.

ok thanks

Edited by jredfox
Link to comment
Share on other sites

1 hour ago, jredfox said:

Well I didn't even execute code on startup but, had client imports and next thing I know on dedicated server it crashes I never even used them could be mistaking but, remember it in 1.12 with deving silkspawners.

It has nothing to do with executing. It has to do with the class file being valid at all, meaning that the JVM has to recognize what is inside the file even if it is not executing.

 

If you just had a class that never executed at all that contained reference to a client-only class such as Minecraft or Renderer and such, it will fail. Because the JVM can't have files that it doesn't understand. The server literally has no idea what the Minecraft class is.

 

You might as well have random text in the method -- would you expect a method with random text in it to not cause an error? There is no difference between saying Minecraft.getMinecraft() and Garbage.getGarbage() -- they'll throw the same error.

 

Code can cause an error just by existing if it causes invalid Java, it doesn't have to be executed. Compilation (and the related activities like linking) can't just say "I don't know what that class is but I hope it is never executed".

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

6 minutes ago, jabelar said:

It has nothing to do with executing. It has to do with the class file being valid at all, meaning that the JVM has to recognize what is inside the file even if it is not executing.

 

If you just had a class that never executed at all that contained reference to a client-only class such as Minecraft or Renderer and such, it will fail. Because the JVM can't have files that it doesn't understand. The server literally has no idea what the Minecraft class is.

 

You might as well have random text in the method -- would you expect a method with random text in it to not cause an error? There is no difference between saying Minecraft.getMinecraft() and Garbage.getGarbage() -- they'll throw the same error.

 

Code can cause an error just by existing if it causes invalid Java, it doesn't have to be executed. Compilation (and the related activities like linking) can't just say "I don't know what that class is but I hope it is never executed".

Yeah don't worry already fixed it on server side 

Link to comment
Share on other sites

On 5/8/2018 at 5:52 AM, Choonster said:

 

Yes, call World#spawnParticles on the client World in the packet's handler to spawn the particles.

Edit: after some detailed tests I used EnumParticleTypes.getshouldIngoreRange() since that seems to be what vanilla uses I kill entity player without any mods and it was long distense

could you please explain what EnumParticleTypes.getShouldIgnoreRange() should be done in my code? Should I be using that boolean for long distance when using/creating my own sendPacketToPlayersWithinRange() ?
 

	public static void sendToAllPlayersWithinRange(World world,double x, double y, double z, boolean longDistance,IMessage packet) 
	{
        for (int i = 0; i < world.playerEntities.size(); ++i)
        {
        	EntityPlayerMP player = (EntityPlayerMP) world.playerEntities.get(i);
        	BlockPos blockpos = player.getPosition();
        	double d0 = blockpos.distanceSq(x, y, z);

        	if (d0 <= 1024.0D || longDistance && d0 <= 262144.0D)
        	{
            	NetWorkHandler.INSTANCE.sendTo(packet, player);
        	}
        }
	}

 

Edited by jredfox
Link to comment
Share on other sites

11 hours ago, jredfox said:

could you please explain what EnumParticleTypes.getShouldIgnoreRange() should be done in my code? Should I be using that boolean for long distance whe

 

Looking at the vanilla code it isn't quite clear. Here is all the vanilla type definitions and the boolean is the ignoreRange value:

 

    EXPLOSION_NORMAL("explode", 0, true),
    EXPLOSION_LARGE("largeexplode", 1, true),
    EXPLOSION_HUGE("hugeexplosion", 2, true),
    FIREWORKS_SPARK("fireworksSpark", 3, false),
    WATER_BUBBLE("bubble", 4, false),
    WATER_SPLASH("splash", 5, false),
    WATER_WAKE("wake", 6, false),
    SUSPENDED("suspended", 7, false),
    SUSPENDED_DEPTH("depthsuspend", 8, false),
    CRIT("crit", 9, false),
    CRIT_MAGIC("magicCrit", 10, false),
    SMOKE_NORMAL("smoke", 11, false),
    SMOKE_LARGE("largesmoke", 12, false),
    SPELL("spell", 13, false),
    SPELL_INSTANT("instantSpell", 14, false),
    SPELL_MOB("mobSpell", 15, false),
    SPELL_MOB_AMBIENT("mobSpellAmbient", 16, false),
    SPELL_WITCH("witchMagic", 17, false),
    DRIP_WATER("dripWater", 18, false),
    DRIP_LAVA("dripLava", 19, false),
    VILLAGER_ANGRY("angryVillager", 20, false),
    VILLAGER_HAPPY("happyVillager", 21, false),
    TOWN_AURA("townaura", 22, false),
    NOTE("note", 23, false),
    PORTAL("portal", 24, false),
    ENCHANTMENT_TABLE("enchantmenttable", 25, false),
    FLAME("flame", 26, false),
    LAVA("lava", 27, false),
    FOOTSTEP("footstep", 28, false),
    CLOUD("cloud", 29, false),
    REDSTONE("reddust", 30, false),
    SNOWBALL("snowballpoof", 31, false),
    SNOW_SHOVEL("snowshovel", 32, false),
    SLIME("slime", 33, false),
    HEART("heart", 34, false),
    BARRIER("barrier", 35, false),
    ITEM_CRACK("iconcrack", 36, false, 2),
    BLOCK_CRACK("blockcrack", 37, false, 1),
    BLOCK_DUST("blockdust", 38, false, 1),
    WATER_DROP("droplet", 39, false),
    ITEM_TAKE("take", 40, false),
    MOB_APPEARANCE("mobappearance", 41, true),
    DRAGON_BREATH("dragonbreath", 42, false),
    END_ROD("endRod", 43, false),
    DAMAGE_INDICATOR("damageIndicator", 44, true),
    SWEEP_ATTACK("sweepAttack", 45, true),
    FALLING_DUST("fallingdust", 46, false, 1),
    TOTEM("totem", 47, false),
    SPIT("spit", 48, true);

 

If you look at the RenderGlobal#spawnParticle0() method you'll see that the code includes the following:

            int k1 = this.calculateParticleLevel(minParticles);
            double d3 = entity.posX - xCoord;
            double d4 = entity.posY - yCoord;
            double d5 = entity.posZ - zCoord;

            if (ignoreRange)
            {
                return this.mc.effectRenderer.spawnEffectParticle(particleID, xCoord, yCoord, zCoord, xSpeed, ySpeed, zSpeed, parameters);
            }
            else if (d3 * d3 + d4 * d4 + d5 * d5 > 1024.0D)
            {
                return null;
            }

 

So it looks like if ignoreRange is false then particles will only spawn in a radius of 32 blocks (square root of 1024).

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • my bad, i shared a very old LOG, now must be the right one, im sorry.
    • Hello TileEntity, thanks for your help, is just that i do not have terraria mod installed, i can give you mi list of mods.   EpicFight-20.7.4.jar handcrafted-forge-1.20.1-3.0.6.jar resourcefullib-forge-1.20.1-2.1.25.jar thedragonlib-1.20.1-1.0.0.jar tameablebeasts-1.20.1-5.1.jar geckolib-forge-1.20.1-4.4.6.jar mythicmounts-20.1-7.4.2-forge.jar Patchouli-1.20.1-84-FORGE.jar morevillagers-forge-1.20.1-5.0.0.jar balm-forge-1.20.1-7.3.4-all.jar trashslot-forge-1.20-15.1.0.jar peacefulrecipes 1.20.jar ferritecore-6.0.1-forge.jar darkmining-forge-1.20.1-1.1.0.jar ParCool-1.20.1-3.2.1.2-R.jar minecolonies-1.20.1-1.1.563-RELEASE.jar towntalk-1.20.1-1.1.0.jar structurize-1.20.1-1.0.733-RELEASE.jar blockui-1.20.1-1.0.156-RELEASE.jar domum_ornamentum-1.20.1-1.0.186-RELEASE-universal.jar multipiston-1.20-1.2.43-RELEASE.jar svmm-1.20.1-1.3.0.3.jar InsaneLib-1.13.5-mc1.20.1.jar Satako-7.0.16-1.20.1.jar Bountiful-6.0.3+1.20.1-forge.jar Kambrik-6.1.1+1.20.1-forge.jar kotlinforforge-4.11.0-all.jar kubejs-forge-2001.6.5-build.7.jar rhino-forge-2001.2.2-build.18.jar superbosses-1.2.0-1.20.1.jar lootjs-forge-1.20.1-2.12.0.jar MobsPropertiesRandomness-4.10.8-mc1.20.1.jar Pehkui-3.8.2+1.20.1-forge.jar lostcities-1.20-7.1.8.jar yuushya-1.20.1-forge-2.1.1.jar architectury-9.2.14-forge.jar artifacts-forge-9.5.11.jar curios-forge-5.9.1+1.20.1.jar cloth-config-11.1.118-forge.jar mcdar-4.0.3.jar mcdw-9.0.4.jar mcda-5.0.2.jar Connector-1.0.0-beta.43+1.20.1.jar ConnectorExtras-1.10.1+1.20.1.jar fabric-api-0.92.2+1.11.8+1.20.1.jar immersive_armors-1.6.1+1.20.1-forge.jar cosmeticarmorreworked-1.20.1-v1a.jar K-Turrets-3.0.25-1.20.1.jar M'TEG-1.0.1-1.20.1.jar JustEnoughGuns-0.4.0-1.20.1.jar framework-forge-1.20.1-0.7.6.jar JustEnoughResources-1.20.1-1.4.0.247.jar modernfix-forge-5.18.1+mc1.20.1.jar corpse-forge-1.20.1-1.0.12.jar randombonemealflowers-1.20.1-4.5.jar collective-1.20.1-7.61.jar treeharvester-1.20.1-8.7.jar ImprovableSkills-1.20.1-20.1.8.jar HammerLib-1.20.1-20.1.30.jar easy_mob_farm_1.20.1-7.1.0.jar easy-piglins-forge-1.20.1-1.0.5.jar easy_villagers-1.20.1-1.0.17.jar the_bumblezone-7.4.5+1.20.1-forge.jar productivebees-1.20.1-12.5.3.jar XaerosWorldMap_1.38.8_Forge_1.20.jar Xaeros_Minimap_24.2.0_Forge_1.20.jar jei-1.20.1-forge-15.3.0.8.jar Rats-1.20.1-8.1.2.jar citadel-2.5.4-1.20.1.jar Animation_Overhaul-forge-1.20.x-1.3.1.jar Necronomicon-Forge-1.4.2.jar invtweaks-1.20.1-1.1.0.jar sophisticatedbackpacks-1.20.1-3.20.5.1044.jar sophisticatedcore-1.20.1-0.6.22.611.jar travelersbackpack-forge-1.20.1-9.1.14.jar BetterThirdPerson-Forge-1.20-1.9.0.jar  
    • ill be asleep by the time you respond so mention like a lot of thing to do so when i wake i can try them
    • it instantly crashes
  • Topics

×
×
  • Create New...

Important Information

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