Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.10.2] EntityLivingBase#isPotionActive doesn't work with RenderLivingEvent?


lamp3345
 Share

Recommended Posts

I've created custom overlay rendering on entity (just like fire overlay) when entity has potion effect.

My problem is my custom overlay not rendered on other entities but only work with player.

Not sure why it doesn't work :( Please let me know if I doing something wrong, Thanks.

 

Picture

MCEWDDp.png

 

Code

    @SubscribeEvent
    public void onRenderLiving(RenderLivingEvent.Post event)
    {
        EntityLivingBase living = event.getEntity();

        System.out.println(living.getActivePotionEffects().contains(MPPotions.INFECTED_CRYSTALLIZE)); // debug test - always return false

        if (living.isPotionActive(MPPotions.INFECTED_CRYSTALLIZE))
        {
            GlStateManager.disableLighting();
            TextureMap texturemap = this.mc.getTextureMapBlocks();
            TextureAtlasSprite textureatlassprite = texturemap.getAtlasSprite("moreplanets:blocks/infected_crystallize");
            GlStateManager.pushMatrix();
            GlStateManager.translate((float)event.getX(), (float)event.getY(), (float)event.getZ());
            float f = living.width * 1.4F;
            GlStateManager.scale(f, f, f);
            Tessellator tessellator = Tessellator.getInstance();
            VertexBuffer worldrenderer = tessellator.getBuffer();
            float f1 = 0.5F;
            float f2 = 0.0F;
            float f3 = living.height / f;
            float f4 = (float)(living.posY - living.getEntityBoundingBox().minY);
            GlStateManager.rotate(-event.getRenderer().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
            GlStateManager.translate(0.0F, 0.0F, -0.3F + (int)f3 * 0.02F);
            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
            float f5 = 0.0F;
            int i = 0;
            worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);

            while (f3 > 0.0F)
            {
                event.getRenderer().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
                float f6 = textureatlassprite.getMinU();
                float f7 = textureatlassprite.getMinV();
                float f8 = textureatlassprite.getMaxU();
                float f9 = textureatlassprite.getMaxV();

                if (i / 2 % 2 == 0)
                {
                    float f10 = f8;
                    f8 = f6;
                    f6 = f10;
                }
                worldrenderer.pos(f1 - f2, 0.0F - f4, f5).tex(f8, f9).endVertex();
                worldrenderer.pos(-f1 - f2, 0.0F - f4, f5).tex(f6, f9).endVertex();
                worldrenderer.pos(-f1 - f2, 1.4F - f4, f5).tex(f6, f7).endVertex();
                worldrenderer.pos(f1 - f2, 1.4F - f4, f5).tex(f8, f7).endVertex();
                f3 -= 0.45F;
                f4 -= 0.45F;
                f1 *= 0.9F;
                f5 += 0.03F;
                ++i;
            }
            tessellator.draw();
            GlStateManager.popMatrix();
            GlStateManager.enableLighting();
        }

 

Link to comment
Share on other sites

The potion effects of an entity are not known on the client. You have to synchronize them manually.

In your potion class applyAttributesModifiersToEntity will be called when an entity receives your potion effect and removeAttributesModifiersFromEntity will be called when the potion effect is removed. You can use these to send a custom packet to all players tracking that entity (WorldServer::getEntityTracker().getTrackingPlayers). In that packet you need to include Entity::getEntityId, which you can use on the client to get the entity instance back (World::getEntityById). Moreover you will need to subscribe to PlayerEvent.StartTracking, which fires when a player starts tracking an entity. If the entity now being tracked has your potion effect, you also need to notify the client about that, using your packet.

  • Like 1
Link to comment
Share on other sites

I've looking at Twilight Forest render event, Ice Cubed will rendered if entity has slowness attribute.

https://github.com/TeamTwilight/twilightforest/blob/1.11.2/src/main/java/twilightforest/client/TFClientEvents.java#L53-L61

 

So I've try the same way as TW does. (Sorry I'm not expert at custom packet and I really don't understand how to do step by step as you said) But this working correctly.

    private static final AttributeModifier CRYSTALLIZE_POTION_MODIFIER = new AttributeModifier(UUID.fromString("0B0BC323-E263-4EF8-9108-4B6503129B16"), "generic.crystallize_effect", 0, 0);

    @SubscribeEvent
    public void onRenderLiving(RenderLivingEvent.Post event)
    {
        EntityLivingBase living = event.getEntity();
        // check if entity has crystallize potion modifier
        boolean hasPotion = living.getEntityAttribute(InfectedCrystallizeEffect.CRYSTALLIZE_EFFECT) != null ? living.getEntityAttribute(InfectedCrystallizeEffect.CRYSTALLIZE_EFFECT).hasModifier(CRYSTALLIZE_POTION_MODIFIER) : false;

        if (hasPotion)
        {
            GlStateManager.disableLighting();
            TextureMap texturemap = this.mc.getTextureMapBlocks();
            TextureAtlasSprite textureatlassprite = texturemap.getAtlasSprite("moreplanets:blocks/infected_crystallize");
            GlStateManager.pushMatrix();
            GlStateManager.translate((float)event.getX(), (float)event.getY(), (float)event.getZ());
            float f = living.width * 1.4F;
            GlStateManager.scale(f, f, f);
            Tessellator tessellator = Tessellator.getInstance();
            VertexBuffer worldrenderer = tessellator.getBuffer();
            float f1 = 0.5F;
            float f2 = 0.0F;
            float f3 = living.height / f;
            float f4 = (float)(living.posY - living.getEntityBoundingBox().minY);
            GlStateManager.rotate(-event.getRenderer().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
            GlStateManager.translate(0.0F, 0.0F, -0.3F + (int)f3 * 0.02F);
            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
            float f5 = 0.0F;
            int i = 0;
            worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);

            while (f3 > 0.0F)
            {
                event.getRenderer().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
                float f6 = textureatlassprite.getMinU();
                float f7 = textureatlassprite.getMinV();
                float f8 = textureatlassprite.getMaxU();
                float f9 = textureatlassprite.getMaxV();

                if (i / 2 % 2 == 0)
                {
                    float f10 = f8;
                    f8 = f6;
                    f6 = f10;
                }
                worldrenderer.pos(f1 - f2, 0.0F - f4, f5).tex(f8, f9).endVertex();
                worldrenderer.pos(-f1 - f2, 0.0F - f4, f5).tex(f6, f9).endVertex();
                worldrenderer.pos(-f1 - f2, 1.4F - f4, f5).tex(f6, f7).endVertex();
                worldrenderer.pos(f1 - f2, 1.4F - f4, f5).tex(f8, f7).endVertex();
                f3 -= 0.45F;
                f4 -= 0.45F;
                f1 *= 0.9F;
                f5 += 0.03F;
                ++i;
            }
            tessellator.draw();
            GlStateManager.popMatrix();
            GlStateManager.enableLighting();
        }
    }

    @SubscribeEvent
    public void onEntityJoinWorld(EntityJoinWorldEvent event)
    {
        if (event.getEntity() instanceof EntityLivingBase)
        {
            EntityLivingBase living = (EntityLivingBase) event.getEntity();

            // check if generic.crystallize_effect is not registed to AttributeMap
            // also prevent exception on server side
            if (living.getAttributeMap().getAttributeInstanceByName("generic.crystallize_effect") == null)
            {
                living.getAttributeMap().registerAttribute(InfectedCrystallizeEffect.CRYSTALLIZE_EFFECT);
            }
        }
    }

// Potion class
      public static final IAttribute CRYSTALLIZE_EFFECT = new RangedAttribute((IAttribute)null, "generic.crystallize_effect", 0.0D, 0.0D, 0.0D).setShouldWatch(true);

    public InfectedCrystallizeEffect()
    {
        super("infected_crystallize", true, ColorHelper.rgbToDecimal(136, 97, 209), 0);
        this.registerPotionAttributeModifier(InfectedCrystallizeEffect.CRYSTALLIZE_EFFECT, "0B0BC323-E263-4EF8-9108-4B6503129B16", 0.0D, 0);
    }

 

Edited by lamp3345
Link to comment
Share on other sites

Hm, I found some problem. Not a game breaking, So how I can fix this after reload worlds?

[12:48:10] [Server thread/WARN]: Ignoring unknown attribute 'generic.crystallize_effect'

Server Log from SharedMonsterAttributes#setAttributeModifiers

Edited by lamp3345
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
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.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Im trying to make a moddes server with my friends but every single time we get same error https://pastebin.com/UP6P6YSd Is there a way to fix it? Thanks for solutions
    • Take a break, go for a walk. Then try again. 🙂
    • Where did you see that? Sorry if I am being a bother, it's just that I have been staring at this mod for a long time and I'm probably looking over a lot of things
    • Taking a look at AbstractContainerScreen.renderSlot() I got the following code: Method created in my AbstractContainerScreen class: private void renderCustomSlot(PoseStack poseStack,ItemStack itemstack,int x, int y) { boolean visible = true; boolean hover = false; this.setBlitOffset(100); this.itemRenderer.blitOffset = 100.0F; if (visible) { if (hover) { //Draw a rectangle behind the item fill(poseStack, x, y, x + 16, y + 16, -2130706433); } //Render item icon RenderSystem.enableDepthTest(); this.itemRenderer.renderAndDecorateItem(this.minecraft.player, itemstack, x, y, x + y * this.imageWidth); //Render item string count PoseStack posestack = new PoseStack(); if (itemstack.getCount() != 1) { String s = String.valueOf(itemstack.getCount()); posestack.translate(0.0D, 0.0D, itemRenderer.blitOffset + 200.0F); MultiBufferSource.BufferSource multibuffersource$buffersource = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder()); /* float scale; if (s.length()<3){ scale=1f; }else if (s.length()<4){ scale = 0.75f; }else { scale=0.5f; s = s.substring(0,s.length()-3)+"k"; } float compensatingScale = 1/scale; float stringX = (x + 19f - 2 - font.width(s)*scale)*compensatingScale; float stringY =(y + 6f + 3)*compensatingScale; posestack.scale(scale,scale,scale); */ float stringX = (x + 19f - 2 - font.width(s)); float stringY =(y + 6f + 3); font.drawInBatch(s,stringX,stringY,16777215, true, posestack.last().pose(), multibuffersource$buffersource, false, 0, 15728880); //posestack.scale(compensatingScale,compensatingScale,compensatingScale); multibuffersource$buffersource.endBatch(); } } this.itemRenderer.blitOffset = 0.0F; this.setBlitOffset(0); } Now it works correctly: Thanks to warjort for the tip!
    • Hello, I am currently trying to get a forge server setup so I can play the Pixelmon mod with some friends on a private server and have run into some issues with launching my forge server file, I downloaded the forge 12.2.2-14.23.5.2859 installer, downloaded it into a folder on my desktop, ran the Mc server file, agreed to Eula, made a run.bat file to launch the forge server at 6GBs, and when I try launching I get this issue: Pixelmon Server>java -Xmx6144M -Xms6144M -jar forge-1.12.2-14.23.5.2859-universal.jar --nogui We appear to be missing one or more essential library files. You will need to add them to your server before FML and Forge will run successfully.java.lang.ClassNotFoundException: org.objectweb.asm.Type         at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)         at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)         at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)         at java.base/java.lang.Class.forName0(Native Method)         at java.base/java.lang.Class.forName(Class.java:466)         at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.run(ServerLaunchWrapper.java:53)         at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.main(ServerLaunchWrapper.java:34)   I've tried using another minecraft server jar file from a different source to see if that would solve anything but its still coming up with this issue. Any help is greatly appreciated, thanks for your help in advance.
×
×
  • Create New...

Important Information

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