mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
Add event for player changing game mode (#7355)
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
@@ -789,6 +789,17 @@ public class ForgeHooks
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.LeftClickEmpty(player));
|
||||
}
|
||||
|
||||
public static boolean onChangeGameMode(PlayerEntity player, GameType currentGameMode, GameType newGameMode)
|
||||
{
|
||||
if (currentGameMode != newGameMode)
|
||||
{
|
||||
PlayerEvent.PlayerChangeGameModeEvent evt = new PlayerEvent.PlayerChangeGameModeEvent(player, currentGameMode, newGameMode);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
return !evt.isCanceled();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static ThreadLocal<Deque<LootTableContext>> lootContext = new ThreadLocal<Deque<LootTableContext>>();
|
||||
private static LootTableContext getLootTableContext()
|
||||
{
|
||||
|
||||
@@ -25,6 +25,7 @@ import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.RegistryKey;
|
||||
import net.minecraft.world.GameType;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
@@ -510,4 +511,40 @@ public class PlayerEvent extends LivingEvent
|
||||
return this.toDim;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when the game type of a server player is changed to a different value than what it was previously. Eg Creative to Survival, not Survival to Survival.
|
||||
* If the event is cancelled the game mode of the player is not changed and the value of <code>newGameMode</code> is ignored.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class PlayerChangeGameModeEvent extends PlayerEvent
|
||||
{
|
||||
private final GameType currentGameMode;
|
||||
private GameType newGameMode;
|
||||
|
||||
public PlayerChangeGameModeEvent(PlayerEntity player, GameType currentGameMode, GameType newGameMode)
|
||||
{
|
||||
super(player);
|
||||
this.currentGameMode = currentGameMode;
|
||||
this.newGameMode = newGameMode;
|
||||
}
|
||||
|
||||
public GameType getCurrentGameMode()
|
||||
{
|
||||
return currentGameMode;
|
||||
}
|
||||
|
||||
public GameType getNewGameMode()
|
||||
{
|
||||
return newGameMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the game mode the player will be changed to if this event is not cancelled.
|
||||
*/
|
||||
public void setNewGameMode(GameType newGameMode)
|
||||
{
|
||||
this.newGameMode = newGameMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user