mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Start firing AttachCapabilitiesEvent<ItemStack> (#3645)
This commit is contained in:
1 parent
5cce054548
commit
bf154730bd
3 files changed
+40
-11
No files matched your search
@@ -40,8 +40,8 @@ import javax.annotation.Nonnull;
|
||||
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);
|
||||
final Map<ResourceLocation, ICapabilityProvider> caps;// package-private for ForgeEventFactory
|
||||
private final Map<ResourceLocation, ICapabilityProvider> view;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Deprecated
|
||||
@@ -50,9 +50,16 @@ public class AttachCapabilitiesEvent<T> extends GenericEvent<T>
|
||||
this((Class<T>)Object.class, obj);
|
||||
}
|
||||
public AttachCapabilitiesEvent(Class<T> type, T obj)
|
||||
{
|
||||
this(type, obj, Maps.<ResourceLocation, ICapabilityProvider>newLinkedHashMap());
|
||||
}
|
||||
// package-private for ForgeEventFactory
|
||||
AttachCapabilitiesEvent(Class<T> type, T obj, Map<ResourceLocation, ICapabilityProvider> caps)
|
||||
{
|
||||
super(type);
|
||||
this.obj = obj;
|
||||
this.caps = caps;
|
||||
this.view = Collections.unmodifiableMap(caps);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,10 +133,10 @@ public class AttachCapabilitiesEvent<T> extends GenericEvent<T>
|
||||
/**
|
||||
* A version of the parent event which is only fired for ItemStacks.
|
||||
*/
|
||||
@Deprecated
|
||||
public static class Item extends AttachCapabilitiesEvent<net.minecraft.item.Item>
|
||||
{
|
||||
private final net.minecraft.item.ItemStack stack;
|
||||
@Deprecated
|
||||
private final net.minecraft.item.Item item;
|
||||
public Item(net.minecraft.item.Item item, @Nonnull net.minecraft.item.ItemStack stack)
|
||||
{
|
||||
@@ -137,7 +144,6 @@ public class AttachCapabilitiesEvent<T> extends GenericEvent<T>
|
||||
this.item = item;
|
||||
this.stack = stack;
|
||||
}
|
||||
@Deprecated
|
||||
public net.minecraft.item.Item getItem()
|
||||
{
|
||||
return this.item;
|
||||
|
||||
@@ -561,7 +561,13 @@ public class ForgeEventFactory
|
||||
@Nullable
|
||||
public static CapabilityDispatcher gatherCapabilities(Item item, ItemStack stack, ICapabilityProvider parent)
|
||||
{
|
||||
return gatherCapabilities(new AttachCapabilitiesEvent.Item(item, stack), parent);
|
||||
// first fire the legacy event
|
||||
AttachCapabilitiesEvent.Item legacyEvent = new AttachCapabilitiesEvent.Item(item, stack);
|
||||
MinecraftForge.EVENT_BUS.post(legacyEvent);
|
||||
|
||||
// fire new event with the caps that were already registered on the legacy event
|
||||
AttachCapabilitiesEvent<ItemStack> event = new AttachCapabilitiesEvent<ItemStack>(ItemStack.class, stack, legacyEvent.caps);
|
||||
return gatherCapabilities(event, parent);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in new issue
Block a user