Skip to content

Commit 61bb434

Browse files
committed
Minecraft.getMinecraft() -> Platform.getClientPlayer()
1 parent 85f9ee3 commit 61bb434

File tree

13 files changed

+49
-40
lines changed

13 files changed

+49
-40
lines changed

src/main/java/com/cleanroommc/modularui/ClientProxy.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.cleanroommc.modularui.test.TestItem;
1515
import com.cleanroommc.modularui.theme.ThemeManager;
1616
import com.cleanroommc.modularui.theme.ThemeReloadCommand;
17+
import com.cleanroommc.modularui.utils.Platform;
1718

1819
import net.minecraft.client.Minecraft;
1920
import net.minecraft.client.resources.IReloadableResourceManager;
@@ -58,12 +59,12 @@ public class ClientProxy extends CommonProxy {
5859
void preInit(FMLPreInitializationEvent event) {
5960
super.preInit(event);
6061

61-
MinecraftForge.EVENT_BUS.register(ClientScreenHandler.class);
62+
MinecraftForge.EVENT_BUS.register(new ClientScreenHandler());
6263
MinecraftForge.EVENT_BUS.register(KeyBindHandler.class);
6364
AnimatorManager.init();
6465

6566
if (ModularUIConfig.enableTestGuis) {
66-
MinecraftForge.EVENT_BUS.register(EventHandler.class);
67+
MinecraftForge.EVENT_BUS.register(new EventHandler());
6768
testKey = new KeyBinding("key.test", KeyConflictContext.IN_GAME, Keyboard.KEY_NUMPAD4, "key.categories.modularui");
6869
ClientRegistry.registerKeyBinding(testKey);
6970
}
@@ -168,7 +169,7 @@ void postInit(FMLPostInitializationEvent event) {
168169
@SubscribeEvent
169170
public void onKeyboard(InputEvent.KeyInputEvent event) {
170171
if (ModularUIConfig.enableTestGuis && testKey != null && testKey.isPressed() && ModularUI.Mods.BAUBLES.isLoaded()) {
171-
InventoryTypes.BAUBLES.visitAll(Minecraft.getMinecraft().player, (type, index, stack) -> {
172+
InventoryTypes.BAUBLES.visitAll(Platform.getClientPlayer(), (type, index, stack) -> {
172173
if (stack.getItem() instanceof TestItem) {
173174
GuiFactories.playerInventory().openFromBaublesClient(index);
174175
return true;

src/main/java/com/cleanroommc/modularui/api/MCHelper.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import net.minecraft.item.ItemStack;
99
import net.minecraft.util.text.TextFormatting;
1010

11+
import org.jetbrains.annotations.Nullable;
12+
1113
import java.util.Collections;
1214
import java.util.List;
1315

@@ -17,11 +19,11 @@ public static boolean hasMc() {
1719
return getMc() != null;
1820
}
1921

20-
public static Minecraft getMc() {
22+
public static @Nullable Minecraft getMc() {
2123
return Minecraft.getMinecraft();
2224
}
2325

24-
public static EntityPlayerSP getPlayer() {
26+
public static @Nullable EntityPlayerSP getPlayer() {
2527
if (hasMc()) {
2628
return getMc().player;
2729
}
@@ -30,7 +32,7 @@ public static EntityPlayerSP getPlayer() {
3032

3133
public static boolean closeScreen() {
3234
if (!hasMc()) return false;
33-
EntityPlayerSP player = Minecraft.getMinecraft().player;
35+
EntityPlayerSP player = getPlayer();
3436
if (player != null) {
3537
player.closeScreen();
3638
return true;

src/main/java/com/cleanroommc/modularui/core/mixins/early/minecraft/InventoryCraftingAccessor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import net.minecraft.inventory.Container;
44
import net.minecraft.inventory.InventoryCrafting;
5-
65
import net.minecraft.item.ItemStack;
76
import net.minecraft.util.NonNullList;
87

src/main/java/com/cleanroommc/modularui/drawable/GuiDraw.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public static void drawItem(ItemStack item, int x, int y, float width, float hei
294294
GlStateManager.scale(width / 16f, height / 16f, 1);
295295
RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
296296
renderItem.zLevel = z + 100;
297-
renderItem.renderItemAndEffectIntoGUI(Minecraft.getMinecraft().player, item, 0, 0);
297+
renderItem.renderItemAndEffectIntoGUI(Platform.getClientPlayer(), item, 0, 0);
298298
renderItem.zLevel = 0;
299299
Platform.endDrawItem();
300300
GlStateManager.popMatrix();
@@ -569,10 +569,10 @@ public static void drawTooltipBackground(ItemStack stack, List<String> lines, in
569569

570570
/**
571571
* Draws an entity. Note that this does NOT do any necessary setup for rendering the entity. Please see
572-
* {@link #drawEntity(Entity, float, float, float, float, Consumer, Consumer)} for a full draw method.
572+
* {@link #drawEntity(Entity, float, float, float, float, float, Consumer, Consumer)} for a full draw method.
573573
*
574574
* @param entity entity to draw.
575-
* @see #drawEntity(Entity, float, float, float, float, Consumer, Consumer)
575+
* @see #drawEntity(Entity, float, float, float, float, float, Consumer, Consumer)
576576
*/
577577
public static void drawEntityRaw(Entity entity) {
578578
RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager();
@@ -616,9 +616,9 @@ public static <T extends Entity> void drawEntity(T entity, float x, float y, flo
616616
* @param entity entity to draw
617617
* @param x x pos
618618
* @param y y pos
619-
* @param w the width of the area where the entity should be drawn
620-
* @param h the height of the area where the entity should be drawn
621-
* @param z the z layer ({@link GuiContext#getCurrentDrawingZ()} if drawn in a MUI)
619+
* @param w the width of the area where the entity should be drawn
620+
* @param h the height of the area where the entity should be drawn
621+
* @param z the z layer ({@link GuiContext#getCurrentDrawingZ()} if drawn in a MUI)
622622
* @param mouseX current x pos of the mouse
623623
* @param mouseY current y pos of the mouse
624624
*/

src/main/java/com/cleanroommc/modularui/factory/SimpleGuiFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.cleanroommc.modularui.factory;
22

33
import com.cleanroommc.modularui.api.IGuiHolder;
4-
import com.cleanroommc.modularui.api.MCHelper;
4+
import com.cleanroommc.modularui.utils.Platform;
55

66
import net.minecraft.entity.player.EntityPlayer;
77
import net.minecraft.entity.player.EntityPlayerMP;
@@ -55,7 +55,7 @@ public void open(EntityPlayerMP player) {
5555

5656
@SideOnly(Side.CLIENT)
5757
public void openClient() {
58-
GuiManager.openFromClient(this, new GuiData(MCHelper.getPlayer()));
58+
GuiManager.openFromClient(this, new GuiData(Platform.getClientPlayer()));
5959
}
6060

6161
@Override

src/main/java/com/cleanroommc/modularui/factory/TileEntityGuiFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.cleanroommc.modularui.factory;
22

33
import com.cleanroommc.modularui.api.IGuiHolder;
4-
import com.cleanroommc.modularui.api.MCHelper;
54
import com.cleanroommc.modularui.utils.Platform;
65

76
import net.minecraft.entity.player.EntityPlayer;
@@ -43,13 +42,13 @@ public void open(EntityPlayer player, BlockPos pos) {
4342
public <T extends TileEntity & IGuiHolder<PosGuiData>> void openClient(T tile) {
4443
verifyTile(Platform.getClientPlayer(), tile);
4544
BlockPos pos = tile.getPos();
46-
GuiManager.openFromClient(this, new PosGuiData(MCHelper.getPlayer(), pos.getX(), pos.getY(), pos.getZ()));
45+
GuiManager.openFromClient(this, new PosGuiData(Platform.getClientPlayer(), pos.getX(), pos.getY(), pos.getZ()));
4746
}
4847

4948
@SideOnly(Side.CLIENT)
5049
public void openClient(BlockPos pos) {
5150
Objects.requireNonNull(pos);
52-
GuiManager.openFromClient(this, new PosGuiData(MCHelper.getPlayer(), pos.getX(), pos.getY(), pos.getZ()));
51+
GuiManager.openFromClient(this, new PosGuiData(Platform.getClientPlayer(), pos.getX(), pos.getY(), pos.getZ()));
5352
}
5453

5554
@Override

src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.cleanroommc.modularui.holoui;
22

33
import com.cleanroommc.modularui.screen.GuiContainerWrapper;
4+
import com.cleanroommc.modularui.utils.Platform;
45

5-
import net.minecraft.client.Minecraft;
66
import net.minecraft.client.renderer.GlStateManager;
77
import net.minecraft.client.renderer.entity.Render;
88
import net.minecraft.client.renderer.entity.RenderManager;
@@ -36,7 +36,7 @@ public void doRender(@NotNull HoloScreenEntity entity, double x, double y, doubl
3636

3737
Plane3D plane3D = entity.getPlane3D();
3838
if (entity.getOrientation() == ScreenOrientation.TO_PLAYER) {
39-
EntityPlayer player = Minecraft.getMinecraft().player;
39+
EntityPlayer player = Platform.getClientPlayer();
4040
float xN = (float) (player.posX - entity.posX);
4141
float yN = (float) (player.posY - entity.posY);
4242
float zN = (float) (player.posZ - entity.posZ);

src/main/java/com/cleanroommc/modularui/network/packets/OpenGuiPacket.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import com.cleanroommc.modularui.factory.GuiManager;
66
import com.cleanroommc.modularui.network.IPacket;
77
import com.cleanroommc.modularui.network.NetworkUtils;
8+
import com.cleanroommc.modularui.utils.Platform;
89

9-
import net.minecraft.client.Minecraft;
1010
import net.minecraft.client.network.NetHandlerPlayClient;
1111
import net.minecraft.network.NetHandlerPlayServer;
1212
import net.minecraft.network.PacketBuffer;
@@ -48,7 +48,7 @@ public void read(PacketBuffer buf) {
4848
@SideOnly(Side.CLIENT)
4949
@Override
5050
public @Nullable IPacket executeClient(NetHandlerPlayClient handler) {
51-
GuiManager.openFromClient(this.windowId, this.factory, this.data, Minecraft.getMinecraft().player);
51+
GuiManager.openFromClient(this.windowId, this.factory, this.data, Platform.getClientPlayer());
5252
return null;
5353
}
5454

src/main/java/com/cleanroommc/modularui/screen/ModularContainer.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.cleanroommc.bogosorter.api.ISortableContainer;
1414
import com.cleanroommc.bogosorter.api.ISortingContextBuilder;
1515

16-
import net.minecraft.client.Minecraft;
1716
import net.minecraft.entity.player.EntityPlayer;
1817
import net.minecraft.entity.player.InventoryPlayer;
1918
import net.minecraft.inventory.ClickType;
@@ -25,9 +24,17 @@
2524
import net.minecraftforge.fml.relauncher.SideOnly;
2625
import net.minecraftforge.items.ItemHandlerHelper;
2726

28-
import org.jetbrains.annotations.*;
27+
import org.jetbrains.annotations.ApiStatus;
28+
import org.jetbrains.annotations.Contract;
29+
import org.jetbrains.annotations.MustBeInvokedByOverriders;
30+
import org.jetbrains.annotations.NotNull;
31+
import org.jetbrains.annotations.Nullable;
2932

30-
import java.util.*;
33+
import java.util.ArrayList;
34+
import java.util.Collections;
35+
import java.util.Comparator;
36+
import java.util.List;
37+
import java.util.Objects;
3138

3239
@Interface(modid = ModularUI.ModIds.BOGOSORTER, iface = "com.cleanroommc.bogosorter.api.ISortableContainer")
3340
public class ModularContainer extends Container implements ISortableContainer {
@@ -75,7 +82,7 @@ void initializeClient(ModularScreen screen) {
7582
@ApiStatus.Internal
7683
@SideOnly(Side.CLIENT)
7784
public void constructClientOnly() {
78-
this.player = Minecraft.getMinecraft().player;
85+
this.player = Platform.getClientPlayer();
7986
this.syncManager = null;
8087
}
8188

src/main/java/com/cleanroommc/modularui/screen/SecondaryPanel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.cleanroommc.modularui.screen;
22

33
import com.cleanroommc.modularui.api.IPanelHandler;
4-
import com.cleanroommc.modularui.api.MCHelper;
4+
import com.cleanroommc.modularui.utils.Platform;
55
import com.cleanroommc.modularui.widget.WidgetTree;
66

77
import net.minecraft.entity.player.EntityPlayer;
@@ -93,7 +93,7 @@ public void openPanel() {
9393

9494
@SideOnly(Side.CLIENT)
9595
private ModularPanel buildPanel() {
96-
return Objects.requireNonNull(this.provider.build(this.screen.getMainPanel(), MCHelper.getPlayer()));
96+
return Objects.requireNonNull(this.provider.build(this.screen.getMainPanel(), Platform.getClientPlayer()));
9797
}
9898

9999
public interface IPanelBuilder {

0 commit comments

Comments
 (0)