2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.item;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2019-01-31 14:58:24 +01:00
|
|
|
import java.util.List;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.ducks.IItemEntity;
|
|
|
|
import com.minelittlepony.unicopia.entity.ItemEntityCapabilities;
|
|
|
|
import com.minelittlepony.unicopia.toxin.Toxicity;
|
2020-01-16 16:46:24 +01:00
|
|
|
import net.minecraft.client.item.TooltipContext;
|
|
|
|
import net.minecraft.entity.EntityType;
|
|
|
|
import net.minecraft.entity.ItemEntity;
|
|
|
|
import net.minecraft.item.Item;
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2020-01-16 16:46:24 +01:00
|
|
|
import net.minecraft.particle.ParticleTypes;
|
|
|
|
import net.minecraft.text.Text;
|
2020-01-27 11:05:22 +01:00
|
|
|
import net.minecraft.util.ActionResult;
|
2019-03-13 21:54:59 +01:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
2019-01-31 14:58:24 +01:00
|
|
|
import net.minecraft.world.World;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2020-04-25 18:41:48 +02:00
|
|
|
public class AppleItem extends Item implements ItemEntityCapabilities.TickableItem {
|
2019-02-07 10:46:59 +01:00
|
|
|
|
2020-04-25 22:22:28 +02:00
|
|
|
public AppleItem(Settings settings) {
|
|
|
|
super(settings);
|
2019-02-06 21:24:22 +01:00
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2019-03-13 21:54:59 +01:00
|
|
|
@Override
|
2020-01-27 11:05:22 +01:00
|
|
|
public ActionResult onGroundTick(IItemEntity item) {
|
2020-04-15 18:12:00 +02:00
|
|
|
ItemEntity entity = item.get().getOwner();
|
2019-03-13 21:54:59 +01:00
|
|
|
|
2020-01-27 11:05:22 +01:00
|
|
|
if (!entity.removed && item.getAge() > item.getPickupDelay()) {
|
2019-03-13 21:54:59 +01:00
|
|
|
|
2020-01-27 11:05:22 +01:00
|
|
|
if (!entity.world.isClient) {
|
|
|
|
entity.remove();
|
2019-03-13 21:54:59 +01:00
|
|
|
|
2020-01-27 11:05:22 +01:00
|
|
|
ItemEntity neu = EntityType.ITEM.create(entity.world);
|
|
|
|
neu.copyPositionAndRotation(entity);
|
2020-04-24 15:23:36 +02:00
|
|
|
neu.setStack(new ItemStack(UItems.ROTTEN_APPLE));
|
2019-03-13 21:54:59 +01:00
|
|
|
|
2020-01-27 11:05:22 +01:00
|
|
|
entity.world.spawnEntity(neu);
|
2019-03-13 21:54:59 +01:00
|
|
|
|
2020-01-27 11:05:22 +01:00
|
|
|
ItemEntity copy = EntityType.ITEM.create(entity.world);
|
|
|
|
copy.copyPositionAndRotation(entity);
|
|
|
|
copy.setStack(entity.getStack());
|
|
|
|
copy.getStack().decrement(1);
|
2019-03-13 21:54:59 +01:00
|
|
|
|
2020-01-27 11:05:22 +01:00
|
|
|
entity.world.spawnEntity(copy);
|
|
|
|
} else {
|
|
|
|
float bob = MathHelper.sin(((float)item.getAge() + 1) / 10F + entity.hoverHeight) * 0.1F + 0.1F;
|
2019-03-13 21:54:59 +01:00
|
|
|
|
2020-01-27 11:05:22 +01:00
|
|
|
for (int i = 0; i < 3; i++) {
|
2020-04-22 16:28:20 +02:00
|
|
|
entity.world.addParticle(ParticleTypes.AMBIENT_ENTITY_EFFECT, entity.getX(), entity.getY() + bob, entity.getZ(),
|
2020-01-27 11:05:22 +01:00
|
|
|
entity.world.random.nextGaussian() - 0.5F,
|
|
|
|
entity.world.random.nextGaussian() - 0.5F,
|
|
|
|
entity.world.random.nextGaussian() - 0.5F);
|
2019-03-13 21:54:59 +01:00
|
|
|
}
|
|
|
|
}
|
2020-01-27 11:05:22 +01:00
|
|
|
}
|
2019-03-13 21:54:59 +01:00
|
|
|
|
2020-01-27 11:05:22 +01:00
|
|
|
return ActionResult.PASS;
|
2019-03-13 21:54:59 +01:00
|
|
|
}
|
|
|
|
|
2019-02-07 11:14:41 +01:00
|
|
|
@Override
|
2020-01-16 16:46:24 +01:00
|
|
|
public void appendTooltip(ItemStack stack, @Nullable World worldIn, List<Text> tooltip, TooltipContext context) {
|
2020-01-27 13:47:14 +01:00
|
|
|
tooltip.add(getToxicity(stack).getTooltip());
|
2019-01-27 16:34:12 +01:00
|
|
|
}
|
|
|
|
|
2020-01-27 13:47:14 +01:00
|
|
|
public Toxicity getToxicity(ItemStack stack) {
|
2019-01-31 14:58:24 +01:00
|
|
|
return Toxicity.SAFE;
|
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|