Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
Capability fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
MerchantPug committed Aug 16, 2024
1 parent ef3e895 commit cb19a38
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public interface IHitsOnTargetCapability {
void removeHits(int entityId);

void serverTick();
void setFrom(IHitsOnTargetCapability cap);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down

0 comments on commit cb19a38

Please sign in to comment.