mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 00:07:45 +00:00
[1.16.5] Backport OnDatapackSyncEvent from 1.17.1 (#7985)
This commit is contained in:
1 parent
c5725d1c61
commit
083624fb67
4 files changed
+86
-2
No files matched your search
@@ -16,8 +16,11 @@
|
||||
GameRules gamerules = serverworld1.func_82736_K();
|
||||
boolean flag = gamerules.func_223586_b(GameRules.field_226683_z_);
|
||||
boolean flag1 = gamerules.func_223586_b(GameRules.field_223612_o);
|
||||
@@ -156,6 +_,7 @@
|
||||
@@ -154,8 +_,10 @@
|
||||
serverplaynethandler.func_147359_a(new SServerDifficultyPacket(iworldinfo.func_176130_y(), iworldinfo.func_176123_z()));
|
||||
serverplaynethandler.func_147359_a(new SPlayerAbilitiesPacket(p_72355_2_.field_71075_bZ));
|
||||
serverplaynethandler.func_147359_a(new SHeldItemChangePacket(p_72355_2_.field_71071_by.field_70461_c));
|
||||
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.OnDatapackSyncEvent(this, p_72355_2_));
|
||||
serverplaynethandler.func_147359_a(new SUpdateRecipesPacket(this.field_72400_f.func_199529_aN().func_199510_b()));
|
||||
serverplaynethandler.func_147359_a(new STagsListPacket(this.field_72400_f.func_244266_aF()));
|
||||
+ net.minecraftforge.fml.network.NetworkHooks.syncCustomTagTypes(p_72355_2_, this.field_72400_f.func_244266_aF());
|
||||
@@ -137,9 +140,11 @@
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -804,6 +_,7 @@
|
||||
@@ -803,7 +_,9 @@
|
||||
playeradvancements.func_240918_a_(this.field_72400_f.func_191949_aK());
|
||||
}
|
||||
|
||||
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.OnDatapackSyncEvent(this, null));
|
||||
this.func_148540_a(new STagsListPacket(this.field_72400_f.func_244266_aF()));
|
||||
+ net.minecraftforge.fml.network.NetworkHooks.syncCustomTagTypes(this.field_72400_f.func_244266_aF());
|
||||
SUpdateRecipesPacket supdaterecipespacket = new SUpdateRecipesPacket(this.field_72400_f.func_199529_aN().func_199510_b());
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.server.management.PlayerList;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
/**
|
||||
* Fires when a player joins the server or when the reload command is ran,
|
||||
* before tags and crafting recipes are sent to the client. Send datapack data
|
||||
* to clients when this event fires.
|
||||
*/
|
||||
public class OnDatapackSyncEvent extends Event
|
||||
{
|
||||
private final PlayerList playerList;
|
||||
@Nullable
|
||||
private final ServerPlayerEntity player;
|
||||
|
||||
public OnDatapackSyncEvent(PlayerList playerList, @Nullable ServerPlayerEntity player)
|
||||
{
|
||||
this.playerList = playerList;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The server's player list to get a view of all players.
|
||||
*/
|
||||
public PlayerList getPlayerList()
|
||||
{
|
||||
return this.playerList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The player to sync datapacks to. Null when syncing for all players,
|
||||
* such as when the reload command runs.
|
||||
*/
|
||||
@Nullable
|
||||
public ServerPlayerEntity getPlayer()
|
||||
{
|
||||
return this.player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.minecraftforge.debug.misc;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraftforge.event.OnDatapackSyncEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod("send_datapacks_to_client")
|
||||
@Mod.EventBusSubscriber
|
||||
public class OnDatapackSynctEventTest
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
@SubscribeEvent
|
||||
protected static void onSendDataToClient(final OnDatapackSyncEvent event)
|
||||
{
|
||||
// Fire for a specific player on login
|
||||
if (event.getPlayer() != null)
|
||||
syncData(event.getPlayer());
|
||||
// Fire for all players on /reload
|
||||
else
|
||||
event.getPlayerList().getPlayers().forEach(OnDatapackSynctEventTest::syncData);
|
||||
}
|
||||
|
||||
private static void syncData(ServerPlayerEntity player)
|
||||
{
|
||||
LOGGER.info("Sending modded datapack data to {}", player.getName().getString());
|
||||
}
|
||||
}
|
||||
@@ -138,3 +138,7 @@ license="LGPL v2.1"
|
||||
modId="dimension_settings_test"
|
||||
[[mods]]
|
||||
modId="player_attack_knockback_test"
|
||||
[[mods]]
|
||||
modId="send_datapacks_to_client"
|
||||
|
||||
# ADD ABOVE THIS LINE
|
||||
Reference in new issue
Block a user