use of net.minecraft.potion.PotionEffect in project Pearcel-Mod by MiningMark48.
the class EventOnHurt method onPlayerHurt.
@SubscribeEvent
public void onPlayerHurt(LivingHurtEvent e) {
if (e.getEntity() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) e.getEntity();
if (!player.isCreative() && player.getHealth() - e.getAmount() <= 0) {
if (player.inventory.hasItemStack(new ItemStack(ModItems.sacrificial_pearcel))) {
player.inventory.removeStackFromSlot(player.inventory.getSlotFor(new ItemStack(ModItems.sacrificial_pearcel)));
if (!player.getEntityWorld().isRemote) {
player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("chat.event.onDie.1")));
}
player.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 60, 0));
e.setCanceled(true);
}
}
}
}
use of net.minecraft.potion.PotionEffect in project Pearcel-Mod by MiningMark48.
the class BlockPearcelSpike method onEntityWalk.
@Override
public void onEntityWalk(World worldIn, BlockPos pos, Entity entityIn) {
if (entityIn instanceof EntityLivingBase) {
if (fakePlayer == null) {
if (!worldIn.isRemote) {
fakePlayer = FakePlayerFactory.get((WorldServer) worldIn, new GameProfile(UUID.randomUUID(), ModBlocks.pearcel_spike.getLocalizedName()));
}
}
if (!(entityIn instanceof EntityPlayer)) {
((EntityLivingBase) entityIn).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 20, 1));
entityIn.attackEntityFrom(DamageSource.causePlayerDamage(fakePlayer), spike_damage);
}
}
super.onEntityWalk(worldIn, pos, entityIn);
}
use of net.minecraft.potion.PotionEffect in project ArsMagica2 by Mithion.
the class AffinityHelper method onEntityLivingBase.
@SubscribeEvent
public void onEntityLivingBase(LivingUpdateEvent event) {
EntityLivingBase ent = event.entityLiving;
if (ent instanceof EntityEnderman) {
if (ent.getLastAttacker() != ent.getAITarget() && ent.getAITarget() instanceof EntityPlayer) {
AffinityData affinityData = AffinityData.For(ent.getAITarget());
float enderDepth = affinityData.getAffinityDepth(Affinity.ENDER);
if (enderDepth == 1.0f) {
ent.setRevengeTarget(null);
}
}
}
if (!(ent instanceof EntityPlayer))
return;
AffinityData affinityData = AffinityData.For(ent);
affinityData.tickDiminishingReturns();
float waterDepth = affinityData.getAffinityDepth(Affinity.WATER);
float fireDepth = affinityData.getAffinityDepth(Affinity.FIRE);
float natureDepth = affinityData.getAffinityDepth(Affinity.NATURE);
float iceDepth = affinityData.getAffinityDepth(Affinity.ICE);
float lifeDepth = affinityData.getAffinityDepth(Affinity.LIFE);
float enderDepth = affinityData.getAffinityDepth(Affinity.ENDER);
float lightningDepth = affinityData.getAffinityDepth(Affinity.LIGHTNING);
AffinityModifiers.instance.applySpeedModifiersBasedOnDepth((EntityPlayer) ent, natureDepth, iceDepth, lightningDepth);
AffinityModifiers.instance.applyHealthModifiers((EntityPlayer) ent, enderDepth, waterDepth, fireDepth, lightningDepth);
applyFulmintion((EntityPlayer) ent, lightningDepth);
if (lightningDepth >= 0.5f) {
ent.stepHeight = 1.014f;
} else if (ent.stepHeight == 1.014f) {
ent.stepHeight = 0.5f;
}
affinityData.accumulatedLifeRegen += 0.025 * lifeDepth;
if (affinityData.accumulatedLifeRegen > 1.0f) {
affinityData.accumulatedLifeRegen -= 1.0f;
ent.heal(1);
}
if (natureDepth == 1.0f) {
if (ent.worldObj.canBlockSeeTheSky((int) ent.posX, (int) ent.posY, (int) ent.posZ) && ent.worldObj.isDaytime()) {
affinityData.accumulatedHungerRegen += 0.02f;
if (affinityData.accumulatedHungerRegen > 1.0f) {
((EntityPlayer) ent).getFoodStats().addStats(1, 0.025f);
affinityData.accumulatedHungerRegen -= 1;
}
} else {
((EntityPlayer) ent).addExhaustion(0.025f);
}
if (ent.isCollidedHorizontally) {
if (!ent.isSneaking()) {
float movement = ExtendedProperties.For(ent).getIsFlipped() ? -0.25f : 0.25f;
ent.moveEntity(0, movement, 0);
ent.motionY = 0;
} else {
ent.motionY *= 0.79999999;
}
ent.fallDistance = 0;
}
}
//Ender Affinity
if (enderDepth >= 0.75f && affinityData.hasActivatedNightVision()) {
if (!ent.worldObj.isRemote && (!ent.isPotionActive(Potion.nightVision.id) || ent.getActivePotionEffect(Potion.nightVision).getDuration() <= 220)) {
ent.addPotionEffect(new PotionEffect(Potion.nightVision.id, 300, 1));
}
}
if (ent.onGround)
affinityData.setLastGroundPosition(new AMVector3(ent));
affinityData.tickCooldown();
if (ent.isInWater()) {
float earthDepth = affinityData.getAffinityDepth(Affinity.EARTH);
if (earthDepth > 0.25f && ent.motionY > -0.3f) {
ent.addVelocity(0, -0.01f * earthDepth, 0);
}
if (waterDepth > 0.5f) {
if (!ent.isPotionActive(BuffList.swiftSwim.id) || ent.getActivePotionEffect(BuffList.swiftSwim).getDuration() < 10) {
ent.addPotionEffect(new BuffEffectSwiftSwim(100, waterDepth > 0.75f ? 2 : 1));
}
}
if (waterDepth > 0.4 && ent.worldObj.rand.nextInt(20) < 4)
ent.setAir(ent.getAir() + 1);
if (!ent.worldObj.isRemote && ent.worldObj.rand.nextInt(100) < 5) {
ent.setAir(ent.getAir() + 1);
byte[] data = new AMDataWriter().add(ent.getEntityId()).add(ent.getAir()).generate();
AMNetHandler.INSTANCE.sendPacketToClientPlayer((EntityPlayerMP) ent, AMPacketIDs.SYNC_AIR_CHANGE, data);
}
boolean waterMovementFlag = false;
if ((ent instanceof EntityPlayer && ((EntityPlayer) ent).inventory.armorInventory[1] != null && ((EntityPlayer) ent).inventory.armorInventory[1].getItem() == ItemsCommonProxy.waterGuardianOrbs)) {
waterMovementFlag = true;
if (!ent.worldObj.isRemote && (!ent.isPotionActive(BuffList.waterBreathing) || ent.getActivePotionEffect(BuffList.waterBreathing).getDuration() <= 200))
ent.addPotionEffect(new BuffEffectWaterBreathing(400, 2));
}
if (waterDepth > 0.5f || waterMovementFlag) {
applyReverseWaterMovement(ent);
}
}
if (ent.worldObj.isRaining() && !ent.worldObj.isRemote && ent.worldObj.getBiomeGenForCoords((int) Math.floor(ent.posX), (int) Math.floor(ent.posZ)).canSpawnLightningBolt()) {
float airDepth = affinityData.getAffinityDepth(Affinity.AIR);
if (airDepth > 0.5f && airDepth < 0.85f && !ent.worldObj.isRemote && ent.worldObj.rand.nextInt(100) < 10) {
if (!ent.isSneaking() && !ent.isPotionActive(BuffList.gravityWell) && !ent.isInsideOfMaterial(Material.water) && ent.isWet()) {
double velX = ent.worldObj.rand.nextDouble() - 0.5;
double velY = ent.worldObj.rand.nextDouble() - 0.5;
double velZ = ent.worldObj.rand.nextDouble() - 0.5;
ent.addVelocity(velX, velY, velZ);
AMNetHandler.INSTANCE.sendVelocityAddPacket(ent.worldObj, ent, velX, velY, velZ);
}
}
}
if (ent.isSneaking()) {
if (iceDepth >= 0.5f) {
makeIceBridge((EntityPlayer) ent, iceDepth);
}
}
}
use of net.minecraft.potion.PotionEffect in project ArsMagica2 by Mithion.
the class AMEventHandler method onPotionBrewed.
@SubscribeEvent
public void onPotionBrewed(PotionBrewedEvent brewEvent) {
for (ItemStack stack : brewEvent.brewingStacks) {
if (stack == null)
continue;
if (stack.getItem() instanceof ItemPotion) {
ItemPotion ptn = ((ItemPotion) stack.getItem());
List<PotionEffect> fx = ptn.getEffects(stack.getItemDamage());
if (fx == null)
return;
for (PotionEffect pe : fx) {
if (pe.getPotionID() == BuffList.greaterManaPotion.id) {
stack = InventoryUtilities.replaceItem(stack, ItemsCommonProxy.greaterManaPotion);
break;
} else if (pe.getPotionID() == BuffList.epicManaPotion.id) {
stack = InventoryUtilities.replaceItem(stack, ItemsCommonProxy.epicManaPotion);
break;
} else if (pe.getPotionID() == BuffList.legendaryManaPotion.id) {
stack = InventoryUtilities.replaceItem(stack, ItemsCommonProxy.legendaryManaPotion);
break;
}
}
}
}
}
use of net.minecraft.potion.PotionEffect in project ConvenientAdditions by Necr0.
the class TileEntityComposter method update.
@Override
public void update() {
if (!getWorld().isRemote) {
for (EntityItem e : getWorld().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(pos.getX(), pos.getY() + 1, pos.getZ(), pos.getX() + 1, pos.getY() + 1.5d, pos.getZ() + 1))) {
if (!e.isDead && !e.getEntityItem().isEmpty()) {
ItemStack i = e.getEntityItem();
i.setCount(stackHandler.insertItem(0, i, false).getCount());
if (i.isEmpty())
e.setDead();
}
}
}
IBlockState state = getWorld().getBlockState(pos);
Random rnd = new Random();
if (!getWorld().isRemote) {
if (content >= ModConfigMisc.composter_progressContent) {
progress++;
if (progress >= ModConfigMisc.composter_progressPeriod) {
progress = 0;
content -= ModConfigMisc.composter_progressContent;
if (getWorld().rand.nextFloat() < ModConfigMisc.composter_compostChance)
Helper.spawnItemInPlace(getWorld(), (double) pos.getX() + .5, (double) pos.getY() + 1.2, (double) pos.getZ() + .5, new ItemStack(ModItems.itemCompost, 1, this.spores ? 1 : 0));
if (getWorld().rand.nextFloat() < ModConfigMisc.composter_extraCompostChance)
Helper.spawnItemInPlace(getWorld(), (double) pos.getX() + .5, (double) pos.getY() + 1.2, (double) pos.getZ() + .5, new ItemStack(ModItems.itemCompost, 1, this.spores ? 1 : 0));
if (getWorld().rand.nextFloat() < ModConfigMisc.composter_dirtChunkChance)
Helper.spawnItemInPlace(getWorld(), (double) pos.getX() + .5, (double) pos.getY() + 1.2, (double) pos.getZ() + .5, new ItemStack(ModItems.itemDirtChunk));
if (getWorld().rand.nextFloat() < ModConfigMisc.composter_fertilizerChance)
Helper.spawnItemInPlace(getWorld(), (double) pos.getX() + .5, (double) pos.getY() + 1.2, (double) pos.getZ() + .5, new ItemStack(ModItems.itemFertilizer));
}
if (content >= ModConfigMisc.composter_capacity && ModConfigMisc.composter_overflowSmell) {
List<EntityPlayer> players = getWorld().getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(pos.getX() - 2, pos.getY() - 2, pos.getZ() - 2, pos.getX() + 3, pos.getY() + 3, pos.getZ() + 3));
for (EntityPlayer p : players) {
switch(rnd.nextInt(120)) {
case 0:
p.addPotionEffect(new PotionEffect(Potion.getPotionById(9), 200, 0));
break;
default:
break;
}
}
}
this.markDirty();
this.getWorld().notifyBlockUpdate(pos, state, state, 3);
} else {
this.progress = 0;
if (this.content == 0)
this.spores = false;
if (processing) {
this.processing = false;
this.markDirty();
this.getWorld().notifyBlockUpdate(pos, state, state, 3);
}
}
} else if (processing) {
if (rnd.nextInt(10) == 0)
getWorld().spawnParticle(EnumParticleTypes.SPELL_MOB, pos.getX() + .5 - ((double) (rnd.nextInt(9) - 4) / 10D), pos.getY() + .2 + (double) content / (double) ModConfigMisc.composter_capacity * .75, pos.getZ() + .5 + ((double) (rnd.nextInt(9) - 4) / 10D), 0, 0.6, 0);
if (content >= ModConfigMisc.composter_capacity)
getWorld().spawnParticle(EnumParticleTypes.SPELL_MOB, pos.getX() + .5 - ((double) (rnd.nextInt(9) - 4) / 10D), pos.getY() + .2 + (double) content / (double) ModConfigMisc.composter_capacity * .75, pos.getZ() + .5 + ((double) (rnd.nextInt(9) - 4) / 10D), 0, 0.6, 0);
}
}
Aggregations