Potion Effect to FLUIDS?

Started by Kane on

Topic category: Help with modding (Java Edition)

Last seen on 12:58, 23. Sep 2019
Joined Aug 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Potion Effect to FLUIDS?
Fri, 08/26/2016 - 16:33 (edited)

I was wandering how can I add a potion effect when entity collides with my fluid.

I tried messing up with the same block event but it doesn't work (I even tried to make a block with water properties, so I can add the event "on collide" but when I touch that block in game, it crashes).

Any help?

I'd like to know how to add particles too :s

Edited by Kane on Fri, 08/26/2016 - 16:33
Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
In LivingUpdateEvent check
Fri, 08/26/2016 - 21:15

In LivingUpdateEvent check for your fluid block , and then add to entity your effect.
For particles override randomDisplayTick() method.

Last seen on 12:58, 23. Sep 2019
Joined Aug 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:In LivingUpdateEvent check
Sat, 08/27/2016 - 14:22

@#1 How do I check for my fluid?

I tried something like this: [spoiler]public void onLivingUpdateEvent(EntityLivingBase entity, mcreator_blood block) {
        if (entity instanceof EntityLivingBase) {
            if (block instanceof mcreator_blood) {
                ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("poison"), 200, 2));
            }
        }
    }

[/spoiler]

No errors but it deosn't work :/

 

Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This is not how are events
Sat, 08/27/2016 - 21:40

This is not how are events registered. LivingUpdateEvent is the parameter of the void + you need @SubscribeEvent annotation.

Last seen on 12:58, 23. Sep 2019
Joined Aug 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:This is not how are events
Sun, 08/28/2016 - 09:50

@#2 Still nothing and I can't override for particles D:

A little question: Why using the LivingUpdateEvent instead of OnCollide ?

Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
OnColide uses the boundingbox
Sun, 08/28/2016 - 13:43

OnColide uses the boundingbox of block but fluids like every passable block will return null,so you must check from entity, not from item.

Last seen on 12:58, 23. Sep 2019
Joined Aug 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:OnColide uses the boundingbox
Sun, 08/28/2016 - 13:46

@#3 Right, I was asking cause the only few example I found on internet were about onCollide.
Btw, how can I make that LivingUpdate work? I'm really stuck since I get no errors...
Maybe due to the changes to the fluids in this version, I don't know, but the code looks "not normal" :/

Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Have you registred the event
Sun, 08/28/2016 - 13:57

Have you registred the event in a event handler?

Last seen on 12:58, 23. Sep 2019
Joined Aug 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:Have you registred the event
Sun, 08/28/2016 - 14:20

@#4 I'm new to this mechanic, even if I guess it's the base for using events, but I don't really know how to do it

Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You need same "event handler"
Mon, 08/29/2016 - 00:39

You need same "event handler" class that will handle your events. Best start for it is using empty GUI overlay element , because it have registred eventhandler + one event in itself. Remove the void that is in the inner class and make your custom one. You can look on some my post , I alredy wrote many times more decribed tutorial or you can wait until I will write more here. You know ,I am gonna sleep now

Last seen on 12:58, 23. Sep 2019
Joined Aug 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:You need same "event handler"
Mon, 08/29/2016 - 10:18

@#5 I think I made it but the game crash at start and it seems the error involves the eventbus

Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Code + log??
Mon, 08/29/2016 - 11:45

Code + log??

Last seen on 12:58, 23. Sep 2019
Joined Aug 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:Code + log??
Mon, 08/29/2016 - 12:15

@#6 this is the event handler : [spoiler]

package mod.mcreator;

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.event.terraingen.PopulateChunkEvent;
import net.minecraftforge.event.terraingen.DecorateBiomeEvent;
import net.minecraftforge.common.MinecraftForge;

import net.minecraft.world.World;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.Potion;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.EntityLivingBase;

import java.util.Random;

 

//import static net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType.*;

//import static net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.*;

public class mcreator_eventhandler {

    public static class GUIRenderEventClass {
        @SubscribeEvent
        public void onLivingUpdateEvent(EntityLivingBase entity, mcreator_blood block) {
            if (entity instanceof EntityLivingBase) {
                if (block instanceof mcreator_blood) {

                    ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("poison"), 200, 2));

                }
            }

        }

    }

    public mcreator_eventhandler() {
    }

    public static Object instance;

    public void load(FMLInitializationEvent event) {
        MinecraftForge.EVENT_BUS.register(new GUIRenderEventClass());
    }

    public void generateNether(World world, Random random, int chunkX, int chunkZ) {
    }

    public void generateSurface(World world, Random random, int chunkX, int chunkZ) {
    }

    public int addFuel(ItemStack fuel) {
        return 0;
    }

    public void serverLoad(FMLServerStartingEvent event) {
    }

    public void preInit(FMLPreInitializationEvent event) {
    }

    public void registerRenderers() {
    }
}

[/spoiler]

and this is the fluid: [spoiler]

