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 00000000..fc3565df Binary files /dev/null and b/src/main/resources/assets/naturesaura/textures/item/pet_reviver.png differ diff --git a/src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/items/pet_reviver.json b/src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/items/pet_reviver.json new file mode 100644 index 00000000..0833af8c --- /dev/null +++ b/src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/items/pet_reviver.json @@ -0,0 +1,21 @@ +{ + "name": "Token of Undying Friendship", + "icon": "naturesaura:pet_reviver", + "category": "items", + "advancement": "naturesaura:sky_ingot", + "pages": [ + { + "type": "text", + "text": "Owning $(thing)pets$() is quite the emotional endeavour, since the chance of them succumbing to monsters or hot lava is alarmingly high. Magical botanists have had to deal with this problem for a long time, until they found out about the powers of the $(item)Token of Undying Friendship$(). Upon being applied to any $(thing)tamed animal$(), the animal will never be able to die anymore." + }, + { + "type": "text", + "text": "Instead, when it reaches dangerously low health, it will be $(thing)sent home$() to the owner's usual revival location. During this process, a rather large amount of $(aura) is drained from the area around this home location.$(br)The animal additionally expresses its happiness over being given this special token by occasionally showing you their heart." + }, + { + "type": "crafting", + "text": "Creating the $(item)Token of Undying Friendship$()", + "recipe": "naturesaura:pet_reviver" + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/naturesaura/recipes/pet_reviver.json b/src/main/resources/data/naturesaura/recipes/pet_reviver.json new file mode 100644 index 00000000..6d58fd22 --- /dev/null +++ b/src/main/resources/data/naturesaura/recipes/pet_reviver.json @@ -0,0 +1,28 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "TGJ", + "SBS", + " G " + ], + "key": { + "G": { + "item": "minecraft:gold_ingot" + }, + "B": { + "item": "minecraft:bone" + }, + "T": { + "item": "naturesaura:token_grief" + }, + "J": { + "item": "naturesaura:token_joy" + }, + "S": { + "item": "naturesaura:sky_ingot" + } + }, + "result": { + "item": "naturesaura:pet_reviver" + } +} \ No newline at end of file