Started by
Kane
on
Topic category: Help with modding (Java Edition)
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
@#8 I had already tried with the event as parameter but it still gives me error cannot find symbol class: LivungUpdateEvent
And for partcles I have to add a sort of if (x) ?
Sorry surely it's a dumb question but I'm fusing here trying to understand ways to do this stuff by more than 2 days :S
Tried: import net.minecraftforge.event.entity.living.LivingEvent.*; ?
And for partcles , it must be in the instance of the BlockFluidClassic , I do not mea use instanceof statement.
@#9 I've imported this: net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
but now I get this error: entityLiving has private access in LivingEvent
About particles, I can't really get where since it's a "strage" class this liquid...
I cannot orientate D:
You are using 1.10.x , right?Change every event.entityLiving to event.getEntityLiving()
@#10 P E R F E C T !
I only need those odious particles (that don't work on a normal block too, still bugged).
If you can give me some other clues :S
Simply if something has to be in instance of something , it means :
a) if the something is a class , put the code to the class:
public static class FluidClass extends BlockLiquid{
public FluidClass(){
super();
}
public void YOUR_VOID(){
......
}
}
b) if the something is called instance of some class:
BlockFluidCustom block = new BlockFluidCustom();
You need add brackets and between them the void:
BlockFluidCustom block = new BlockFluidCustom(){
public void YOUR_VOID(){
......
}
};
@#11 ok, but it seems to doens't work the same.
First I tried to write it after block = new BlockFluidClassic(fluid, Material.WATER);
(adding it before the ; inside 2 brackets)
No errors but no particles too.
So I tried writing it after everything "possible" but I always get same errors.
Could be the particles code not updated or something? Since I got it directly from the one of block mod in mcreator (and it doesn't work)
@#11 One night trying to make it work in any way but nothing...
I think I'm going to give up on damn particles D:
I tried to find the fluid class to "study" lava code in eclipse, but I cannot find it!
Can I see your code?
@#12 [spoiler]
package mod.mcreator;
import net.minecraftforge.fml.relauncher.SideOnly;
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.event.entity.living.LivingEvent.LivingUpdateEvent;
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.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) {
@SideOnly(Side.CLIENT)
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.SPELL_INSTANT, d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
}
}
};
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 load(FMLInitializationEvent event) {
GameRegistry.addSmelting(new ItemStack(Blocks.STONE, 1, 6), new ItemStack(item), 1.0f);
}
@SubscribeEvent
public void onLivingUpdateEvent(LivingUpdateEvent event) {
BlockPos pos = new BlockPos(event.getEntityLiving().posX, event.getEntityLiving().posY, event.getEntityLiving().posZ);
World world = event.getEntityLiving().worldObj;
if (world.getBlockState(pos).getBlock() == mcreator_blood.block) {
event.getEntityLiving().addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("weakness"), 200, 2));
event.getEntityLiving().addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("slowness"), 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]
I put @SideOnly since I found that particles are client only, but don't know if I'm right
@#12.1
Try:
[spoiler]
package mod.mcreator;
import net.minecraftforge.fml.relauncher.SideOnly;
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.event.entity.living.LivingEvent.LivingUpdateEvent;
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.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){
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
double b0 = (double)pos.getX();
double b1 = (double)pos.getY();
double b2 = (double)pos.getZ();
World par1World = world;
for (int la = 0; la < 1; ++la) {
double d0 = (double) ((float) b0 + 0.5F) + (double) (par5Random.nextFloat() - 0.5F) * 0.09999999850988389D;
double d1 = ((double) ((float) b1 + 0.7F) + (double) (par5Random.nextFloat() - 0.5F) * 0.09999999850988389D) + 0.5D;
double d2 = (double) ((float) b2 + 0.5F) + (double) (par5Random.nextFloat() - 0.5F) * 0.09999999850988389D;
double d3 = 0.2199999988079071D;
double d4 = 0.27000001072883606D;
par1World.spawnParticle(EnumParticleTypes.SPELL_INSTANT, d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
}
}};
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 load(FMLInitializationEvent event) {
GameRegistry.addSmelting(new ItemStack(Blocks.STONE, 1, 6), new ItemStack(item), 1.0f);
}
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]
and instand of the par5Random use rand
@#13 And yes, it works too perfectly to be true!
Even if I don't understand why with this code, I can Override :/ Wonderful :D
Thank you again and again Nuparu, basically it's not my mod anymore, I'm just bringing YOUR codes to life x)