From 4d8174cf953aebbd905b99323db213af04927e00 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Sat, 18 Jul 2020 18:57:24 -0500 Subject: [PATCH] Reimplement pixie spawning --- .../java/vazkii/botania/common/Botania.java | 1 - .../common/block/tile/TileSpawnerClaw.java | 1 - .../common/core/handler/PixieHandler.java | 16 +--------------- .../vazkii/botania/mixin/MixinPlayerEntity.java | 17 +++++++++++++++++ .../assets/botania/botania.mixins.json | 3 ++- 5 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 src/main/java/vazkii/botania/mixin/MixinPlayerEntity.java diff --git a/src/main/java/vazkii/botania/common/Botania.java b/src/main/java/vazkii/botania/common/Botania.java index 6a4032b06..68fafa975 100644 --- a/src/main/java/vazkii/botania/common/Botania.java +++ b/src/main/java/vazkii/botania/common/Botania.java @@ -174,7 +174,6 @@ public class Botania { forgeBus.addListener(ItemVirus::onLivingHurt); forgeBus.addListener(SleepingHandler::trySleep); forgeBus.addListener(PixieHandler::onDamageTaken); - forgeBus.addGenericListener(Entity.class, PixieHandler::attachAttribute); forgeBus.addGenericListener(TileEntity.class, ExoflameFurnaceHandler::attachFurnaceCapability); forgeBus.addListener(CommonTickHandler::onTick); forgeBus.addListener(PotionBloodthirst::onSpawn); diff --git a/src/main/java/vazkii/botania/common/block/tile/TileSpawnerClaw.java b/src/main/java/vazkii/botania/common/block/tile/TileSpawnerClaw.java index 2e3ecfbd1..a991fab3a 100644 --- a/src/main/java/vazkii/botania/common/block/tile/TileSpawnerClaw.java +++ b/src/main/java/vazkii/botania/common/block/tile/TileSpawnerClaw.java @@ -43,7 +43,6 @@ public class TileSpawnerClaw extends TileMod implements IManaReceiver, ITickable AccessorAbstractSpawner mLogic = (AccessorAbstractSpawner) logic; // [VanillaCopy] AbstractSpawner.tick, edits noted - // todo 1.16 investigate instead mixing into AbstractSpawner instead of duplicating logic here if (!mLogic.callIsActivated()) { // Activate when vanilla is *not* running the spawner mLogic.setPrevMobRotation(mLogic.getMobRotation()); } else { diff --git a/src/main/java/vazkii/botania/common/core/handler/PixieHandler.java b/src/main/java/vazkii/botania/common/core/handler/PixieHandler.java index 5e1b492b7..e6e721e64 100644 --- a/src/main/java/vazkii/botania/common/core/handler/PixieHandler.java +++ b/src/main/java/vazkii/botania/common/core/handler/PixieHandler.java @@ -68,23 +68,10 @@ public final class PixieHandler { return new AttributeModifier(DEFAULT_MODIFIER_UUIDS.get(slot), name, amount, AttributeModifier.Operation.ADDITION); } - // Want to do this as early as possible -- doing it at entity join world means attribute modifiers are ignored when loading - public static void attachAttribute(AttachCapabilitiesEvent evt) { - if (evt.getObject() instanceof PlayerEntity) { - /* todo 1.16 impossible rn? - AbstractAttributeMap attributes = ((PlayerEntity) evt.getObject()).getAttributes(); - if (attributes.getAttributeInstance(PIXIE_SPAWN_CHANCE) == null) { - attributes.registerAttribute(PIXIE_SPAWN_CHANCE); - } - */ - } - } - public static void onDamageTaken(LivingHurtEvent event) { if (!event.getEntityLiving().world.isRemote && event.getEntityLiving() instanceof PlayerEntity && event.getSource().getTrueSource() instanceof LivingEntity) { PlayerEntity player = (PlayerEntity) event.getEntityLiving(); - /* todo unimpl - double chance = player.getAttribute(PIXIE_SPAWN_CHANCE).getValue(); + double chance = player.func_233637_b_(PIXIE_SPAWN_CHANCE); ItemStack sword = PlayerHelper.getFirstHeldItem(player, s -> s.getItem() == ModItems.elementiumSword); if (Math.random() < chance) { @@ -105,7 +92,6 @@ public final class PixieHandler { SpawnReason.EVENT, null, null); player.world.addEntity(pixie); } - */ } } } diff --git a/src/main/java/vazkii/botania/mixin/MixinPlayerEntity.java b/src/main/java/vazkii/botania/mixin/MixinPlayerEntity.java new file mode 100644 index 000000000..f24d65f91 --- /dev/null +++ b/src/main/java/vazkii/botania/mixin/MixinPlayerEntity.java @@ -0,0 +1,17 @@ +package vazkii.botania.mixin; + +import net.minecraft.entity.ai.attributes.AttributeModifierMap; +import net.minecraft.entity.player.PlayerEntity; +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.CallbackInfoReturnable; +import vazkii.botania.common.core.handler.PixieHandler; + +@Mixin(PlayerEntity.class) +public class MixinPlayerEntity { + @Inject(at = @At("RETURN"), method = "func_234570_el_") + private static void addPixieAttribute(CallbackInfoReturnable cir) { + cir.getReturnValue().func_233814_a_(PixieHandler.PIXIE_SPAWN_CHANCE); + } +} diff --git a/src/main/resources/assets/botania/botania.mixins.json b/src/main/resources/assets/botania/botania.mixins.json index 3c2ff4997..04db4e568 100644 --- a/src/main/resources/assets/botania/botania.mixins.json +++ b/src/main/resources/assets/botania/botania.mixins.json @@ -18,7 +18,8 @@ "AccessorMobEntity", "AccessorNearestAttackableTarget", "AccessorRecipeManager", - "AccessorWitherEntity" + "AccessorWitherEntity", + "MixinPlayerEntity" ], "client": [ "AccessorBiomeGeneratorTypeScreens",