Jump to content

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


leonardude

Recommended Posts

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

@Override
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 comment
Share on other sites

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

@Override
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 comment
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
GameRegistry.registerBlock(blockCorrosiveAcid);

//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;

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

	for (Field f : Potion.class.getDeclaredFields()) {
		f.setAccessible(true);
		try {
			if (f.getName().equals("potionTypes") || f.getName().equals("field_76425_a")) {
				Field modfield = Field.class.getDeclaredField("modifiers");
				modfield.setAccessible(true);
				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:");
			System.err.println(e);
		}
	}

	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() {
	super("fluidCorrosiveAcid");
	this.setDensity(10);
	this.setViscosity(1000);
	FluidRegistry.registerFluid(this);
}

}

 

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);
	this.setCreativeTab(CreativeTabs.tabBlock);
	Zether.fluidCorrosiveAcid.setBlockID(id);
}

@Override
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));
	}
}

@Override
@SideOnly(Side.CLIENT)
public Icon getIcon(int side, int meta) {
	return Block.waterMoving.getIcon(side, meta);
}

@Override
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 {

@ForgeSubscribe
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) {
				event.entityLiving.removePotionEffect(Zether.corrosiveAcid.id);
				return;
			}
		}
	}
}

}

 

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 comment
Share on other sites

  • 2 years later...
Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • JANGKRIK4D >> SLOT DANA GOPAY OVO | SLOT GACOR GAMPANG MAXWIN X100 X250 X500  << DAFTAR JANGKRIK4D >> JANGKRIK4D SITUS SLOT PGSOFT GAMING TERPERCAYA JANGKRIK4D 🚀 SITUS PGSLOT DAN PGSOFT GAMING TERPERCAYA 🚀 – JANGKRIK4D situs pgslot paling gacor telah hadir bersama JANGKRIK4D yang karena telah memberikan berbagai macam permainan untuk mendapatkan jackpot yang besar karena sudah menjadi pioneer untuk penyedia game paling mujarab beserta jajaran pgsoft gaming terpercaya yang telah bersama dengan JANGKRIK4D menjalin kerja sama resmi serta berlisensi untuk memberikan kemenangan paling besar untuk para player yang mencoba menamatkan permainan yang telah memeberikan kemenangan fantastis saat ini. jangkrik4d slot gacor slot deposit dana demo slot gacor demo slot pg demo pg soft slot deposit gopay slot deposit pulsa slot server jepang
    • LINK DAFTAR KLIK DISINI slot deposit dana 5000 ribu via spaylater  adalah permainan slot dana gacor dengan menyediakan slot server thailand deposit dana. dan slot deposit dana adalah slot terbesar di thailand. anda cukup daftar disini dan mainkan disini slot deposit 5000 ribu via dana sudah dipastikan dengan deposit dana akan membuat akun anda menjadi akun special. situs deposit dana adalah situs yang terpercaya dan terakurat. Slot dana merupakan situs slot deposit dana yang sangat trending dan sangat dikenal luas di masyarakat. dengan adanya MAXWINBET77 anda bisa mendapatkan keuntungan besar setiap hari tanpa adanya potongan  yang pastinya menguntungkan bagi anda. situs slot dana  maxwinbet77 adalah situs slot dana terbaik 2024 dan dijamin mudah maxwin.
    • MELATI88 adalah pilihan terbaik bagi Anda yang ingin bermain slot dengan deposit pulsa tanpa potongan besar sebesar 5000. Dengan berbagai keunggulan yang kami tawarkan, kami siap memberikan Anda pengalaman bermain yang tak terlupakan. Bergabunglah dengan kami sekarang dan mulailah petualangan bermain slot yang seru dan menguntungkan!    
    • SENSASLOT adalah pilihan tepat bagi Anda yang menginginkan pengalaman bermain slot tanpa potongan besar saat deposit menggunakan Dana. Berikut adalah beberapa alasan mengapa Anda harus memilih SENSASLOT: Deposit Dana Tanpa Potongan Kami bangga menjadi salah satu situs slot pertama yang menawarkan deposit menggunakan Dana tanpa potongan besar sebesar 1000 ribu. Ini berarti Anda dapat melakukan deposit sebesar 1000 ribu dan mendapatkan seluruhnya untuk digunakan dalam permainan slot kami. Beragam Pilihan Permainan SENSASLOT menyajikan koleksi permainan slot yang beragam dan menarik dari berbagai provider terkemuka. Mulai dari tema klasik hingga yang paling modern, Anda akan menemukan banyak pilihan permainan yang sesuai dengan selera dan preferensi Anda. Kemudahan Bertransaksi Selain deposit Dana tanpa potongan besar, kami juga menyediakan berbagai metode pembayaran lainnya untuk kenyamanan Anda. Proses deposit dan penarikan dana di SENSASLOT cepat, mudah, dan aman.    
    • GIGASLOT adalah pilihan utama bagi para pemain yang menginginkan pengalaman bermain slot yang menyenangkan dan menguntungkan. Berikut adalah beberapa alasan mengapa Anda harus memilih GIGASLOT: Slot Gacor dengan Maxwin Kami menyajikan koleksi slot gacor terbaik dengan peluang meraih maxwin yang menggiurkan. Dengan berbagai tema permainan dan fitur bonus yang menarik, Anda akan selalu merasa terhibur dan berkesempatan untuk meraih kemenangan besar. Deposit Terjangkau Melalui Bank Permata Kami memahami bahwa kemudahan dalam bertransaksi adalah hal penting bagi para pemain. Oleh karena itu, kami menyediakan layanan deposit melalui Bank Permata dengan nominal deposit yang terjangkau, mulai dari 10K saja! Prosesnya cepat, mudah, dan aman, sehingga Anda dapat langsung memulai petualangan bermain tanpa hambatan. GIGASLOT adalah pilihan terbaik untuk Anda yang ingin menikmati slot gacor dengan maxwin dan melakukan deposit yang terjangkau melalui Bank Permata. Dengan berbagai keunggulan yang kami tawarkan, kami siap memberikan Anda pengalaman bermain .    
  • Topics

×
×
  • Create New...

Important Information

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