2020-09-22 15:11:20 +02:00
|
|
|
package com.minelittlepony.unicopia.item;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2022-01-04 23:43:07 +01:00
|
|
|
import com.minelittlepony.unicopia.USounds;
|
2020-09-22 15:11:20 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.IItemEntity;
|
|
|
|
import com.minelittlepony.unicopia.entity.ItemImpl;
|
|
|
|
|
2021-08-04 15:38:03 +02:00
|
|
|
import net.minecraft.entity.Entity.RemovalReason;
|
2020-01-16 16:46:24 +01:00
|
|
|
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;
|
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;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2022-03-26 22:51:34 +01:00
|
|
|
public class AppleItem {
|
|
|
|
private static final ItemImpl.GroundTickCallback TICK_CALLBACK = AppleItem::onGroundTick;
|
|
|
|
|
|
|
|
private AppleItem() { }
|
2019-02-07 10:46:59 +01:00
|
|
|
|
2022-03-26 22:51:34 +01:00
|
|
|
public static <T extends Item> T registerTickCallback(T item) {
|
|
|
|
return ItemImpl.registerTickCallback(item, TICK_CALLBACK);
|
2019-02-06 21:24:22 +01:00
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2022-03-26 22:51:34 +01:00
|
|
|
private static ActionResult onGroundTick(IItemEntity item) {
|
2022-12-19 17:27:24 +01:00
|
|
|
ItemEntity entity = item.get().asEntity();
|
2019-03-13 21:54:59 +01:00
|
|
|
|
2023-06-03 13:40:54 +02:00
|
|
|
if (!entity.isRemoved() && item.getPickupDelay() == 0 && item.getAge() > 2030 && entity.getWorld().random.nextInt(150) < 10) {
|
2019-03-13 21:54:59 +01:00
|
|
|
|
2023-06-03 13:40:54 +02:00
|
|
|
if (!entity.getWorld().isClient) {
|
2021-08-04 15:38:03 +02:00
|
|
|
entity.remove(RemovalReason.KILLED);
|
2019-03-13 21:54:59 +01:00
|
|
|
|
2023-06-03 13:40:54 +02:00
|
|
|
ItemEntity neu = EntityType.ITEM.create(entity.getWorld());
|
2020-01-27 11:05:22 +01:00
|
|
|
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
|
|
|
|
2023-06-03 13:40:54 +02:00
|
|
|
entity.getWorld().spawnEntity(neu);
|
2019-03-13 21:54:59 +01:00
|
|
|
|
2023-06-03 13:40:54 +02:00
|
|
|
ItemEntity copy = EntityType.ITEM.create(entity.getWorld());
|
2020-01-27 11:05:22 +01:00
|
|
|
copy.copyPositionAndRotation(entity);
|
|
|
|
copy.setStack(entity.getStack());
|
|
|
|
copy.getStack().decrement(1);
|
2019-03-13 21:54:59 +01:00
|
|
|
|
2023-06-03 13:40:54 +02:00
|
|
|
entity.getWorld().spawnEntity(copy);
|
2019-03-13 21:54:59 +01:00
|
|
|
}
|
2021-01-27 17:03:57 +01:00
|
|
|
|
2021-08-04 15:38:03 +02:00
|
|
|
float bob = MathHelper.sin(((float)item.getAge() + 1) / 10F + entity.uniqueOffset) * 0.1F + 0.1F;
|
2021-01-27 17:03:57 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
2023-06-03 13:40:54 +02:00
|
|
|
entity.getWorld().addParticle(ParticleTypes.AMBIENT_ENTITY_EFFECT, entity.getX(), entity.getY() + bob, entity.getZ(),
|
|
|
|
entity.getWorld().random.nextGaussian() - 0.5F,
|
|
|
|
entity.getWorld().random.nextGaussian() - 0.5F,
|
|
|
|
entity.getWorld().random.nextGaussian() - 0.5F);
|
2021-01-27 17:03:57 +01:00
|
|
|
}
|
2022-01-04 23:43:07 +01:00
|
|
|
entity.playSound(USounds.ITEM_APPLE_ROT, 0.5F, 1.5F);
|
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
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|