Skip to content

Commit

Permalink
Use a malilib wrapper class to get the client instance
Browse files Browse the repository at this point in the history
  • Loading branch information
maruohon committed Oct 6, 2021
1 parent 967f4a3 commit b3e1d5b
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 36 deletions.
3 changes: 2 additions & 1 deletion src/main/java/fi/dy/masa/minihud/data/DataStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.world.chunk.Chunk;
import fi.dy.masa.malilib.overlay.message.MessageUtils;
import fi.dy.masa.malilib.util.EntityUtils;
import fi.dy.masa.malilib.util.GameUtils;
import fi.dy.masa.malilib.util.JsonUtils;
import fi.dy.masa.malilib.util.WorldUtils;
import fi.dy.masa.minihud.LiteModMiniHud;
Expand All @@ -35,7 +36,7 @@ public class DataStorage
{
private static final DataStorage INSTANCE = new DataStorage();

private final Minecraft mc = Minecraft.getMinecraft();
private final Minecraft mc = GameUtils.getClient();

private final MobCapDataHolder mobcapData = new MobCapDataHolder();
private final StructureStorage structureStorage = new StructureStorage();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/fi/dy/masa/minihud/data/MobCapDataHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.WorldServer;
import fi.dy.masa.malilib.util.GameUtils;
import fi.dy.masa.malilib.util.StringUtils;
import fi.dy.masa.minihud.util.MiscUtils;

Expand All @@ -29,7 +30,7 @@ public class MobCapDataHolder
"ambient", EnumCreatureType.AMBIENT,
"water_creature", EnumCreatureType.WATER_CREATURE);

private final Minecraft mc = Minecraft.getMinecraft();
private final Minecraft mc = GameUtils.getClient();
private final MobCapData localData = new MobCapData();
private final MobCapData syncedParsedData = new MobCapData();
private final MobCapData syncedPubsubData = new MobCapData();
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/fi/dy/masa/minihud/data/StructureStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.minecraft.world.gen.structure.StructureStart;
import fi.dy.masa.malilib.registry.Registry;
import fi.dy.masa.malilib.util.FileUtils;
import fi.dy.masa.malilib.util.GameUtils;
import fi.dy.masa.malilib.util.StringUtils;
import fi.dy.masa.malilib.util.data.Constants;
import fi.dy.masa.malilib.util.nbt.NbtUtils;
Expand Down Expand Up @@ -56,7 +57,7 @@ public class StructureStorage
private static final int SERVUX_PACKET_S2C_METADATA = 1;
private static final int SERVUX_PACKET_S2C_STRUCTURE_DATA = 2;

private final Minecraft mc = Minecraft.getMinecraft();
private final Minecraft mc = GameUtils.getClient();
private final ArrayListMultimap<StructureType, StructureData> structureMap = ArrayListMultimap.create();
@Nullable private BlockPos lastStructureUpdatePos;
private boolean hasStructureDataFromServer;
Expand Down Expand Up @@ -157,20 +158,18 @@ else if (this.structuresNeedUpdating(playerPos, 128))

