mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +00:00
Invalidate capabilities that we attach to vanilla entities and TileEntities. Closes #5307
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
@@ -569,7 +569,7 @@ public class ForgeEventFactory
|
||||
private static CapabilityDispatcher gatherCapabilities(AttachCapabilitiesEvent<?> event, @Nullable ICapabilityProvider parent)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getCapabilities().size() > 0 || parent != null ? new CapabilityDispatcher(event.getCapabilities(), parent) : null;
|
||||
return event.getCapabilities().size() > 0 || parent != null ? new CapabilityDispatcher(event.getCapabilities(), event.getListeners(), parent) : null;
|
||||
}
|
||||
|
||||
public static boolean fireSleepingLocationCheck(EntityPlayer player, BlockPos sleepingLocation)
|
||||
@@ -634,7 +634,7 @@ public class ForgeEventFactory
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new ProjectileImpactEvent.Throwable(throwable, ray));
|
||||
}
|
||||
|
||||
|
||||
public static boolean onReplaceBiomeBlocks(IChunkGenerator<?> gen, IChunk chunk, IWorld world)
|
||||
{
|
||||
ChunkGeneratorEvent.ReplaceBiomeBlocks event = new ChunkGeneratorEvent.ReplaceBiomeBlocks(gen, chunk, world);
|
||||
|
||||
Reference in new issue
Block a user