Add event for player changing game mode (#7355)

This commit is contained in:
Ocelot authored and GitHub committed 2020-10-15 10:15:06 -07:00
1 parent 5f292895cb
commit 51fa230e7b
8 files changed
+176 -7

No files matched your search

@@ -32,6 +32,7 @@ import net.minecraft.client.gui.ClientBossInfo;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.screen.MainMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.network.play.NetworkPlayerInfo;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.FogRenderer.FogType;
import net.minecraft.client.renderer.color.BlockColors;
@@ -72,6 +73,7 @@ import net.minecraft.util.math.vector.Vector3f;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.GameType;
import net.minecraft.world.IBlockDisplayReader;
import net.minecraftforge.client.event.*;
import net.minecraftforge.client.event.sound.PlaySoundEvent;
@@ -562,6 +564,15 @@ public class ForgeHooksClient
return event;
}
public static void onClientChangeGameMode(NetworkPlayerInfo info, GameType currentGameMode, GameType newGameMode)
{
if (currentGameMode != newGameMode)
{
ClientPlayerChangeGameModeEvent evt = new ClientPlayerChangeGameModeEvent(info, currentGameMode, newGameMode);
MinecraftForge.EVENT_BUS.post(evt);
}
}
@SuppressWarnings("deprecation")
public static IBakedModel handlePerspective(IBakedModel model, ItemCameraTransforms.TransformType type, MatrixStack stack)
{
@@ -0,0 +1,37 @@
package net.minecraftforge.client.event;
import net.minecraft.client.network.play.NetworkPlayerInfo;
import net.minecraft.world.GameType;
import net.minecraftforge.eventbus.api.Event;
/**
* Fired before the client player is notified of a change in game mode from the server.
*/
public class ClientPlayerChangeGameModeEvent extends Event
{
private final NetworkPlayerInfo info;
private final GameType currentGameMode;
private final GameType newGameMode;
public ClientPlayerChangeGameModeEvent(NetworkPlayerInfo info, GameType currentGameMode, GameType newGameMode)
{
this.info = info;
this.currentGameMode = currentGameMode;
this.newGameMode = newGameMode;
}
public NetworkPlayerInfo getInfo()
{
return info;
}
public GameType getCurrentGameMode()
{
return currentGameMode;
}
public GameType getNewGameMode()
{
return newGameMode;
}
}