mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Improve TagsUpdatedEvent by adding update case information. (#8636)
This commit is contained in:
1 parent
e4837f65a3
commit
8d14797416
4 files changed
+69
-15
No files matched your search
@@ -99,9 +99,12 @@ public class ForgeInternalHandler
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public synchronized void tagsUpdated(TagsUpdatedEvent event)
|
||||
public void tagsUpdated(TagsUpdatedEvent event)
|
||||
{
|
||||
ForgeHooks.updateBurns();
|
||||
if (event.shouldUpdateStaticData())
|
||||
{
|
||||
ForgeHooks.updateBurns();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -6,22 +6,73 @@
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
|
||||
/**
|
||||
* Fired when tags are updated on either server or client. This event can be used to refresh data that depends on tags.
|
||||
*/
|
||||
public class TagsUpdatedEvent extends Event
|
||||
{
|
||||
private final RegistryAccess registries;
|
||||
private final UpdateCause updateCause;
|
||||
private final boolean integratedServer;
|
||||
|
||||
public TagsUpdatedEvent(RegistryAccess registries)
|
||||
{
|
||||
this.registries = registries;
|
||||
}
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
public TagsUpdatedEvent(RegistryAccess registries)
|
||||
{
|
||||
this.registries = registries;
|
||||
this.updateCause = ClientGamePacketListener.class.isAssignableFrom(StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass()) ? UpdateCause.CLIENT_PACKET_RECEIVED : UpdateCause.SERVER_DATA_LOAD;
|
||||
var currentServer = ServerLifecycleHooks.getCurrentServer();
|
||||
this.integratedServer = currentServer != null && !currentServer.isDedicatedServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The dynamic registries that have had their tags rebound.
|
||||
*/
|
||||
public RegistryAccess getTagManager()
|
||||
{
|
||||
return registries;
|
||||
}
|
||||
public TagsUpdatedEvent(RegistryAccess registries, boolean fromClientPacket, boolean isIntegratedServerConnection)
|
||||
{
|
||||
this.registries = registries;
|
||||
this.updateCause = fromClientPacket ? UpdateCause.CLIENT_PACKET_RECEIVED : UpdateCause.SERVER_DATA_LOAD;
|
||||
this.integratedServer = isIntegratedServerConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The dynamic registries that have had their tags rebound.
|
||||
*/
|
||||
public RegistryAccess getTagManager()
|
||||
{
|
||||
return registries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cause for this tag update
|
||||
*/
|
||||
public UpdateCause getUpdateCause()
|
||||
{
|
||||
return updateCause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether static data (which in single player is shared between server and client thread) should be updated as a
|
||||
* result of this event. Effectively this means that in single player only the server-side updates this data.
|
||||
*/
|
||||
public boolean shouldUpdateStaticData()
|
||||
{
|
||||
return updateCause == UpdateCause.SERVER_DATA_LOAD || !integratedServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the cause for a tag update.
|
||||
*/
|
||||
public enum UpdateCause
|
||||
{
|
||||
/**
|
||||
* The tag update is caused by the server loading datapack data. Note that in single player this still happens
|
||||
* on the client thread.
|
||||
*/
|
||||
SERVER_DATA_LOAD,
|
||||
/**
|
||||
* The tag update is caused by the client receiving the tag data from the server.
|
||||
*/
|
||||
CLIENT_PACKET_RECEIVED
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user