Invalidate capabilities that we attach to vanilla entities and TileEntities. Closes #5307

This commit is contained in:
LexManos committed 2019-02-06 22:55:17 -08:00
1 parent d930c8ae8b
commit 0b1b3c68fa
13 files changed
+139 -53

No files matched your search

@@ -20,8 +20,10 @@
package net.minecraftforge.event;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.minecraft.util.ResourceLocation;
@@ -40,6 +42,8 @@ public class AttachCapabilitiesEvent<T> extends GenericEvent<T>
private final T obj;
private final Map<ResourceLocation, ICapabilityProvider> caps = Maps.newLinkedHashMap();
private final Map<ResourceLocation, ICapabilityProvider> view = Collections.unmodifiableMap(caps);
private final List<Runnable> listeners = Lists.newArrayList();
private final List<Runnable> listenersView = Collections.unmodifiableList(listeners);
public AttachCapabilitiesEvent(Class<T> type, T obj)
{
@@ -77,4 +81,20 @@ public class AttachCapabilitiesEvent<T> extends GenericEvent<T>
{
return view;
}
/**
* Adds a callback that is fired when the attacked object is invalidated.
* Such as a Entity/TileEntity being removed from world.
* All attached providers should invalidate all of their held capability instances.
*/
public void addListener(Runnable listener)
{
this.listeners.add(listener);
}
public List<Runnable> getListeners()
{
return this.listenersView;
}
}