package mod.mcreator;

import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.BlockFluidClassic;
import net.minecraftforge.client.model.ModelLoader;

import net.minecraft.world.World;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.Potion;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemBucket;
import net.minecraft.item.Item;
import net.minecraft.init.Blocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.Minecraft;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.material.Material;

import java.util.Random;

 

public class mcreator_blood {

    public static Object instance;

    static {
        FluidRegistry.enableUniversalBucket();

    }

    public mcreator_blood() {
    }

    public static BlockFluidClassic block = null;
    public static ItemBucket item = null;

    public void preInit(FMLPreInitializationEvent event) {
        ResourceLocation still = new ResourceLocation("blocks/0");
        ResourceLocation flowing = new ResourceLocation("blocks/14");
        Fluid fluid = new Fluid("blood", still, flowing).setLuminosity(0).setDensity(2000).setViscosity(2000).setGaseous(false);
        FluidRegistry.registerFluid(fluid);
        FluidRegistry.addBucketForFluid(fluid);

        block = new BlockFluidClassic(fluid, Material.WATER);
        block.setUnlocalizedName("blood");
        block.setRegistryName("fluid." + block.getFluid().getName());

        GameRegistry.registerBlock(block);

        if (event.getSide() == Side.CLIENT) {
            Item item = Item.getItemFromBlock(block);
            ModelBakery.registerItemVariants(item);
            final ModelResourceLocation loc = new ModelResourceLocation("TestEnvironmentMod:blood", "blood");
            ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {
                @Override
                public ModelResourceLocation getModelLocation(ItemStack stack) {
                    return loc;
                }
            });
            ModelLoader.setCustomStateMapper(block, new StateMapperBase() {
                @Override
                protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
                    return loc;
                }
            });
        }

    }

    public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random random) {
        EntityPlayer entity = Minecraft.getMinecraft().thePlayer;
        int i = pos.getX();
        int j = pos.getY();
        int k = pos.getZ();
        World par1World = world;
        int par2 = i;
        int par3 = j;
        int par4 = k;
        Random par5Random = random;
        if (true)
            for (int la = 0; la < 1; ++la) {
                double d0 = (double) ((float) par2 + 0.5F) + (double) (par5Random.nextFloat() - 0.5F) * 0.09999999850988389D;
                double d1 = ((double) ((float) par3 + 0.7F) + (double) (par5Random.nextFloat() - 0.5F) * 0.09999999850988389D) + 0.5D;
                double d2 = (double) ((float) par4 + 0.5F) + (double) (par5Random.nextFloat() - 0.5F) * 0.09999999850988389D;
                double d3 = 0.2199999988079071D;
                double d4 = 0.27000001072883606D;
                par1World.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
            }

    }

    public void load(FMLInitializationEvent event) {

        GameRegistry.addSmelting(new ItemStack(Blocks.STONE, 1, 6), new ItemStack(item), 1.0f);

    }

    @SubscribeEvent
    public void onLivingUpdateEvent(EntityLivingBase entity, mcreator_blood block) {
        if (entity instanceof EntityLivingBase) {
            if (block instanceof mcreator_blood) {

                ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("poison"), 200, 2));

            }
        }
    }

    public void generateNether(World world, Random random, int chunkX, int chunkZ) {
    }

    public void generateSurface(World world, Random random, int chunkX, int chunkZ) {
    }

    public int addFuel(ItemStack fuel) {
        return 0;
    }

    public void registerRenderers() {

    }

    public void serverLoad(FMLServerStartingEvent event) {
    }

}

[/spoiler]

Error here: [spoiler]Description: Initializing game
java.lang.IllegalArgumentException: Method public void mod.mcreator.mcreator_eventhandler$GUIRenderEventClass.onLivingUpdateEvent(net.minecraft.entity.EntityLivingBase,mod.mcreator.mcreator_blood) has @SubscribeEvent annotation, but requires 2 arguments.  Event handler methods must require a single argument.[/spoiler]

Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
No , the event is parameter
Mon, 08/29/2016 - 12:32

No , the event is parameter of the void:

    @SubscribeEvent
        public void onLivingUpdateEvent(LivingUpdateEvent event) {
                BlockPos pos = new BlockPos(event.entityLiving.posX,event.entityLiving.posY,event.entityLiving.posZ);

World world = event.entityLiving.worldObj;
                if (world.getBlockState(pos).getBlock() instanceof mcreator_blood.YOURINNERCLASSNAME) {

                    event.entityLiving.addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("poison"), 200, 2));

                }
            }

        

    

Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ok  , I see that version
Mon, 08/29/2016 - 12:39

Ok  , I see that version changed a bit so your fluid does not have not inner class so instand of:     if (world.getBlockState(pos).getBlock() instanceof mcreator_blood.YOURINNERCLASSNAME) {

use:

    if (world.getBlockState(pos).getBlock() ==mcreator_blood.block) {

and your particles did not work because the code is outside the instance of block