2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.toxin;
|
2020-01-27 11:05:22 +01:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.Race;
|
2020-04-15 18:12:00 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
2020-01-27 13:47:14 +01:00
|
|
|
import net.minecraft.block.Block;
|
2020-01-27 11:05:22 +01:00
|
|
|
import net.minecraft.client.item.TooltipContext;
|
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2020-01-27 13:47:14 +01:00
|
|
|
import net.minecraft.item.BlockItem;
|
|
|
|
import net.minecraft.item.FoodComponent;
|
2020-01-27 11:05:22 +01:00
|
|
|
import net.minecraft.item.Item;
|
2020-01-27 13:47:14 +01:00
|
|
|
import net.minecraft.item.ItemGroup;
|
2020-01-27 11:05:22 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.text.Text;
|
|
|
|
import net.minecraft.util.ActionResult;
|
|
|
|
import net.minecraft.util.Hand;
|
|
|
|
import net.minecraft.util.TypedActionResult;
|
|
|
|
import net.minecraft.util.UseAction;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2020-04-25 16:07:09 +02:00
|
|
|
public class ToxicBlockItem extends BlockItem {
|
2020-01-27 11:05:22 +01:00
|
|
|
|
2020-01-27 13:47:14 +01:00
|
|
|
private final UseAction action;
|
2020-01-27 11:05:22 +01:00
|
|
|
private final Toxicity toxicity;
|
2020-04-25 16:07:09 +02:00
|
|
|
private final Toxin toxin;
|
2020-01-27 11:05:22 +01:00
|
|
|
|
2020-04-25 16:07:09 +02:00
|
|
|
public ToxicBlockItem(Block block, Item.Settings settings, int hunger, float saturation, UseAction action, Toxicity toxicity, Toxin toxin) {
|
2020-01-27 13:47:14 +01:00
|
|
|
super(block, settings
|
|
|
|
.group(ItemGroup.FOOD)
|
|
|
|
.food(new FoodComponent.Builder()
|
|
|
|
.hunger(hunger)
|
|
|
|
.saturationModifier(saturation)
|
|
|
|
.build()));
|
2020-01-27 11:05:22 +01:00
|
|
|
this.toxicity = toxicity;
|
2020-01-27 13:47:14 +01:00
|
|
|
this.action = action;
|
2020-04-25 16:07:09 +02:00
|
|
|
this.toxin = toxin;
|
2020-01-27 11:05:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public UseAction getUseAction(ItemStack stack) {
|
2020-01-27 13:47:14 +01:00
|
|
|
return action;
|
2020-01-27 11:05:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
|
2020-04-25 16:07:09 +02:00
|
|
|
tooltip.add(toxicity.getTooltip());
|
2020-01-27 11:05:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack finishUsing(ItemStack stack, World world, LivingEntity entity) {
|
|
|
|
super.finishUsing(stack, world, entity);
|
|
|
|
|
|
|
|
if (entity instanceof PlayerEntity) {
|
2020-04-15 18:12:00 +02:00
|
|
|
Race race = Pony.of((PlayerEntity)entity).getSpecies();
|
2020-04-25 16:07:09 +02:00
|
|
|
Toxicity toxicity = (race.isDefault() || race == Race.CHANGELING) ? Toxicity.LETHAL : this.toxicity;
|
2020-01-27 11:05:22 +01:00
|
|
|
|
2020-04-25 16:07:09 +02:00
|
|
|
toxin.addSecondaryEffects((PlayerEntity)entity, toxicity, stack);
|
2020-01-27 11:05:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return new ItemStack(getRecipeRemainder());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
2020-04-15 18:12:00 +02:00
|
|
|
Race race = Pony.of(player).getSpecies();
|
2020-01-27 11:05:22 +01:00
|
|
|
|
|
|
|
if (race.isDefault() || race == Race.CHANGELING) {
|
|
|
|
return new TypedActionResult<>(ActionResult.FAIL, player.getStackInHand(hand));
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.use(world, player, hand);
|
|
|
|
}
|
|
|
|
}
|