mirror of
https://github.com/GTNewHorizons/Yamcl.git
synced 2026-11-13 00:37:49 +00:00
Added support for Potion-Effects of fluid that has been placed in the world. PotionEffects can be stacked, like IC2 radiation does
This commit is contained in:
1 parent
cbfe9db41a
commit
fdff19b454
2 files changed
+113
-1
No files matched your search
+1
-1
@@ -17,7 +17,7 @@ buildscript {
|
||||
|
||||
apply plugin: 'forge'
|
||||
|
||||
version = "1.7.10-0.5.1"
|
||||
version = "1.7.10-0.5.2"
|
||||
group= "eu.usrv.YAMCore" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
archivesBaseName = "YAMCore"
|
||||
|
||||
|
||||
@@ -1,21 +1,40 @@
|
||||
package eu.usrv.yamcore.fluids;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.BlockFluidClassic;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import eu.usrv.yamcore.YAMCore;
|
||||
|
||||
public class ModSimpleBaseFluid extends BlockFluidClassic {
|
||||
public ModSimpleBaseFluid(Fluid fluid, Material material) {
|
||||
super(fluid, material);
|
||||
_mRegisterBucket = true;
|
||||
_mPotionEffects = new ArrayList<PotionEffect>();
|
||||
_mStackingPotionEffects = new ArrayList<PotionEffect>();
|
||||
_mEffectsOnlyToPlayers = false;
|
||||
_mRand = new Random(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
private List<PotionEffect> _mPotionEffects;
|
||||
private List<PotionEffect> _mStackingPotionEffects;
|
||||
private boolean _mEffectsOnlyToPlayers;
|
||||
private Random _mRand;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected IIcon stillIcon;
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -37,6 +56,35 @@ public class ModSimpleBaseFluid extends BlockFluidClassic {
|
||||
return _mRegisterBucket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add pEffect to the list of potion effects that will not stack over time
|
||||
* @param pEffect
|
||||
*/
|
||||
public void addPotionEffect(PotionEffect pEffect)
|
||||
{
|
||||
_mPotionEffects.add(pEffect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add pEffect to the list of potion effects that will stack over time as long
|
||||
* as the entity remains in the fluid
|
||||
* @param pEffect
|
||||
*/
|
||||
public void addStackingPotionEffect(PotionEffect pEffect)
|
||||
{
|
||||
_mStackingPotionEffects.add(pEffect);
|
||||
}
|
||||
|
||||
/**
|
||||
* If set to true, the potion effects will only be applied to Players.
|
||||
* If you don't set anything here, ALL entities will get the potion effects
|
||||
* @param pFlag
|
||||
*/
|
||||
public void setApplyEffectsToPlayersOnly(boolean pFlag)
|
||||
{
|
||||
_mEffectsOnlyToPlayers = pFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the textures used to indicate still and liquid/flowing state
|
||||
* @param pModID ModID String, used to locate the resources
|
||||
@@ -101,4 +149,68 @@ public class ModSimpleBaseFluid extends BlockFluidClassic {
|
||||
{
|
||||
return _mCreativeTab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(World pWorld, int pX, int pY, int pZ, boolean pDoDrain)
|
||||
{
|
||||
pWorld.setBlockToAir(pX, pY, pZ);
|
||||
return new FluidStack(this.getFluid(), 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(World pWorld, int pX, int pY, int pZ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is triggered when an entity steps into this fluid
|
||||
* @param pWorld
|
||||
* @param pX
|
||||
* @param pY
|
||||
* @param pZ
|
||||
* @param pEntity
|
||||
*/
|
||||
@Override
|
||||
public void onEntityCollidedWithBlock(World pWorld, int pX, int pY, int pZ, Entity pEntity) {
|
||||
super.onEntityCollidedWithBlock(pWorld, pX, pY, pZ, pEntity);
|
||||
|
||||
try
|
||||
{
|
||||
if (!(pEntity instanceof EntityLivingBase))
|
||||
return;
|
||||
|
||||
if (!(pEntity instanceof EntityPlayer) && _mEffectsOnlyToPlayers)
|
||||
return;
|
||||
|
||||
EntityLivingBase tElivBase = (EntityLivingBase)pEntity;
|
||||
|
||||
for (PotionEffect tEffect : _mPotionEffects)
|
||||
tElivBase.addPotionEffect(tEffect);
|
||||
|
||||
if (_mRand.nextInt(10) == 0)
|
||||
{
|
||||
for (PotionEffect tStackingEffect : _mStackingPotionEffects)
|
||||
{
|
||||
int tDuration = tStackingEffect.getDuration();
|
||||
for (Object actEffObj : tElivBase.getActivePotionEffects())
|
||||
{
|
||||
PotionEffect pae = (PotionEffect)actEffObj;
|
||||
|
||||
if (pae.getPotionID() == tStackingEffect.getPotionID())
|
||||
{
|
||||
tDuration += pae.getDuration();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tElivBase.addPotionEffect(new PotionEffect(tStackingEffect.getPotionID(), tDuration, tStackingEffect.getAmplifier()));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
YAMCore.instance.getLogger().error(String.format("Apply potioneffect failed for fluidblock %s", this.getFluid().getUnlocalizedName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user