From cb19a3883a1b0b9e068e24a43d41580fe99bd5ed Mon Sep 17 00:00:00 2001 From: Pug <81167232+MerchantPug@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:39:23 +1000 Subject: [PATCH] Capability fixes. --- CHANGELOG.md | 3 +++ .../apugli/ApugliForgeEventHandler.java | 8 ++++++++ .../capability/entity/HitsOnTargetCapability.java | 8 ++++++++ .../capability/entity/IHitsOnTargetCapability.java | 1 + .../capability/entity/IKeyPressCapability.java | 2 ++ .../capability/entity/KeyPressCapability.java | 14 ++++++++++++++ .../capability/item/IEntityLinkCapability.java | 4 ++++ 7 files changed, 40 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5992c427..06742361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ ## Bugfixes - Fixed `damage_nearby_x_hit` power type running attacker, target bientity conditions without an attacker. ([toomanyorigins#87](https://github.com/MerchantPug/toomanyorigins/issues/87)) - Backported fix for a crash relating to explosions. #62 +- [FORGE] Fixed `modify_breeding_cooldown` not functioning properly. #79 +- [FORGE] Fixed `key_pressed` entity condition not being persistent across dimensions. +- [FORGE] Fixed `hits_on_target` not updating. - Fixed the custom projectile power/action modifying the shooter's tag instead of the projectile's tag with the `tag` field. ## Miscellaneous diff --git a/Forge/src/main/java/net/merchantpug/apugli/ApugliForgeEventHandler.java b/Forge/src/main/java/net/merchantpug/apugli/ApugliForgeEventHandler.java index 212a0a33..8042f321 100644 --- a/Forge/src/main/java/net/merchantpug/apugli/ApugliForgeEventHandler.java +++ b/Forge/src/main/java/net/merchantpug/apugli/ApugliForgeEventHandler.java @@ -145,6 +145,8 @@ public static void modifyAerialBreakSpeed(PlayerEvent.BreakSpeed event) { @SubscribeEvent public static void onLivingTick(LivingEvent.LivingTickEvent event) { event.getEntity().getCapability(KeyPressCapability.INSTANCE).ifPresent(KeyPressCapability::tick); + if (!event.getEntity().level.isClientSide) + event.getEntity().getCapability(HitsOnTargetCapability.INSTANCE).ifPresent(HitsOnTargetCapability::serverTick); if (event.getEntity().isDeadOrDying()) return; @@ -294,6 +296,12 @@ public static void onMobInteract(PlayerInteractEvent.EntityInteractSpecific even } } + @SubscribeEvent + public static void onPlayerClone(PlayerEvent.Clone event) { + event.getEntity().getCapability(KeyPressCapability.INSTANCE).ifPresent(cap -> event.getOriginal().getCapability(KeyPressCapability.INSTANCE).ifPresent(cap::setFrom)); + event.getEntity().getCapability(HitsOnTargetCapability.INSTANCE).ifPresent(cap -> event.getOriginal().getCapability(HitsOnTargetCapability.INSTANCE).ifPresent(cap::setFrom)); + } + @SubscribeEvent public static void prePowerLoad(AddReloadListenerEvent event) { TextureUtil.getCache().clear(); diff --git a/Forge/src/main/java/net/merchantpug/apugli/capability/entity/HitsOnTargetCapability.java b/Forge/src/main/java/net/merchantpug/apugli/capability/entity/HitsOnTargetCapability.java index 0ac8f345..5848e9af 100644 --- a/Forge/src/main/java/net/merchantpug/apugli/capability/entity/HitsOnTargetCapability.java +++ b/Forge/src/main/java/net/merchantpug/apugli/capability/entity/HitsOnTargetCapability.java @@ -73,6 +73,14 @@ public void serverTick() { previousHits = hits; } + @Override + public void setFrom(IHitsOnTargetCapability cap) { + previousHits.clear(); + previousHits.putAll(cap.getPreviousHits()); + hits.clear(); + hits.putAll(cap.getHits()); + } + public void sync() { if (provider.level.isClientSide) return; ApugliPacketHandler.INSTANCE.send(PacketDistributor.TRACKING_ENTITY_AND_SELF.with(() -> provider), new SyncHitsOnTargetCapabilityPacket(provider.getId(), hits)); diff --git a/Forge/src/main/java/net/merchantpug/apugli/capability/entity/IHitsOnTargetCapability.java b/Forge/src/main/java/net/merchantpug/apugli/capability/entity/IHitsOnTargetCapability.java index d78c6454..15ef5858 100644 --- a/Forge/src/main/java/net/merchantpug/apugli/capability/entity/IHitsOnTargetCapability.java +++ b/Forge/src/main/java/net/merchantpug/apugli/capability/entity/IHitsOnTargetCapability.java @@ -16,4 +16,5 @@ public interface IHitsOnTargetCapability { void removeHits(int entityId); void serverTick(); + void setFrom(IHitsOnTargetCapability cap); } diff --git a/Forge/src/main/java/net/merchantpug/apugli/capability/entity/IKeyPressCapability.java b/Forge/src/main/java/net/merchantpug/apugli/capability/entity/IKeyPressCapability.java index c861bd5a..68c280f5 100644 --- a/Forge/src/main/java/net/merchantpug/apugli/capability/entity/IKeyPressCapability.java +++ b/Forge/src/main/java/net/merchantpug/apugli/capability/entity/IKeyPressCapability.java @@ -19,4 +19,6 @@ public interface IKeyPressCapability { void addKey(IActivePower.Key key); void addPreviousKey(IActivePower.Key key); void removeKey(IActivePower.Key key); + + void setFrom(IKeyPressCapability cap); } \ No newline at end of file diff --git a/Forge/src/main/java/net/merchantpug/apugli/capability/entity/KeyPressCapability.java b/Forge/src/main/java/net/merchantpug/apugli/capability/entity/KeyPressCapability.java index f05d625b..b8ec857d 100644 --- a/Forge/src/main/java/net/merchantpug/apugli/capability/entity/KeyPressCapability.java +++ b/Forge/src/main/java/net/merchantpug/apugli/capability/entity/KeyPressCapability.java @@ -86,6 +86,20 @@ public void tick() { this.previousPowerSize = powerSize; } + @Override + public void setFrom(IKeyPressCapability cap) { + if (!(cap instanceof KeyPressCapability classCap)) + return; + previousPowerSize = classCap.previousPowerSize; + + keysToCheck.clear(); + keysToCheck.addAll(classCap.keysToCheck); + previouslyUsedKeys.clear(); + previouslyUsedKeys.addAll(classCap.previouslyUsedKeys); + currentlyUsedKeys.clear(); + currentlyUsedKeys.addAll(classCap.currentlyUsedKeys); + } + public void sync() { if (provider.level.isClientSide) return; ApugliPacketHandler.INSTANCE.send(PacketDistributor.TRACKING_ENTITY.with(() -> provider), new SyncKeyPressCapabilityPacket(provider.getId(), previouslyUsedKeys, currentlyUsedKeys)); diff --git a/Forge/src/main/java/net/merchantpug/apugli/capability/item/IEntityLinkCapability.java b/Forge/src/main/java/net/merchantpug/apugli/capability/item/IEntityLinkCapability.java index 2c467423..28c5ac50 100644 --- a/Forge/src/main/java/net/merchantpug/apugli/capability/item/IEntityLinkCapability.java +++ b/Forge/src/main/java/net/merchantpug/apugli/capability/item/IEntityLinkCapability.java @@ -6,6 +6,10 @@ import javax.annotation.Nullable; +/** + * Use {@link net.merchantpug.apugli.access.ItemStackAccess} instead. + */ +@Deprecated public interface IEntityLinkCapability { ResourceLocation ID = Apugli.asResource("entity_link");