Jump to content

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


Recommended Posts

Posted

Hello everyone!

 

I'm leonardude, and I've been searching around and I can't figure out how to make a custom liquid that has potion effects. Thanks in advance for helping me!

 

  ;D ;D ;D ;D

Leonardude

Posted

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!

Posted

There is no such thing as entity.addPotionEffect

I still don't know what to do. I made a potion effect and a liquid, but I still don't know how to add the potion effect to the liquid.

Posted

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

Posted
  On 11/3/2013 at 12:28 AM, leonardude said:

I can't locate the class EntityLivingBase

 

CTRL+SHIFT+T ?

  Quote

If you guys dont get it.. then well ya.. try harder...

Posted

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!

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

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Make a test with another Launcher like the Curseforge Launcher, MultiMC or AT Launcher
    • can anyone help me i am opening forge and add modpacks and then it says unable to update native luancher and i redownlaod java and the luancher it self?
    • The problem occurs also in 1.20.1 Forge, but with an "Error executing task on client" instead. I have "Sinytra Connector" installed. On 1.21.5 Fabric, there is no problem. When this happens, the chat message before the death screen appears gets sent, with an extra dash added.
    • Well, as usual, it was user error. Naming mismatch in sounds.json.  Please delete this post if you find it necessary. 
    • Hello Forge community.  I'm running into an issue with a mod I'm working on.  To preface, I can call /playsound modId:name music @a and I can hear the sound I registered being played in game. Great!  However, I cannot get it to trigger via my mod code.    Registration: public static final RegistryObject<SoundEvent> A_WORLD_OF_MADNESS = SOUND_EVENTS.register("a_world_of_madness", () -> new SoundEvent(new ResourceLocation("tetheredsouls", "a_world_of_madness")));   Playback: Minecraft mc = Minecraft.getInstance(); if (!(mc.player instanceof LocalPlayer) || mc.level == null) return; LocalPlayer player = (LocalPlayer) mc.player; BlockPos pos = player.blockPosition(); SoundEvent track = ModSounds.A_WORLD_OF_MADNESS.get(); System.out.println(track); System.out.println(pos); System.out.println(player); // play exactly like the tutorial: client-only, at the player's position try { mc.level.playLocalSound( player.getX(), player.getY(), player.getZ(), track, SoundSource.MUSIC, // Or MASTER if needed 1f, 1f, false ); System.out.println("[DEBUG] playSound success: " + track.getLocation()); } catch (Exception e) { System.err.println("[ERROR] Failed to play sound: " + track.getLocation()); e.printStackTrace(); } Sounds.json:   { "theme_of_laura": { "category": "music", "sounds": [ { "name": "tetheredsouls:a_world_of_madness", "stream": true } ] } } Things I have tried: - multiple .ogg files. Short .ogg files (5 seconds, <100KB).  - default minecraft sounds imported from import net.minecraft.sounds.SoundEvents; These work given my code. No idea why these are different.  - playSound() method, as well as several others in past iterations that did not work   I would be forever grateful if somebody could point me in the right direction. I've looked at several mod github repositories and found extremely similar code to what I'm doing. I've also found several threads in this forum that did not solve my issue. I just cannot figure out what I'm doing differently, and why I'm able to queue sounds manually with playsound but the code won't play it (despite confirming the code is being run with the debug statements.)
  • Topics

×
×
  • Create New...

Important Information

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