mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 11:19:19 +00:00
1 parent
9c0b4ceac9
commit
ce30444ba7
2 files changed
+40
-42
No files matched your search
@@ -13,6 +13,7 @@ package vazkii.botania.common.item.equipment.bauble;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.potion.Effect;
|
||||
import net.minecraft.potion.EffectInstance;
|
||||
import net.minecraft.potion.Effects;
|
||||
import vazkii.botania.api.mana.IManaUsingItem;
|
||||
@@ -22,8 +23,8 @@ import vazkii.botania.common.item.ModItems;
|
||||
|
||||
public class ItemWaterRing extends ItemBauble implements IManaUsingItem {
|
||||
|
||||
private static final double SPEED_MULT = 1.2;
|
||||
private static final double MAX_SPEED = 1.3;
|
||||
private static final int COST = 3;
|
||||
private static final int MAGIC_AMPLIFIER = 123;
|
||||
|
||||
public ItemWaterRing(Properties props) {
|
||||
super(props);
|
||||
@@ -32,49 +33,43 @@ public class ItemWaterRing extends ItemBauble implements IManaUsingItem {
|
||||
@Override
|
||||
public void onWornTick(ItemStack stack, LivingEntity living) {
|
||||
if(living.isInWaterOrBubbleColumn()) {
|
||||
if(living instanceof LivingEntity) {
|
||||
// only activate for one ring at a time
|
||||
ItemStack result = EquipmentHandler.findOrEmpty(ModItems.waterRing, living);
|
||||
if(result != stack)
|
||||
return;
|
||||
}
|
||||
// only activate for one ring at a time
|
||||
ItemStack result = EquipmentHandler.findOrEmpty(ModItems.waterRing, living);
|
||||
if(result != stack)
|
||||
return;
|
||||
|
||||
double motionX = living.getMotion().getX() * SPEED_MULT;
|
||||
double motionY = living.getMotion().getY() * SPEED_MULT;
|
||||
double motionZ = living.getMotion().getZ() * SPEED_MULT;
|
||||
double newMX = living.getMotion().getX();
|
||||
double newMY = living.getMotion().getY();
|
||||
double newMZ = living.getMotion().getZ();
|
||||
|
||||
boolean flying = living instanceof PlayerEntity && ((PlayerEntity) living).abilities.isFlying;
|
||||
|
||||
if(Math.abs(motionX) < MAX_SPEED && !flying)
|
||||
newMX = motionX;
|
||||
if(Math.abs(motionY) < MAX_SPEED && !flying)
|
||||
newMY = motionY;
|
||||
if(Math.abs(motionZ) < MAX_SPEED && !flying)
|
||||
newMZ = motionZ;
|
||||
living.setMotion(newMX, newMY, newMZ);
|
||||
|
||||
EffectInstance effect = living.getActivePotionEffect(Effects.NIGHT_VISION);
|
||||
if(effect == null) {
|
||||
EffectInstance neweffect = new EffectInstance(Effects.NIGHT_VISION, Integer.MAX_VALUE, -42, true, true);
|
||||
living.addPotionEffect(neweffect);
|
||||
}
|
||||
|
||||
if(living.getAir() <= 1 && living instanceof PlayerEntity) {
|
||||
int mana = ManaItemHandler.requestMana(stack, (PlayerEntity) living, 300, true);
|
||||
if(mana > 0)
|
||||
living.setAir(mana);
|
||||
if (!living.world.isRemote) {
|
||||
if (living instanceof PlayerEntity && !ManaItemHandler.requestManaExact(stack, (PlayerEntity) living, COST, true)) {
|
||||
onUnequipped(stack, living);
|
||||
} else {
|
||||
addEffect(living, Effects.CONDUIT_POWER);
|
||||
addEffect(living, Effects.DOLPHINS_GRACE);
|
||||
}
|
||||
}
|
||||
} else onUnequipped(stack, living);
|
||||
}
|
||||
|
||||
private static void addEffect(LivingEntity living, Effect effect) {
|
||||
EffectInstance inst = living.getActivePotionEffect(effect);
|
||||
if (inst == null) {
|
||||
EffectInstance neweffect = new EffectInstance(effect, Short.MAX_VALUE, MAGIC_AMPLIFIER, true, true);
|
||||
living.addPotionEffect(neweffect);
|
||||
}
|
||||
}
|
||||
|
||||
private static void removeEffect(LivingEntity living, Effect effect) {
|
||||
EffectInstance inst = living.getActivePotionEffect(effect);
|
||||
if (inst != null && inst.getAmplifier() == MAGIC_AMPLIFIER) {
|
||||
living.removePotionEffect(effect);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequipped(ItemStack stack, LivingEntity living) {
|
||||
EffectInstance effect = living.getActivePotionEffect(Effects.NIGHT_VISION);
|
||||
if(effect != null && effect.getAmplifier() == -42)
|
||||
living.removePotionEffect(Effects.NIGHT_VISION);
|
||||
if (!living.world.isRemote) {
|
||||
removeEffect(living, Effects.CONDUIT_POWER);
|
||||
removeEffect(living, Effects.DOLPHINS_GRACE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user