From 1e880b6ef640a6c7aed3a52e6e972dc952ddd351 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 30 Sep 2020 03:26:04 +0200 Subject: [PATCH] finished the token of undying friendship --- .../naturesaura/models/item/pet_reviver.json | 6 ++++ .../naturesaura/items/ItemPetReviver.java | 28 ++++++++++++++++-- .../naturesaura/textures/item/pet_reviver.png | Bin 0 -> 315 bytes .../book/en_us/entries/items/pet_reviver.json | 21 +++++++++++++ .../data/naturesaura/recipes/pet_reviver.json | 28 ++++++++++++++++++ 5 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 src/generated/resources/assets/naturesaura/models/item/pet_reviver.json create mode 100644 src/main/resources/assets/naturesaura/textures/item/pet_reviver.png create mode 100644 src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/items/pet_reviver.json create mode 100644 src/main/resources/data/naturesaura/recipes/pet_reviver.json diff --git a/src/generated/resources/assets/naturesaura/models/item/pet_reviver.json b/src/generated/resources/assets/naturesaura/models/item/pet_reviver.json new file mode 100644 index 00000000..089068a4 --- /dev/null +++ b/src/generated/resources/assets/naturesaura/models/item/pet_reviver.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "naturesaura:item/pet_reviver" + } +} \ No newline at end of file diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemPetReviver.java b/src/main/java/de/ellpeck/naturesaura/items/ItemPetReviver.java index 5b99b0cc..de9877a1 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemPetReviver.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemPetReviver.java @@ -12,6 +12,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.SpawnLocationHelper; import net.minecraft.item.ItemStack; +import net.minecraft.particles.ParticleTypes; import net.minecraft.util.ActionResultType; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; @@ -21,6 +22,7 @@ import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.server.ServerWorld; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.LivingDeathEvent; +import net.minecraftforge.event.entity.living.LivingEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -36,11 +38,31 @@ public class ItemPetReviver extends ItemImpl { private static class Events { + @SubscribeEvent + public void onEntityTick(LivingEvent.LivingUpdateEvent event) { + LivingEntity entity = event.getEntityLiving(); + if (entity.world.isRemote || entity.world.getGameTime() % 20 != 0 || !(entity instanceof TameableEntity)) + return; + TameableEntity tameable = (TameableEntity) entity; + if (!tameable.isTamed() || !tameable.getPersistentData().getBoolean(NaturesAura.MOD_ID + ":pet_reviver")) + return; + LivingEntity owner = tameable.getOwner(); + if (owner == null || owner.getDistanceSq(tameable) > 5 * 5) + return; + if (entity.world.rand.nextFloat() >= 0.65F) { + ((ServerWorld) entity.world).spawnParticle(ParticleTypes.HEART, + entity.getPosX() + entity.world.rand.nextGaussian() * 0.25F, + entity.getPosYEye() + entity.world.rand.nextGaussian() * 0.25F, + entity.getPosZ() + entity.world.rand.nextGaussian() * 0.25F, + entity.world.rand.nextInt(2) + 1, 0, 0, 0, 0); + } + } + // we need to use the event since the item doesn't receive the interaction for tamed pets.. @SubscribeEvent public void onEntityInteract(PlayerInteractEvent.EntityInteractSpecific event) { Entity target = event.getTarget(); - if (!(target instanceof TameableEntity)) + if (!(target instanceof TameableEntity) || !((TameableEntity) target).isTamed()) return; if (target.getPersistentData().getBoolean(NaturesAura.MOD_ID + ":pet_reviver")) return; @@ -48,7 +70,8 @@ public class ItemPetReviver extends ItemImpl { if (stack.getItem() != ModItems.PET_REVIVER) return; target.getPersistentData().putBoolean(NaturesAura.MOD_ID + ":pet_reviver", true); - stack.shrink(1); + if (!target.world.isRemote) + stack.shrink(1); event.setCancellationResult(ActionResultType.SUCCESS); event.setCanceled(true); } @@ -71,7 +94,6 @@ public class ItemPetReviver extends ItemImpl { LivingEntity owner = tameable.getOwner(); if (owner instanceof ServerPlayerEntity) { ServerPlayerEntity player = (ServerPlayerEntity) owner; - // I'm not really sure what this means, but I got it from PlayerList.func_232644_a_ haha BlockPos pos = player.func_241140_K_(); if (pos != null) { diff --git a/src/main/resources/assets/naturesaura/textures/item/pet_reviver.png b/src/main/resources/assets/naturesaura/textures/item/pet_reviver.png new file mode 100644 index 0000000000000000000000000000000000000000..fc3565dfeeb8d603348c0d7e8854733f331149c3 GIT binary patch literal 315 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|zIwVihFJ6_ zCjh~VmpT9T=UhDVpU0&swL9(Kdmz7G(W6K4#j6OYJU48lD!MlH3 z|G$5ye#~U@Oo0xc?~~nsKL38~}o*cPcZ|QhHYu`Di2+-1}JE|Db8@XE}o{ z=c*eH9cO*Oc0^=-YR$J_>W8<_7g+d8g_Xy7-`^CcLOU;s0|zGEd+c508bZFpGCp^MC!9ylPgHd3hKZgp8-!_IPPJ0|S7;)78&q Iol`;+0OI