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

Commit 5602298

Browse files
authored
Fix energy capability not being registered and mark @CapabilityInject as deprecated (#186)
* Fix energy capability not being registered * Fix checkstyle + license * Mark `@CapabilityInject` as deprecated
1 parent 5ad67b2 commit 5602298

4 files changed

Lines changed: 45 additions & 2 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.lang.annotation.RetentionPolicy;
2525
import java.lang.annotation.Target;
2626

27+
import net.patchworkmc.api.capability.CapabilityRegisteredCallback;
28+
2729
/**
2830
* When placed on a field, the field will be set to an
2931
* instance of {@link Capability} once that capability is registered.
@@ -48,9 +50,12 @@
4850
*
4951
* <b>Warning</b>: Capability injections are run in the thread that the capability is registered.
5052
* Due to parallel mod loading, this can potentially be off of the main thread.
53+
*
54+
* @deprecated Don't use this in patchwork - use {@link CapabilityRegisteredCallback}.
5155
*/
5256
@Retention(RetentionPolicy.RUNTIME)
5357
@Target({ElementType.FIELD, ElementType.METHOD})
58+
@Deprecated
5459
public @interface CapabilityInject {
5560
/**
5661
* The capability interface to listen for registration.

patchwork-capabilities/src/main/java/net/minecraftforge/energy/CapabilityEnergy.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@
2121

2222
import net.minecraftforge.common.capabilities.Capability;
2323
import net.minecraftforge.common.capabilities.Capability.IStorage;
24-
import net.minecraftforge.common.capabilities.CapabilityInject;
2524
import net.minecraftforge.common.capabilities.CapabilityManager;
2625

2726
import net.minecraft.nbt.IntTag;
2827
import net.minecraft.nbt.Tag;
2928
import net.minecraft.util.math.Direction;
3029

30+
import net.patchworkmc.api.capability.CapabilityRegisteredCallback;
31+
3132
public class CapabilityEnergy {
32-
@CapabilityInject(IEnergyStorage.class)
3333
public static Capability<IEnergyStorage> ENERGY = null;
3434

3535
public static void register() {
36+
CapabilityRegisteredCallback.event(IEnergyStorage.class).register(cap -> ENERGY = cap);
37+
3638
CapabilityManager.INSTANCE.register(IEnergyStorage.class, new IStorage<IEnergyStorage>() {
3739
@Override
3840
public Tag writeNBT(Capability<IEnergyStorage> capability, IEnergyStorage instance, Direction side) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package net.patchworkmc.impl.capability;
21+
22+
import net.minecraftforge.energy.CapabilityEnergy;
23+
24+
import net.fabricmc.api.ModInitializer;
25+
26+
public class PatchworkCapabilities implements ModInitializer {
27+
@Override
28+
public void onInitialize() {
29+
CapabilityEnergy.register();
30+
}
31+
}

patchwork-capabilities/src/main/resources/fabric.mod.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
"mixins": [
1919
"patchwork-capabilities.mixins.json"
2020
],
21+
"entrypoints": {
22+
"main": [
23+
"net.patchworkmc.impl.capability.PatchworkCapabilities"
24+
]
25+
},
2126
"description": "Implementation of the Forge Capabilities API",
2227
"custom": {
2328
"modmenu:api": true,

0 commit comments

Comments
 (0)