mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 19:58:34 +01:00
finished the token of undying friendship
This commit is contained in:
parent
68bc3c6af2
commit
1e880b6ef6
5 changed files with 80 additions and 3 deletions
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "minecraft:item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "naturesaura:item/pet_reviver"
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.entity.player.SpawnLocationHelper;
|
import net.minecraft.entity.player.SpawnLocationHelper;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.particles.ParticleTypes;
|
||||||
import net.minecraft.util.ActionResultType;
|
import net.minecraft.util.ActionResultType;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
@ -21,6 +22,7 @@ import net.minecraft.util.text.TranslationTextComponent;
|
||||||
import net.minecraft.world.server.ServerWorld;
|
import net.minecraft.world.server.ServerWorld;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||||
|
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||||
import net.minecraftforge.eventbus.api.EventPriority;
|
import net.minecraftforge.eventbus.api.EventPriority;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
@ -36,11 +38,31 @@ public class ItemPetReviver extends ItemImpl {
|
||||||
|
|
||||||
private static class Events {
|
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..
|
// we need to use the event since the item doesn't receive the interaction for tamed pets..
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onEntityInteract(PlayerInteractEvent.EntityInteractSpecific event) {
|
public void onEntityInteract(PlayerInteractEvent.EntityInteractSpecific event) {
|
||||||
Entity target = event.getTarget();
|
Entity target = event.getTarget();
|
||||||
if (!(target instanceof TameableEntity))
|
if (!(target instanceof TameableEntity) || !((TameableEntity) target).isTamed())
|
||||||
return;
|
return;
|
||||||
if (target.getPersistentData().getBoolean(NaturesAura.MOD_ID + ":pet_reviver"))
|
if (target.getPersistentData().getBoolean(NaturesAura.MOD_ID + ":pet_reviver"))
|
||||||
return;
|
return;
|
||||||
|
@ -48,6 +70,7 @@ public class ItemPetReviver extends ItemImpl {
|
||||||
if (stack.getItem() != ModItems.PET_REVIVER)
|
if (stack.getItem() != ModItems.PET_REVIVER)
|
||||||
return;
|
return;
|
||||||
target.getPersistentData().putBoolean(NaturesAura.MOD_ID + ":pet_reviver", true);
|
target.getPersistentData().putBoolean(NaturesAura.MOD_ID + ":pet_reviver", true);
|
||||||
|
if (!target.world.isRemote)
|
||||||
stack.shrink(1);
|
stack.shrink(1);
|
||||||
event.setCancellationResult(ActionResultType.SUCCESS);
|
event.setCancellationResult(ActionResultType.SUCCESS);
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
|
@ -71,7 +94,6 @@ public class ItemPetReviver extends ItemImpl {
|
||||||
LivingEntity owner = tameable.getOwner();
|
LivingEntity owner = tameable.getOwner();
|
||||||
if (owner instanceof ServerPlayerEntity) {
|
if (owner instanceof ServerPlayerEntity) {
|
||||||
ServerPlayerEntity player = (ServerPlayerEntity) owner;
|
ServerPlayerEntity player = (ServerPlayerEntity) owner;
|
||||||
|
|
||||||
// I'm not really sure what this means, but I got it from PlayerList.func_232644_a_ haha
|
// I'm not really sure what this means, but I got it from PlayerList.func_232644_a_ haha
|
||||||
BlockPos pos = player.func_241140_K_();
|
BlockPos pos = player.func_241140_K_();
|
||||||
if (pos != null) {
|
if (pos != null) {
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 315 B |
|
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
28
src/main/resources/data/naturesaura/recipes/pet_reviver.json
Normal file
28
src/main/resources/data/naturesaura/recipes/pet_reviver.json
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue