mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 03:49:14 +00:00
Remove generic from AttachCapabilitiesEvent to help prevent modders from having unchecked casts. Closes #10707
This commit is contained in:
4 files changed
+42
-17
No files matched your search
@@ -50,7 +50,7 @@ public abstract class CapabilityProvider<B extends ICapabilityProviderImpl<B>> i
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AttachCapabilitiesEvent<Entity> fireAttachCapabilitiesEvent(Entity provider) {
|
||||
protected AttachCapabilitiesEvent.Entities fireAttachCapabilitiesEvent(Entity provider) {
|
||||
return AttachCapabilitiesEvent.Entities.BUS.fire(new AttachCapabilitiesEvent.Entities(provider));
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public abstract class CapabilityProvider<B extends ICapabilityProviderImpl<B>> i
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AttachCapabilitiesEvent<BlockEntity> fireAttachCapabilitiesEvent(BlockEntity provider) {
|
||||
protected AttachCapabilitiesEvent.BlockEntities fireAttachCapabilitiesEvent(BlockEntity provider) {
|
||||
return AttachCapabilitiesEvent.BlockEntities.BUS.fire(new AttachCapabilitiesEvent.BlockEntities(provider));
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public abstract class CapabilityProvider<B extends ICapabilityProviderImpl<B>> i
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AttachCapabilitiesEvent<ItemStack> fireAttachCapabilitiesEvent(ItemStack provider) {
|
||||
protected AttachCapabilitiesEvent.ItemStacks fireAttachCapabilitiesEvent(ItemStack provider) {
|
||||
return AttachCapabilitiesEvent.ItemStacks.BUS.fire(new AttachCapabilitiesEvent.ItemStacks(provider));
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public abstract class CapabilityProvider<B extends ICapabilityProviderImpl<B>> i
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AttachCapabilitiesEvent<Level> fireAttachCapabilitiesEvent(Level provider) {
|
||||
protected AttachCapabilitiesEvent.Levels fireAttachCapabilitiesEvent(Level provider) {
|
||||
return AttachCapabilitiesEvent.Levels.BUS.fire(new AttachCapabilitiesEvent.Levels(provider));
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ public abstract class CapabilityProvider<B extends ICapabilityProviderImpl<B>> i
|
||||
doGatherCapabilities(parent == null ? null : parent.get());
|
||||
}
|
||||
|
||||
protected abstract AttachCapabilitiesEvent<?> fireAttachCapabilitiesEvent(B provider);
|
||||
protected abstract AttachCapabilitiesEvent fireAttachCapabilitiesEvent(B provider);
|
||||
protected abstract boolean shouldFireAttachCapabilitiesEvent();
|
||||
|
||||
private void doGatherCapabilities(@Nullable ICapabilityProvider parent) {
|
||||
@@ -282,7 +282,7 @@ public abstract class CapabilityProvider<B extends ICapabilityProviderImpl<B>> i
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AttachCapabilitiesEvent<LevelChunk> fireAttachCapabilitiesEvent(LevelChunk provider) {
|
||||
protected AttachCapabilitiesEvent.LevelChunks fireAttachCapabilitiesEvent(LevelChunk provider) {
|
||||
return AttachCapabilitiesEvent.LevelChunks.BUS.fire(new AttachCapabilitiesEvent.LevelChunks(provider));
|
||||
}
|
||||
|
||||
|
||||
@@ -37,61 +37,86 @@ import org.jspecify.annotations.NullMarked;
|
||||
* @see LevelChunks
|
||||
*/
|
||||
@NullMarked
|
||||
public abstract class AttachCapabilitiesEvent<T> extends MutableEvent implements InheritableEvent {
|
||||
private final T obj;
|
||||
public abstract class AttachCapabilitiesEvent extends MutableEvent implements InheritableEvent {
|
||||
private final Object obj;
|
||||
private final Map<ResourceLocation, ICapabilityProvider> caps = new LinkedHashMap<>();
|
||||
private final Map<ResourceLocation, ICapabilityProvider> view = Collections.unmodifiableMap(caps);
|
||||
private final List<Runnable> listeners = new ArrayList<>();
|
||||
private final List<Runnable> listenersView = Collections.unmodifiableList(listeners);
|
||||
|
||||
public static class Entities extends AttachCapabilitiesEvent<Entity> {
|
||||
public static class Entities extends AttachCapabilitiesEvent {
|
||||
public static final EventBus<Entities> BUS = EventBus.create(Entities.class);
|
||||
|
||||
public Entities(Entity obj) {
|
||||
super(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity getObject() {
|
||||
return (Entity)super.getObject();
|
||||
}
|
||||
}
|
||||
|
||||
public static class BlockEntities extends AttachCapabilitiesEvent<BlockEntity> {
|
||||
public static class BlockEntities extends AttachCapabilitiesEvent {
|
||||
public static final EventBus<BlockEntities> BUS = EventBus.create(BlockEntities.class);
|
||||
|
||||
public BlockEntities(BlockEntity obj) {
|
||||
super(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity getObject() {
|
||||
return (BlockEntity)super.getObject();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ItemStacks extends AttachCapabilitiesEvent<ItemStack> {
|
||||
public static class ItemStacks extends AttachCapabilitiesEvent {
|
||||
public static final EventBus<ItemStacks> BUS = EventBus.create(ItemStacks.class);
|
||||
|
||||
public ItemStacks(ItemStack obj) {
|
||||
super(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getObject() {
|
||||
return (ItemStack)super.getObject();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Levels extends AttachCapabilitiesEvent<Level> {
|
||||
public static class Levels extends AttachCapabilitiesEvent {
|
||||
public static final EventBus<Levels> BUS = EventBus.create(Levels.class);
|
||||
|
||||
public Levels(Level obj) {
|
||||
super(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Level getObject() {
|
||||
return (Level)super.getObject();
|
||||
}
|
||||
}
|
||||
|
||||
public static class LevelChunks extends AttachCapabilitiesEvent<LevelChunk> {
|
||||
public static class LevelChunks extends AttachCapabilitiesEvent {
|
||||
public static final EventBus<LevelChunks> BUS = EventBus.create(LevelChunks.class);
|
||||
|
||||
public LevelChunks(LevelChunk obj) {
|
||||
super(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LevelChunk getObject() {
|
||||
return (LevelChunk)super.getObject();
|
||||
}
|
||||
}
|
||||
|
||||
protected AttachCapabilitiesEvent(T obj) {
|
||||
protected AttachCapabilitiesEvent(Object obj) {
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the object that is being created, Not much state is set.
|
||||
*/
|
||||
public T getObject() {
|
||||
public Object getObject() {
|
||||
return this.obj;
|
||||
}
|
||||
|
||||
|
||||
@@ -571,7 +571,7 @@ public final class ForgeEventFactory {
|
||||
// }
|
||||
|
||||
@Nullable
|
||||
public static CapabilityDispatcher gatherCapabilities(AttachCapabilitiesEvent<?> event, @Nullable ICapabilityProvider parent) {
|
||||
public static CapabilityDispatcher gatherCapabilities(AttachCapabilitiesEvent event, @Nullable ICapabilityProvider parent) {
|
||||
return !event.getCapabilities().isEmpty() || parent != null ? new CapabilityDispatcher(event.getCapabilities(), event.getListeners(), parent) : null;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user