use of net.minecraft.potion.EffectInstance in project NetherEx by LogicTechCorp.
the class SoulGlassBlock method onEntityCollision.
@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
if (entity instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity) entity;
boolean sinking = player.getLookVec().y < -0.75D;
CompoundNBT playerData = player.getPersistentData();
Direction shootDirection = null;
if (!player.isPotionActive(NetherExEffects.SOUL_SUCKED.get())) {
playerData.remove(SHOOT_DIRECTION_KEY);
}
if (playerData.contains(SHOOT_DIRECTION_KEY)) {
shootDirection = Direction.byIndex(playerData.getInt(SHOOT_DIRECTION_KEY));
}
if (player.isShiftKeyDown()) {
if (!sinking) {
if (shootDirection == null) {
shootDirection = player.getHorizontalFacing().getOpposite();
}
Block blockOneBack = world.getBlockState(pos.offset(shootDirection)).getBlock();
Block blockTwoBack = world.getBlockState(pos.offset(shootDirection, 2)).getBlock();
Block blockThreeBack = world.getBlockState(pos.offset(shootDirection, 3)).getBlock();
if (blockOneBack != this) {
player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 0, false, false));
}
if (blockOneBack == this && blockTwoBack != this) {
player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 1, false, false));
} else if (blockOneBack == this && blockThreeBack != this) {
player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 2, false, false));
} else if (blockOneBack == this) {
player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 3, false, false));
}
} else {
if (shootDirection == null) {
shootDirection = Direction.UP;
}
Block blockUpOne = world.getBlockState(pos.up()).getBlock();
Block blockUpTwo = world.getBlockState(pos.up(2)).getBlock();
Block blockUpThree = world.getBlockState(pos.up(3)).getBlock();
if (blockUpOne != this) {
player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 0, false, false));
}
if (blockUpOne == this && blockUpTwo != this) {
player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 1, false, false));
} else if (blockUpOne == this && blockUpThree != this) {
player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 2, false, false));
} else if (blockUpOne == this) {
player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 3, false, false));
player.setPosition(player.getPosX(), player.prevPosY, player.getPosZ());
}
player.setMotion(player.getMotion().mul(1.0D, 0.25D, 1.0D));
}
} else {
EffectInstance effect = player.getActivePotionEffect(NetherExEffects.SOUL_SUCKED.get());
int amplifier = 1;
if (effect != null) {
amplifier = (effect.getAmplifier() + 1);
}
Vec3d motion = player.getMotion();
if (!sinking && shootDirection != null && shootDirection != Direction.UP) {
Direction playerDirection = shootDirection.getOpposite();
if (playerDirection == Direction.NORTH) {
if (motion.getZ() < 0) {
player.setMotion(motion.mul(1.0D, 1.0D, -1.0D));
} else if (motion.getZ() == 0) {
player.setMotion(new Vec3d(motion.getX(), motion.getY(), 0.5D));
}
} else if (playerDirection == Direction.EAST) {
if (motion.getX() > 0) {
player.setMotion(motion.mul(-1.0D, 1.0D, 1.0D));
} else if (motion.getX() == 0) {
player.setMotion(new Vec3d(-0.5D, motion.getY(), motion.getZ()));
}
} else if (playerDirection == Direction.SOUTH) {
if (motion.getZ() > 0) {
player.setMotion(motion.mul(1.0D, 1.0D, -1.0D));
} else if (motion.getZ() == 0) {
player.setMotion(new Vec3d(motion.getX(), motion.getY(), -0.5D));
}
} else if (playerDirection == Direction.WEST) {
if (motion.getX() < 0) {
player.setMotion(motion.mul(-1.0D, 1.0D, 1.0D));
} else if (motion.getX() == 0) {
player.setMotion(new Vec3d(0.5D, motion.getY(), motion.getZ()));
}
}
if (motion.getX() > -6.0D && motion.getX() < 6.0D) {
player.setMotion(new Vec3d((motion.getX() * 1.15D * amplifier), motion.getY(), motion.getZ()));
}
if (motion.getZ() > -6.0D && motion.getZ() < 6.0D) {
player.setMotion(new Vec3d(motion.getX(), motion.getY(), (motion.getZ() * 1.15D * amplifier)));
}
} else {
if (motion.getY() <= 0) {
player.setMotion(new Vec3d(motion.getX(), 0.105D, motion.getZ()));
}
if (motion.getY() < 1.315D) {
player.setMotion(new Vec3d(motion.getX(), (motion.getY() + (amplifier * 0.1D)), motion.getZ()));
}
}
}
if (shootDirection != null) {
playerData.putInt(SHOOT_DIRECTION_KEY, shootDirection.getIndex());
}
}
}
use of net.minecraft.potion.EffectInstance in project NetherEx by LogicTechCorp.
the class SporeCreeperEntity method spawnLingeringCloud.
private void spawnLingeringCloud() {
Collection<EffectInstance> effects = this.getActivePotionEffects();
if (!effects.isEmpty()) {
AreaEffectCloudEntity cloud = new AreaEffectCloudEntity(this.world, this.getPosX(), this.getPosY(), this.getPosZ());
cloud.setRadius(2.5F);
cloud.setRadiusOnUse(-0.5F);
cloud.setWaitTime(10);
cloud.setDuration(cloud.getDuration() / 2);
cloud.setRadiusPerTick(-cloud.getRadius() / (float) cloud.getDuration());
for (EffectInstance effect : effects) {
cloud.addEffect(new EffectInstance(effect));
}
this.world.addEntity(cloud);
}
}
use of net.minecraft.potion.EffectInstance in project AgriCraft by AgriCraft.
the class JsonPlantCallBackPoisoning method onEntityCollision.
public void onEntityCollision(@Nonnull IAgriCrop crop, Entity entity) {
if (entity instanceof LivingEntity && !entity.isSneaking() && !entity.getEntityWorld().isRemote) {
LivingEntity livingEntity = ((LivingEntity) entity);
if (!livingEntity.isPotionActive(Effects.POISON)) {
EffectInstance poison = new EffectInstance(Effects.POISON, (int) (20 * crop.getStats().getAverage()));
((LivingEntity) entity).addPotionEffect(poison);
}
}
}
use of net.minecraft.potion.EffectInstance in project Overloaded by CJ-MC-Mods.
the class ArmorEventHandler method tryRemoveHarmful.
private void tryRemoveHarmful(@Nonnull PlayerEntity player, @Nonnull LogicalSide side) {
Iterator<EffectInstance> potionEffectIterator = player.getActiveEffects().iterator();
while (potionEffectIterator.hasNext()) {
EffectInstance effect = potionEffectIterator.next();
Effect potion = effect.getEffect();
if (potion.isBeneficial())
continue;
if (!extractEnergy(player, OverloadedConfig.INSTANCE.multiArmorConfig.removeEffect, true)) {
continue;
}
if (extractEnergy(player, OverloadedConfig.INSTANCE.multiArmorConfig.removeEffect, side == LogicalSide.CLIENT)) {
// If not canceled
if (!MinecraftForge.EVENT_BUS.post(new PotionEvent.PotionRemoveEvent(player, potion))) {
potionEffectIterator.remove();
}
}
}
}
use of net.minecraft.potion.EffectInstance in project AgriCraft by AgriCraft.
the class JsonPlantCallBackWithering method onEntityCollision.
public void onEntityCollision(@Nonnull IAgriCrop crop, Entity entity) {
if (entity instanceof LivingEntity) {
EffectInstance wither = new EffectInstance(Effects.WITHER, (int) (10 * crop.getStats().getAverage()));
((LivingEntity) entity).addPotionEffect(wither);
}
}
Aggregations