2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.item;
|
2020-01-17 14:27:26 +01:00
|
|
|
|
2020-04-15 18:12:00 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
|
|
|
import com.minelittlepony.unicopia.magic.Caster;
|
2020-04-25 22:03:36 +02:00
|
|
|
import com.minelittlepony.unicopia.magic.Dispensable;
|
2020-04-15 18:12:00 +02:00
|
|
|
import com.minelittlepony.unicopia.util.projectile.TossableItem;
|
2020-01-17 14:27:26 +01:00
|
|
|
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.block.Material;
|
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
import net.minecraft.entity.effect.StatusEffectInstance;
|
|
|
|
import net.minecraft.entity.effect.StatusEffects;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.ActionResult;
|
|
|
|
import net.minecraft.util.Hand;
|
|
|
|
import net.minecraft.util.TypedActionResult;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2020-04-15 18:12:00 +02:00
|
|
|
public class RottenTomatoItem extends TomatoItem implements TossableItem {
|
2020-01-17 14:27:26 +01:00
|
|
|
|
2020-04-25 18:41:48 +02:00
|
|
|
public RottenTomatoItem(Settings settings) {
|
|
|
|
super(settings);
|
2020-04-25 22:03:36 +02:00
|
|
|
Dispensable.setDispenseable(this, this::dispenseStack);
|
2020-01-17 14:27:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
|
|
|
ItemStack itemstack = player.getStackInHand(hand);
|
|
|
|
|
|
|
|
if (canBeThrown(itemstack) && !player.canConsume(false)) {
|
|
|
|
toss(world, itemstack, player);
|
|
|
|
|
|
|
|
return new TypedActionResult<>(ActionResult.SUCCESS, itemstack);
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.use(world, player, hand);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean isSickening(ItemStack stack, PlayerEntity player) {
|
|
|
|
return canBeThrown(stack)
|
2020-04-15 18:12:00 +02:00
|
|
|
&& !Pony.of(player).getSpecies().canUseEarth();
|
2020-01-17 14:27:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack finishUsing(ItemStack stack, World world, LivingEntity entity) {
|
|
|
|
if (entity instanceof PlayerEntity && isSickening(stack, (PlayerEntity)entity)) {
|
|
|
|
int duration = 7000;
|
|
|
|
|
|
|
|
StatusEffectInstance effect = entity.getStatusEffect(StatusEffects.NAUSEA);
|
|
|
|
|
|
|
|
if (effect != null) {
|
|
|
|
duration += Math.max(0, effect.getDuration());
|
|
|
|
}
|
|
|
|
|
2020-04-22 16:28:20 +02:00
|
|
|
entity.addStatusEffect(new StatusEffectInstance(StatusEffects.NAUSEA, duration, 4));
|
2020-01-17 14:27:26 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
return entity.eatFood(world, stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-15 18:12:00 +02:00
|
|
|
public void onImpact(Caster<?> caster, BlockPos pos, BlockState state) {
|
2020-01-17 14:27:26 +01:00
|
|
|
if (caster.isLocal() && state.getMaterial() == Material.GLASS) {
|
|
|
|
caster.getWorld().breakBlock(pos, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|