Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.event.AttachCapabilitiesEvent;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.Direction;

import net.patchworkmc.impl.capability.CapabilityEvents;

@ParametersAreNonnullByDefault
public abstract class CapabilityProvider<B> implements ICapabilityProvider {
protected final Class<B> baseClass;
Expand All @@ -45,14 +45,7 @@ public final void gatherCapabilities() {
}

public void gatherCapabilities(@Nullable ICapabilityProvider parent) {
AttachCapabilitiesEvent<B> event = new AttachCapabilitiesEvent<>(baseClass, (B) this);
MinecraftForge.EVENT_BUS.post(event);

if (!event.getCapabilities().isEmpty() || parent != null) {
capabilities = new CapabilityDispatcher(event.getCapabilities(), event.getListeners(), parent);
} else {
capabilities = null;
}
capabilities = CapabilityEvents.gatherCapabilities(baseClass, this, parent);
}

public final @Nullable CapabilityDispatcher getCapabilities() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@

import javax.annotation.Nullable;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.CapabilityDispatcher;
import net.minecraftforge.common.capabilities.CapabilityProvider;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.event.AttachCapabilitiesEvent;

public class BaseCapabilityProvider<T> extends CapabilityProvider<T> {
private final T provider;
Expand All @@ -37,13 +34,6 @@ public BaseCapabilityProvider(Class<T> baseClass, T provider) {

@Override
public void gatherCapabilities(@Nullable ICapabilityProvider parent) {
AttachCapabilitiesEvent<T> event = new AttachCapabilitiesEvent<>(baseClass, provider);
MinecraftForge.EVENT_BUS.post(event);

if (!event.getCapabilities().isEmpty() || parent != null) {
capabilities = new CapabilityDispatcher(event.getCapabilities(), event.getListeners(), parent);
} else {
capabilities = null;
}
capabilities = CapabilityEvents.gatherCapabilities(baseClass, provider, parent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Minecraft Forge, Patchwork Project
* Copyright (c) 2016-2020, 2019-2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.patchworkmc.impl.capability;

import javax.annotation.Nullable;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.CapabilityDispatcher;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.event.AttachCapabilitiesEvent;

public class CapabilityEvents {
// This is less restrictive than Forge's implementation, since patchwork can't make vanilla extend stuff at random.
@SuppressWarnings("unchecked")
@Nullable
public static <T> CapabilityDispatcher gatherCapabilities(Class<? extends T> type, T provider, @Nullable ICapabilityProvider parent) {
AttachCapabilitiesEvent<T> event = new AttachCapabilitiesEvent<T>((Class<T>) type, provider);
MinecraftForge.EVENT_BUS.post(event);

if (!event.getCapabilities().isEmpty() || parent != null) {
return new CapabilityDispatcher(event.getCapabilities(), event.getListeners(), parent);
} else {
return null;
}
}
}
1 change: 1 addition & 0 deletions patchwork-god-classes/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ version = getSubprojectVersion(project, "0.1.0")

dependencies {
compile project(path: ':patchwork-fml', configuration: 'dev')
compile project(path: ':patchwork-capabilities', configuration: 'dev')
compile project(path: ':patchwork-events-lifecycle', configuration: 'dev')
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,25 @@

package net.minecraftforge.event;

import javax.annotation.Nullable;

import net.minecraftforge.common.capabilities.CapabilityDispatcher;
import net.minecraftforge.common.capabilities.ICapabilityProvider;

import net.patchworkmc.impl.capability.CapabilityEvents;

/*
* Note: this class is intended for mod use only, to dispatch to the implementations kept in their own modules.
* Do not keep implementation details here, methods should be thin wrappers around methods in other modules.
*/
public class ForgeEventFactory {
@Nullable
public static <T> CapabilityDispatcher gatherCapabilities(Class<? extends T> type, T provider) {
return gatherCapabilities(type, provider, null);
}

@Nullable
public static <T> CapabilityDispatcher gatherCapabilities(Class<? extends T> type, T provider, @Nullable ICapabilityProvider parent) {
return CapabilityEvents.gatherCapabilities(type, provider, parent);
}
}
1 change: 1 addition & 0 deletions patchwork-god-classes/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"depends": {
"fabricloader": ">=0.8.4",
"patchwork-fml": "*",
"patchwork-capabilities": "*",
"patchwork-events-lifecycle": "*"
},
"custom": {
Expand Down