Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 68c5eb3

Browse files
committed
Fix a bug where the capabilities would be compared with itself
1 parent cdef921 commit 68c5eb3

5 files changed

Lines changed: 19 additions & 10 deletions

File tree

patchwork-capabilities/src/main/java/com/patchworkmc/impl/capability/BaseCapabilityProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public void gatherCapabilities(@Nullable ICapabilityProvider parent) {
4040
AttachCapabilitiesEvent<T> event = new AttachCapabilitiesEvent<>(baseClass, provider);
4141
MinecraftForge.EVENT_BUS.post(event);
4242

43-
capabilities = !event.getCapabilities().isEmpty() || parent != null ? new CapabilityDispatcher(event.getCapabilities(), event.getListeners(), parent) : null;
43+
if (!event.getCapabilities().isEmpty() || parent != null) {
44+
capabilities = new CapabilityDispatcher(event.getCapabilities(), event.getListeners(), parent);
45+
} else {
46+
capabilities = null;
47+
}
4448
}
4549
}

patchwork-capabilities/src/main/java/com/patchworkmc/mixin/capability/ItemEntityMixin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
public class ItemEntityMixin {
3434
@Inject(method = "merge", at = @At("HEAD"), cancellable = true)
3535
private static void merge(ItemEntity targetEntity, ItemStack targetStack, ItemEntity sourceEntity, ItemStack sourceStack, CallbackInfo callbackInfo) {
36-
CapabilityProviderHolder a = (CapabilityProviderHolder) (Object) targetStack;
37-
CapabilityProviderHolder b = (CapabilityProviderHolder) (Object) targetStack;
36+
CapabilityProviderHolder source = (CapabilityProviderHolder) (Object) sourceStack;
37+
CapabilityProviderHolder target = (CapabilityProviderHolder) (Object) targetStack;
3838

39-
if (!a.areCapsCompatible(b.getCapabilityProvider())) {
39+
if (!source.areCapsCompatible(target.getCapabilityProvider())) {
4040
callbackInfo.cancel();
4141
}
4242
}

patchwork-capabilities/src/main/java/net/minecraftforge/common/capabilities/CapabilityDispatcher.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ public CapabilityDispatcher(Map<Identifier, ICapabilityProvider> providers, List
7575
}
7676

7777
for (Map.Entry<Identifier, ICapabilityProvider> entry : providers.entrySet()) {
78-
ICapabilityProvider prov = entry.getValue();
79-
capabilities.add(prov);
78+
ICapabilityProvider provider = entry.getValue();
79+
capabilities.add(provider);
8080

81-
if (prov instanceof INBTSerializable) {
82-
writers.add((INBTSerializable<Tag>) prov);
81+
if (provider instanceof INBTSerializable) {
82+
writers.add((INBTSerializable<Tag>) provider);
8383
names.add(entry.getKey().toString());
8484
}
8585
}

patchwork-capabilities/src/main/java/net/minecraftforge/common/capabilities/CapabilityProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ public final void gatherCapabilities() {
4747
public void gatherCapabilities(@Nullable ICapabilityProvider parent) {
4848
AttachCapabilitiesEvent<B> event = new AttachCapabilitiesEvent<>(baseClass, (B) this);
4949
MinecraftForge.EVENT_BUS.post(event);
50-
capabilities = !event.getCapabilities().isEmpty() || parent != null ? new CapabilityDispatcher(event.getCapabilities(), event.getListeners(), parent) : null;
50+
51+
if (!event.getCapabilities().isEmpty() || parent != null) {
52+
capabilities = new CapabilityDispatcher(event.getCapabilities(), event.getListeners(), parent);
53+
} else {
54+
capabilities = null;
55+
}
5156
}
5257

5358
public final @Nullable CapabilityDispatcher getCapabilities() {

patchwork-capabilities/src/main/java/net/minecraftforge/event/AttachCapabilitiesEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public T getObject() {
6363
}
6464

6565
/**
66-
* Adds a {@link net.minecraftforge.common.capabilities.Capability} to be attached to this object.
66+
* Adds a {@link net.minecraftforge.common.capabilities.ICapabilityProvider capability provider} to be attached to this object.
6767
* Keys MUST be unique, it is suggested that you set the domain to your mod ID.
6868
* If the capability is an instance of {@link net.minecraftforge.common.util.INBTSerializable}, this key will be used when serializing this capability.
6969
*

0 commit comments

Comments
 (0)