From 5a88206bf53bfe69481c66b592211d9b3012a2a7 Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 5 May 2023 23:22:41 +0100 Subject: [PATCH] Adjust damage amount when removing the alicorn amulet --- .../unicopia/entity/ItemImpl.java | 7 +++ .../unicopia/item/AlicornAmuletItem.java | 51 +++++++++++++++++-- .../mixin/MixinAbstractDecorationEntity.java | 29 +++++++++++ src/main/resources/unicopia.mixin.json | 1 + 4 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/mixin/MixinAbstractDecorationEntity.java diff --git a/src/main/java/com/minelittlepony/unicopia/entity/ItemImpl.java b/src/main/java/com/minelittlepony/unicopia/entity/ItemImpl.java index f739053c..1777d7dc 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/ItemImpl.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/ItemImpl.java @@ -11,6 +11,7 @@ import net.minecraft.entity.*; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; +import net.minecraft.entity.decoration.ItemFrameEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.item.Item; @@ -129,10 +130,12 @@ public class ItemImpl implements Equine { return physics; } + @Override public Race getSpecies() { return Race.fromName(entity.getDataTracker().get(ITEM_RACE), Race.HUMAN); } + @Override public void setSpecies(Race race) { entity.getDataTracker().set(ITEM_RACE, Race.REGISTRY.getId(race).toString()); } @@ -207,5 +210,9 @@ public class ItemImpl implements Equine { default void interactWithPlayer(IItemEntity entity, PlayerEntity player) { } + + default void inFrameTick(ItemFrameEntity entity) { + + } } } diff --git a/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java b/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java index 0226fda4..97ee180f 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java @@ -10,8 +10,12 @@ import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.entity.*; import com.minelittlepony.unicopia.entity.effect.UEffects; import com.minelittlepony.unicopia.entity.player.*; +import com.minelittlepony.unicopia.particle.FollowingParticleEffect; +import com.minelittlepony.unicopia.particle.ParticleUtils; +import com.minelittlepony.unicopia.particle.UParticles; import com.minelittlepony.unicopia.trinkets.TrinketsDelegate; import com.minelittlepony.unicopia.util.MagicalDamageSource; +import com.minelittlepony.unicopia.util.VecHelper; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -24,16 +28,20 @@ import net.minecraft.entity.*; import net.minecraft.entity.Entity.RemovalReason; import net.minecraft.entity.attribute.*; import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.decoration.ItemFrameEntity; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleTypes; +import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.sound.SoundCategory; import net.minecraft.text.Text; import net.minecraft.util.*; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.random.Random; import net.minecraft.world.LocalDifficulty; import net.minecraft.world.World; @@ -126,12 +134,14 @@ public class AlicornAmuletItem extends AmuletItem implements ItemTracker.Trackab return; } - float attachedTime = timeWorn / 100F; + float attachedTime = timeWorn / ItemTracker.HOURS; LocalDifficulty difficulty = wearer.asWorld().getLocalDifficulty(wearer.getOrigin()); - float amount = attachedTime * (1 + difficulty.getClampedLocalDifficulty()); + float amount = Math.min(entity.getMaxHealth() - 1, (attachedTime / 4) * (1 + difficulty.getClampedLocalDifficulty())); - amount = Math.min(amount, entity.getMaxHealth()); + if (timeWorn > ItemTracker.DAYS) { + amount++; + } if (entity instanceof PlayerEntity player) { player.getHungerManager().setFoodLevel(1); @@ -142,7 +152,7 @@ public class AlicornAmuletItem extends AmuletItem implements ItemTracker.Trackab entity.addStatusEffect(new StatusEffectInstance(StatusEffects.WEAKNESS, 200, 3)); } - if (attachedTime > 120) { + if (attachedTime > ItemTracker.HOURS / 2) { entity.takeKnockback(1, 1, 1); wearer.updateVelocity(); } @@ -281,4 +291,37 @@ public class AlicornAmuletItem extends AmuletItem implements ItemTracker.Trackab return ActionResult.PASS; } + + @Override + public void inFrameTick(ItemFrameEntity entity) { + Random rng = entity.world.random; + + if (rng.nextInt(500) == 0) { + entity.world.playSound(null, entity.getBlockPos(), USounds.ITEM_ALICORN_AMULET_AMBIENT, SoundCategory.HOSTILE, 0.5F, 1); + for (int i = 0; i < 5; i++) { + entity.world.addParticle(rng.nextBoolean() ? ParticleTypes.LARGE_SMOKE : ParticleTypes.FLAME, + rng.nextTriangular(entity.getX(), 0.5), + rng.nextTriangular(entity.getY(), 0.5), + rng.nextTriangular(entity.getZ(), 0.5), + 0, 0, 0 + ); + } + } + + if ((entity.age / 1000) % 10 == 0 && entity.age % 50 == 0) { + for (Entity target : VecHelper.findInRange(entity, entity.world, entity.getPos(), 10, EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR)) { + for (ItemStack equipment : target.getItemsEquipped()) { + if (equipment.getItem() == UItems.GROGARS_BELL) { + ChargeableItem chargeable = (ChargeableItem)UItems.GROGARS_BELL; + if (chargeable.hasCharge(equipment)) { + ChargeableItem.consumeEnergy(equipment, 3); + ParticleUtils.spawnParticle(entity.world, + new FollowingParticleEffect(UParticles.HEALTH_DRAIN, entity, 0.4F) + .withChild(ParticleTypes.COMPOSTER), target.getEyePos(), Vec3d.ZERO); + } + } + } + } + } + } } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinAbstractDecorationEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinAbstractDecorationEntity.java new file mode 100644 index 00000000..855c049b --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinAbstractDecorationEntity.java @@ -0,0 +1,29 @@ +package com.minelittlepony.unicopia.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import com.minelittlepony.unicopia.entity.ItemImpl.ClingyItem; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.decoration.AbstractDecorationEntity; +import net.minecraft.entity.decoration.ItemFrameEntity; +import net.minecraft.item.ItemStack; + +@Mixin(AbstractDecorationEntity.class) +abstract class MixinAbstractDecorationEntity extends Entity { + MixinAbstractDecorationEntity() { super(null, null); } + + @Inject(method = "tick()V", at = @At("HEAD"), cancellable = true) + private void beforeTick(CallbackInfo info) { + final Object _this = this; + if (_this instanceof ItemFrameEntity self) { + ItemStack stack = self.getHeldItemStack(); + if (stack.getItem() instanceof ClingyItem item) { + item.inFrameTick(self); + } + } + } +} diff --git a/src/main/resources/unicopia.mixin.json b/src/main/resources/unicopia.mixin.json index fd4468a8..5a5a9ef9 100644 --- a/src/main/resources/unicopia.mixin.json +++ b/src/main/resources/unicopia.mixin.json @@ -5,6 +5,7 @@ "refmap": "unicopia.mixin.refmap.json", "compatibilityLevel": "JAVA_17", "mixins": [ + "MixinAbstractDecorationEntity", "MixinBlazeEntity", "MixinBlockEntity", "MixinBlockItem",