public void requestStructureDataUpdates()
{
Minecraft mc = Minecraft.getMinecraft();

if (mc.world != null)
if (GameUtils.getClient().world != null)
{
boolean enabled = RendererToggle.OVERLAY_STRUCTURE_MAIN_TOGGLE.isRendererEnabled();

if (mc.isSingleplayer() == false)
if (GameUtils.isSinglePlayer() == false)
{
if (enabled)
{
Registry.CLIENT_PACKET_CHANNEL_HANDLER.registerClientChannelHandler(CarpetStructurePacketHandler.INSTANCE);
Registry.CLIENT_PACKET_CHANNEL_HANDLER.registerClientChannelHandler(ServuxStructurePacketHandler.INSTANCE);

LiteModMiniHud.logger.info("Attempting to register structure packet handlers to the server");
MiniHUD.logInfo("Attempting to register structure packet handlers to the server");
}
else
{
Expand Down Expand Up @@ -332,7 +331,7 @@ private void readStructureDataServuxV1(NBTTagCompound nbt)
this.structuresDirty = true;
this.structuresNeedUpdating = false;

EntityPlayer player = Minecraft.getMinecraft().player;
EntityPlayer player = GameUtils.getClientPlayer();

if (player != null)
{
Expand All @@ -356,7 +355,7 @@ private void readStructureDataCarpetAll(NBTTagCompound nbt)
this.structuresDirty = true;
this.structuresNeedUpdating = false;

EntityPlayer player = Minecraft.getMinecraft().player;
EntityPlayer player = GameUtils.getClientPlayer();

if (player != null)
{
Expand Down Expand Up @@ -395,7 +394,7 @@ private void readStructureDataCarpetSplitBoxes(PacketBuffer data, int boxCount)
this.structuresDirty = true;
this.structuresNeedUpdating = false;

EntityPlayer player = Minecraft.getMinecraft().player;
EntityPlayer player = GameUtils.getClientPlayer();

if (player != null)
{
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/fi/dy/masa/minihud/data/TpsData.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import fi.dy.masa.malilib.util.GameUtils;
import fi.dy.masa.malilib.util.StringUtils;

public class TpsData
{
private static final Pattern PATTERN_CARPET_TPS = Pattern.compile("TPS: (?<tps>[0-9]+[\\.,][0-9]) MSPT: (?<mspt>[0-9]+[\\.,][0-9])");

private final Minecraft mc = Minecraft.getMinecraft();
private final Minecraft mc = GameUtils.getClient();
private boolean hasCalculatedTpsData;
private boolean hasSyncedTpsData;
private boolean hasPubsubData;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/fi/dy/masa/minihud/event/RenderHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import fi.dy.masa.malilib.registry.Registry;
import fi.dy.masa.malilib.render.inventory.InventoryRenderUtils;
import fi.dy.masa.malilib.util.BlockUtils;
import fi.dy.masa.malilib.util.GameUtils;
import fi.dy.masa.malilib.util.StringUtils;
import fi.dy.masa.malilib.util.WorldUtils;
import fi.dy.masa.minihud.Reference;
Expand Down Expand Up @@ -371,7 +372,7 @@ private void addLine(String text)

private void addLine(InfoLine type)
{
Minecraft mc = Minecraft.getMinecraft();
Minecraft mc = GameUtils.getClient();
Entity entity = mc.getRenderViewEntity();
World world = entity.getEntityWorld();
BlockPos pos = new BlockPos(entity.posX, entity.getEntityBoundingBox().minY, entity.posZ);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fi.dy.masa.minihud.hotkeys;

import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import fi.dy.masa.malilib.config.option.BooleanConfig;
Expand All @@ -10,6 +9,7 @@
import fi.dy.masa.malilib.input.callback.ToggleBooleanWithMessageKeyCallback;
import fi.dy.masa.malilib.overlay.message.MessageUtils;
import fi.dy.masa.malilib.util.EntityUtils;
import fi.dy.masa.malilib.util.GameUtils;
import fi.dy.masa.malilib.util.StringUtils;
import fi.dy.masa.minihud.config.Configs;
import fi.dy.masa.minihud.config.RendererToggle;
Expand All @@ -28,9 +28,7 @@ public RendererToggleHotkeyCallback(BooleanConfig config)
@Override
public ActionResult onKeyAction(KeyAction action, KeyBind key)
{
Minecraft mc = Minecraft.getMinecraft();

if (mc != null && mc.player != null && super.onKeyAction(action, key) == ActionResult.SUCCESS)
if (GameUtils.getClientPlayer() != null && super.onKeyAction(action, key) == ActionResult.SUCCESS)
{
if (this.config.getBooleanValue() == false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import io.netty.buffer.Unpooled;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.item.EnumDyeColor;
Expand All @@ -24,6 +23,7 @@
import fi.dy.masa.malilib.network.PacketSplitter;
import fi.dy.masa.malilib.network.PluginChannelHandler;
import fi.dy.masa.malilib.registry.Registry;
import fi.dy.masa.malilib.util.GameUtils;
import fi.dy.masa.minihud.LiteModMiniHud;
import fi.dy.masa.minihud.config.Configs;
import fi.dy.masa.minihud.config.InfoLine;
Expand Down Expand Up @@ -183,7 +183,7 @@ public static void unsubscribe(Collection<String> nodes)

private static void updateSubscriptions(int updateType, Collection<String> nodes)
{
NetHandlerPlayClient handler = Minecraft.getMinecraft().getConnection();
NetHandlerPlayClient handler = GameUtils.getClient().getConnection();

if (handler != null)
{
Expand Down Expand Up @@ -231,7 +231,7 @@ public static void updatePubsubSubscriptions()
{
ServuxInfoSubDataPacketHandler.INSTANCE.updateSubscriptions();

World world = Minecraft.getMinecraft().world;
World world = GameUtils.getClient().world;

if (world != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Set;
import io.netty.buffer.Unpooled;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.nbt.NBTTagCompound;
Expand All @@ -22,6 +21,7 @@
import fi.dy.masa.malilib.network.PluginChannelHandler;
import fi.dy.masa.malilib.overlay.message.MessageDispatcher;
import fi.dy.masa.malilib.registry.Registry;
import fi.dy.masa.malilib.util.GameUtils;
import fi.dy.masa.malilib.util.data.Constants;
import fi.dy.masa.malilib.util.data.palette.HashMapPalette;
import fi.dy.masa.malilib.util.data.palette.Palette;
Expand All @@ -38,7 +38,6 @@ public class ServuxInfoSubDataPacketHandler implements PluginChannelHandler
public static final ServuxInfoSubDataPacketHandler INSTANCE = new ServuxInfoSubDataPacketHandler();
protected static final List<ResourceLocation> CHANNELS = ImmutableList.of(new ResourceLocation("servux:info_data"));

protected final Minecraft mc = Minecraft.getMinecraft();
protected final Map<String, BufferReader> allBufferReaders = new HashMap<>();
protected final Int2ObjectOpenHashMap<BufferReader> idMappedDataReaders = new Int2ObjectOpenHashMap<>();
protected final Set<String> currentSubscriptions = new HashSet<>();
Expand Down Expand Up @@ -191,7 +190,7 @@ protected NBTTagCompound channelToTag(String channel)

protected void updateSubscriptions(String action, Collection<String> channels)
{
NetHandlerPlayClient handler = Minecraft.getMinecraft().getConnection();
NetHandlerPlayClient handler = GameUtils.getClient().getConnection();

if (handler != null)
{
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/fi/dy/masa/minihud/renderer/RenderUtils.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package fi.dy.masa.minihud.renderer;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import fi.dy.masa.malilib.util.data.Color4f;
import fi.dy.masa.malilib.util.EntityUtils;
import fi.dy.masa.malilib.util.GameUtils;
import fi.dy.masa.malilib.util.MathUtils;
import fi.dy.masa.malilib.util.data.Color4f;

public class RenderUtils
{
Expand All @@ -29,7 +29,7 @@ public static void renderWallsWithLines(

final int centerX = (int) Math.floor(entity.posX);
final int centerZ = (int) Math.floor(entity.posZ);
final int maxDist = Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 32; // double the view distance in blocks
final int maxDist = GameUtils.getClient().gameSettings.renderDistanceChunks * 32; // double the view distance in blocks
final int rangeMinX = centerX - maxDist;
final int rangeMinZ = centerZ - maxDist;
final int rangeMaxX = centerX + maxDist;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.entity.Entity;
import fi.dy.masa.malilib.config.value.BaseOptionListConfigValue;
import fi.dy.masa.malilib.listener.LayerRangeChangeListener;
import fi.dy.masa.malilib.util.GameUtils;
import fi.dy.masa.malilib.util.JsonUtils;
import fi.dy.masa.malilib.util.StringUtils;
import fi.dy.masa.malilib.util.data.Color4f;
Expand All @@ -18,7 +19,7 @@

public abstract class ShapeBase extends OverlayRendererBase implements LayerRangeChangeListener
{
protected final Minecraft mc;
protected final Minecraft mc = GameUtils.getClient();
protected final ShapeType type;
protected final LayerRange layerRange;
protected String displayName;
Expand All @@ -29,7 +30,6 @@ public abstract class ShapeBase extends OverlayRendererBase implements LayerRang

public ShapeBase(ShapeType type, Color4f color)
{
this.mc = Minecraft.getMinecraft();
this.type = type;
this.color = color;
this.layerRange = new LayerRange(this);
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/fi/dy/masa/minihud/util/DebugInfoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import io.netty.buffer.Unpooled;
import com.google.common.collect.MapMaker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.debug.DebugRendererNeighborsUpdate;
Expand All @@ -19,12 +20,12 @@
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import fi.dy.masa.malilib.util.GameUtils;
import fi.dy.masa.malilib.util.WorldUtils;
import fi.dy.masa.minihud.config.Configs;
import fi.dy.masa.minihud.config.RendererToggle;
import fi.dy.masa.minihud.mixin.IMixinDebugRenderer;
import fi.dy.masa.minihud.mixin.IMixinPathNavigate;
import io.netty.buffer.Unpooled;

public class DebugInfoUtils
{
Expand Down Expand Up @@ -127,18 +128,18 @@ public static void onNeighborNotify(World world, BlockPos pos, EnumSet<EnumFacin
{
final long time = world.getTotalWorldTime();

Minecraft.getMinecraft().addScheduledTask(() -> {
GameUtils.getClient().addScheduledTask(() -> {
for (EnumFacing side : notifiedSides)
{
((DebugRendererNeighborsUpdate) Minecraft.getMinecraft().debugRenderer.neighborsUpdate).addUpdate(time, pos.offset(side));
((DebugRendererNeighborsUpdate) GameUtils.getClient().debugRenderer.neighborsUpdate).addUpdate(time, pos.offset(side));
}
});
}
}

public static void onServerTickEnd(MinecraftServer server)
{
Minecraft mc = Minecraft.getMinecraft();
Minecraft mc = GameUtils.getClient();

// Send the custom packet with the Path data, if that debug renderer is enabled
if (pathFindingEnabled && mc.world != null && ++tickCounter >= 10)
Expand Down Expand Up @@ -207,7 +208,7 @@ private static boolean isAnyPlayerWithinRange(World world, Entity entity, double

public static void toggleDebugRenderer(RendererToggle config)
{
Minecraft mc = Minecraft.getMinecraft();
Minecraft mc = GameUtils.getClient();
boolean enabled = config.isRendererEnabled();

if (config == RendererToggle.DEBUG_COLLISION_BOXES)
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/fi/dy/masa/minihud/util/MiscUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.List;
import java.util.Random;
import java.util.Set;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand All @@ -18,6 +17,7 @@
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.WorldServer;
import net.minecraft.world.gen.structure.StructureBoundingBox;
import fi.dy.masa.malilib.util.GameUtils;
import fi.dy.masa.malilib.util.StringUtils;
import fi.dy.masa.malilib.util.data.IntBoundingBox;
import fi.dy.masa.malilib.util.nbt.PrettyNbtStringifier;
Expand Down Expand Up @@ -180,12 +180,11 @@ public static int getSpawnableChunksCount(WorldServer world)

public static void getItemTooltip(ItemStack stack, List<String> lines)
{
Minecraft mc = Minecraft.getMinecraft();
boolean showPretty = Configs.Generic.ITEM_NBT_KEY_PRETTY.isHeld();
boolean showString = Configs.Generic.ITEM_NBT_KEY_STRING.isHeld();

// If the vanilla advanced tooltips are disabled, add them here, when showing a tooltip
if (mc.gameSettings.advancedItemTooltips == false && (showPretty || showString))
if (GameUtils.getClient().gameSettings.advancedItemTooltips == false && (showPretty || showString))
{
if (stack.isItemDamaged())
{
Expand Down

0 comments on commit b3e1d5b

Please sign in to comment.