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

How do I create a custom liquid that has potion effects? [NOT SOLVED: HARD]

Recommended Posts

Well, first take a look at the method, how it should look in your code:

public void onEntityCollidedWithBlock( World world, int x, int y, int z, Entity entity ) {}


Now, we have an Entity. What can we do with an Entity? Yeah, add the potion effect:

public void onEntityCollidedWithBlock( World world, int x, int y, int z, Entity entity ) 
   // Dont know if you need to check if the world is remote
  entity.addPotionEffect( new MyPotionEffect() )
  // The argument obviously must be instanceof PotionEffect

From here you are on you're own!

I am fairly new to Java and modding, so my answers are not always 100% correct. Sorry for that!

Link to post
Share on other sites

Try something like this (didn't tested it):

public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
if (entity instanceof EntityPlayer) {
	((EntityPlayer) entity).addPotionEffect(new PotionEffect(yourArgumentsHere));

Link to post
Share on other sites

I have written the code that you said into my liquid block file and it didn't work.


This is the code for my that has to do with the liquid in my mod's main class:

//Define Fluids
public static Fluid fluidCorrosiveAcid;
public static Block blockCorrosiveAcid;

//Initialize Fluids
fluidCorrosiveAcid = new FluidCorrosiveAcid();
blockCorrosiveAcid = new BlockCorrosiveAcid(3200);

//Register Fluids To The Game

//Register Names Of Fluids
LanguageRegistry.addName(blockCorrosiveAcid, "Corrosive Acid");


This is the code that has to do with the potion in my mod's main class:

//Define Potions
public static Potion corrosiveAcid;

public void preInit(FMLPreInitializationEvent event) {
	Potion[] potionTypes = null;

	for (Field f : Potion.class.getDeclaredFields()) {
		try {
			if (f.getName().equals("potionTypes") || f.getName().equals("field_76425_a")) {
				Field modfield = Field.class.getDeclaredField("modifiers");
				modfield.setInt(f, f.getModifiers() & ~Modifier.FINAL);

				potionTypes = (Potion[])f.get(null);
				final Potion[] newPotionTypes = new Potion[256];
				System.arraycopy(potionTypes, 0, newPotionTypes, 0, potionTypes.length);
				f.set(null, newPotionTypes);
		catch (Exception e) {
			System.err.println("Severe error, please report this to the mod author:");

	MinecraftForge.EVENT_BUS.register(new ZetherEventHooks());

//Initialize Potions
corrosiveAcid = new PotionCorrosiveAcid(32, false, 0).setPotionName("corrosiveAcid");


This is the code for my FluidCorrosiveAcid:

package com.leonardude.zether.blocks;

import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;

public class FluidCorrosiveAcid extends Fluid {

public FluidCorrosiveAcid() {



This is the code for my BlockCorrosiveAcid:

package com.leonardude.zether.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.BlockFluidClassic;

import com.leonardude.zether.main.Zether;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockCorrosiveAcid extends BlockFluidClassic {

public BlockCorrosiveAcid(int id) {
	super(id, Zether.fluidCorrosiveAcid, Material.water);

public void onEntityCollidedWithBlock( World world, int x, int y, int z, Entity entity ) {
	if (entity instanceof EntityLiving) {
		((EntityLiving)entity).addPotionEffect(new PotionEffect(Zether.corrosiveAcid.id, 200, 0));

public Icon getIcon(int side, int meta) {
	return Block.waterMoving.getIcon(side, meta);

public int colorMultiplier(IBlockAccess iblockaccess, int x, int y, int z) {
	return 0x66FF00;



This is the code for my PotionCorrosiveAcid:

package com.leonardude.zether.potions;

import net.minecraft.potion.Potion;

public class PotionCorrosiveAcid extends Potion {

public PotionCorrosiveAcid(int id, boolean par2, int par3) {
	super(id, par2, par3);




And this is the code for the event hook that has to do with the potion:

package com.leonardude.zether.event;

import net.minecraft.util.DamageSource;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;

import com.leonardude.zether.main.Zether;

public class ZetherEventHooks {

public void onEntityUpdate(LivingUpdateEvent event) {
	if (event.entityLiving.isPotionActive(Zether.corrosiveAcid)) {
		if (event.entityLiving.worldObj.rand.nextInt(20) == 0) {
			event.entityLiving.attackEntityFrom(DamageSource.lava, 2);
			if (event.entityLiving.getActivePotionEffect(Zether.corrosiveAcid).getDuration()==0) {



Do I have to register the potion to the game? If so how do I do that?

Please help me, as I have no idea what I am doing wrong!!!

Thanks, in advance!

Link to post
Share on other sites
  • 2 years later...
This topic is now closed to further replies.

  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • So I thought that I had gotten pretty far on my own but now apparently my code crashes the game. I am new to using the forge API and modding in general and some help on why this crashes the game and how to fix it would be greatly appreciated:   public class SpecialItem extends ShootableItem {      public SpecialItem(Properties properties){ super(properties); }      @Override      public Predicate<ItemStack> getInventoryAmmoPredicate() { return null; }      @Override      public int func_230305_d_() { return 15; }      public int tcount=0;      @SubscribeEvent public void ontick(TickEvent.ClientTickEvent event){            tcount++;      }      @Override      public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {      if (!playerIn.getCooldownTracker().hasCooldown(this)) {           playerIn.getCooldownTracker().setCooldown(this, 40);           Vector3d v3 = playerIn.getLook(1);           for (tcount = 0; tcount <= 40;) {                if (tcount%10 == 0 && tcount!= 40) {                     final SmallFireballEntity entitysmallfireball = new SmallFireballEntity(playerIn.getEntityWorld(), playerIn.getPosX(), playerIn.getPosY() + playerIn.getEyeHeight() - 0.4, playerIn.getPosZ(), v3.x + playerIn.getRNG().nextGaussian() * 0.05, v3.y, v3.z);                     entitysmallfireball./* shoot */func_234612_a_(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0f, 1.5f, 1.0f); worldIn.addEntity(entitysmallfireball); } } tcount = 0;                     return ActionResult.resultSuccess(playerIn.getHeldItem(handIn));            } return ActionResult.resultFail(playerIn.getHeldItem(handIn));      } }
    • I found a way to handle this, using javapoet as you suggested. For those who are interested in how it works, you can take a look at my sample here: https://github.com/DarkShadow44/compatibilitymod/tree/sourcegen Might not work with eclipse yet, but it builds properly.
    • It's fired on the logical client and logical server. Most likely you'll only need to execute the logic on the server.
    • If you're translating individual files, there's not much you can do about it. You could use the updateMappings gradlew task, but that's better for large batches of code. As for JSON item models, that is a much more complicated issue that involves layers and custom transform types. While still possible, the tradeoff isn't really worth it.
    • it keeps saying when i i try to install it, it says These libraries failed to download. Try again   
  • Topics

  • Who's Online (See full list)

  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.