Skip to content

Commit

Permalink
More clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
maruohon committed Dec 18, 2022
1 parent 1b0a642 commit a1641a8
Show file tree
Hide file tree
Showing 18 changed files with 182 additions and 172 deletions.
2 changes: 1 addition & 1 deletion src/main/java/minihud/InitHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void registerModHandlers()
Registry.CLIENT_PACKET_CHANNEL_HANDLER.registerClientChannelHandler(ServuxInfoSubRegistrationPacketHandler.INSTANCE);
Registry.CLIENT_PACKET_CHANNEL_HANDLER.registerClientChannelHandler(ServuxInfoSubDataPacketHandler.INSTANCE);

MiniHUDActions.init();
MiniHudActions.init();
ConfigCallbacks.init();
}
}
4 changes: 0 additions & 4 deletions src/main/java/minihud/LiteModMiniHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@
import com.mumfrey.liteloader.Configurable;
import com.mumfrey.liteloader.LiteMod;
import com.mumfrey.liteloader.modconfig.ConfigPanel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import malilib.registry.Registry;
import minihud.gui.MiniHudConfigPanel;

public class LiteModMiniHud implements LiteMod, Configurable
{
public static final Logger logger = LogManager.getLogger(Reference.MOD_ID);

public LiteModMiniHud()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import minihud.config.Configs;

public class MiniHUD
public class MiniHud
{
public static final Logger LOGGER = LogManager.getLogger(Reference.MOD_ID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import minihud.gui.GuiShapeEditor;
import minihud.gui.ShapeManagerScreen;

public class MiniHUDActions
public class MiniHudActions
{
public static final NamedAction OPEN_CONFIG_SCREEN = register("openConfigScreen", ConfigScreen::open);
public static final NamedAction OPEN_SHAPE_EDITOR = register("openShapeEditor", GuiShapeEditor::openShapeEditor);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/minihud/config/ConfigCallbacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import minihud.data.DataStorage;
import minihud.data.WoolCounters;
import minihud.data.structure.StructureDataUtils;
import minihud.MiniHUDActions;
import minihud.MiniHudActions;
import minihud.network.carpet.CarpetPubsubPacketHandler;
import minihud.network.servux.ServuxInfoSubDataPacketHandler;
import minihud.renderer.RenderContainer;
Expand All @@ -26,10 +26,10 @@ public static void init()
{
Configs.Generic.OVERLAYS_RENDERING_TOGGLE.addValueChangeListener(OverlayRendererContainer.INSTANCE::setEnabledRenderersNeedUpdate);

Configs.Hotkeys.OPEN_CONFIG_GUI.createCallbackForAction(MiniHUDActions.OPEN_CONFIG_SCREEN);
Configs.Hotkeys.OPEN_SHAPE_EDITOR.createCallbackForAction(MiniHUDActions.OPEN_SHAPE_EDITOR);
Configs.Hotkeys.OPEN_SHAPE_MANAGER.createCallbackForAction(MiniHUDActions.OPEN_SHAPE_MANAGER);
Configs.Hotkeys.SET_DISTANCE_REFERENCE_POINT.createCallbackForAction(MiniHUDActions.SET_DISTANCE_REFERENCE_POINT);
Configs.Hotkeys.OPEN_CONFIG_GUI.createCallbackForAction(MiniHudActions.OPEN_CONFIG_SCREEN);
Configs.Hotkeys.OPEN_SHAPE_EDITOR.createCallbackForAction(MiniHudActions.OPEN_SHAPE_EDITOR);
Configs.Hotkeys.OPEN_SHAPE_MANAGER.createCallbackForAction(MiniHudActions.OPEN_SHAPE_MANAGER);
Configs.Hotkeys.SET_DISTANCE_REFERENCE_POINT.createCallbackForAction(MiniHudActions.SET_DISTANCE_REFERENCE_POINT);

InfoLineToggle.CHUNK_UNLOAD_ORDER.getHotkeyConfig().getKeyBind().setCallback(AdjustableValueHotkeyCallback.createBitShifter(
InfoLineToggle.CHUNK_UNLOAD_ORDER.getBooleanConfig(), Configs.Generic.DROPPED_CHUNKS_HASH_SIZE)
Expand Down
125 changes: 5 additions & 120 deletions src/main/java/minihud/data/DataStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@

import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;

import malilib.overlay.message.MessageUtils;
import malilib.util.data.json.JsonUtils;
import malilib.util.game.WorldUtils;
import malilib.util.game.wrap.EntityWrap;
import malilib.util.game.wrap.GameUtils;
import minihud.LiteModMiniHud;
import minihud.config.Configs;
import minihud.data.structure.StructureDataUtils;
import minihud.data.structure.StructureStorage;
import minihud.event.RenderHandler;
Expand Down Expand Up @@ -121,6 +117,11 @@ public boolean hasStoredWorldSeed()
return this.worldProperties.worldSeed.isPresent();
}

public long getStoredWorldSeed()
{
return this.worldProperties.worldSeed.isPresent() ? this.worldProperties.worldSeed.getAsLong() : 0;
}

public long getWorldSeed(World world)
{
if (this.hasStoredWorldSeed() == false && GameUtils.isSinglePlayer())
Expand Down Expand Up @@ -191,122 +192,6 @@ public double getBlockBreakingSpeed()
return MiscUtils.intAverage(this.blockBreakCounter) * 20;
}

public boolean onSendChatMessage(String message)
{
String[] parts = message.split(" ");

if (parts[0].equals("minihud-seed"))
{
if (parts.length == 2)
{
try
{
long seed = Long.parseLong(parts[1]);
this.setWorldSeed(seed);
MessageUtils.printCustomActionbarMessage("minihud.message.info.seed_set", seed);
}
catch (NumberFormatException e)
{
MessageUtils.printCustomActionbarMessage("minihud.message.error.failed_to_parse_seed_from_chat");
}
}
else if (this.worldProperties.worldSeed.isPresent() && parts.length == 1)
{
MessageUtils.printCustomActionbarMessage("minihud.message.info.seed_set",
this.worldProperties.worldSeed.getAsLong());
}

return true;
}
else if (parts[0].equals("minihud-dropped-chunks-hash-size"))
{
if (parts.length == 2)
{
try
{
int size = Integer.parseInt(parts[1]);
Configs.Generic.DROPPED_CHUNKS_HASH_SIZE.setValue(size);
// Fetch it again from the config, to take the bounds clamping into account
MessageUtils.printCustomActionbarMessage("minihud.message.info.dropped_chunks_hash_size_set_to",
Configs.Generic.DROPPED_CHUNKS_HASH_SIZE.getIntegerValue());
}
catch (NumberFormatException e)
{
MessageUtils.printCustomActionbarMessage("minihud.message.error.invalid_dropped_chunks_hash_size");
}
}
else if (parts.length == 1)
{
MessageUtils.printCustomActionbarMessage("minihud.message.info.dropped_chunks_hash_size_get",
DroppedChunks.getDroppedChunksHashSize());
}

return true;
}

return false;
}

public void onChatMessage(ITextComponent message)
{
if (message instanceof TextComponentTranslation)
{
TextComponentTranslation text = (TextComponentTranslation) message;

// The vanilla "/seed" command
if ("commands.seed.success".equals(text.getKey()))
{
try
{
long seed = Long.parseLong(text.getFormatArgs()[0].toString());
this.setWorldSeed(seed);
LiteModMiniHud.logger.info("Received world seed from the vanilla /seed command: {}", seed);
MessageUtils.printCustomActionbarMessage("minihud.message.info.seed_set", seed);
}
catch (Exception e)
{
LiteModMiniHud.logger.warn("Failed to read the world seed from '{}'", text.getFormatArgs()[0], e);
}
}
// The "/jed seed" command
else if ("jed.commands.seed.success".equals(text.getKey()))
{
try
{
long seed = Long.parseLong(text.getFormatArgs()[1].toString());
this.setWorldSeed(seed);
LiteModMiniHud.logger.info("Received world seed from the JED '/jed seed' command: {}", seed);
MessageUtils.printCustomActionbarMessage("minihud.message.info.seed_set", seed);
}
catch (Exception e)
{
LiteModMiniHud.logger.warn("Failed to read the world seed from '{}'", text.getFormatArgs()[1], e);
}
}
else if ("commands.setworldspawn.success".equals(text.getKey()) && text.getFormatArgs().length == 3)
{
try
{
Object[] o = text.getFormatArgs();
int x = Integer.parseInt(o[0].toString());
int y = Integer.parseInt(o[1].toString());
int z = Integer.parseInt(o[2].toString());

BlockPos spawn = new BlockPos(x, y, z);
this.setWorldSpawn(spawn);

String spawnStr = String.format("x: %d, y: %d, z: %d", spawn.getX(), spawn.getY(), spawn.getZ());
LiteModMiniHud.logger.info("Received world spawn from the vanilla /setworldspawn command: {}", spawnStr);
MessageUtils.printCustomActionbarMessage("minihud.message.info.spawn_set", spawnStr);
}
catch (Exception e)
{
LiteModMiniHud.logger.warn("Failed to read the world spawn point from '{}'", text.getFormatArgs(), e);
}
}
}
}

public JsonObject toJson()
{
JsonObject obj = new JsonObject();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/minihud/data/WorldGenPositions.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import net.minecraft.util.math.BlockPos;

import minihud.MiniHUD;
import minihud.MiniHud;
import minihud.config.Configs;

public class WorldGenPositions
Expand Down Expand Up @@ -49,7 +49,7 @@ public void addDungeonSpawnerPosition(BlockPos pos)

if (Configs.Generic.SPAWNER_POSITION_PRINT.getBooleanValue())
{
MiniHUD.LOGGER.info("Spawner gen attempt: Chunk: [{}, {}] pos: [{}, {}, {}]",
MiniHud.LOGGER.info("Spawner gen attempt: Chunk: [{}, {}] pos: [{}, {}, {}]",
pos.getX() >> 4, pos.getZ() >> 4, pos.getX(), pos.getY(), pos.getZ());
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/minihud/data/structure/StructureDataUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import malilib.util.game.wrap.NbtWrap;
import malilib.util.nbt.NbtUtils;
import malilib.util.position.IntBoundingBox;
import minihud.MiniHUD;
import minihud.MiniHud;
import minihud.Reference;
import minihud.config.RendererToggle;
import minihud.mixin.structure.ChunkGeneratorEndMixin;
Expand All @@ -61,7 +61,7 @@ public static void requestStructureDataUpdates()
{
if (enabled)
{
MiniHUD.debugLog("Attempting to register structure packet handlers to the server");
MiniHud.debugLog("Attempting to register structure packet handlers to the server");

// TODO on Servux servers this re-register shouldn't be done when the player just moves around.
// But on 1.12.x Carpet server I think a re-request is needed, it doesn't seem like the server
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/minihud/data/structure/StructureStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import malilib.util.game.wrap.EntityWrap;
import malilib.util.game.wrap.GameUtils;
import minihud.MiniHUD;
import minihud.MiniHud;
import minihud.data.structure.StructureDataUtils.StructureFileUtils;

public class StructureStorage
Expand Down Expand Up @@ -62,13 +62,13 @@ public void addStructureDataFromServer(ArrayListMultimap<StructureType, Structur
public void addStructureDataFromLocalStructureFiles(ArrayListMultimap<StructureType, StructureData> data)
{
this.addStructureData(data);
MiniHUD.debugLog("Structure data updated from local structure files, structure count = {}", data.size());
MiniHud.debugLog("Structure data updated from local structure files, structure count = {}", data.size());
}

public void addStructureDataFromIntegratedServer(ArrayListMultimap<StructureType, StructureData> data)
{
this.addStructureData(data);
MiniHUD.debugLog("Structure data updated from the integrated server, structure count = {}", data.size());
MiniHud.debugLog("Structure data updated from the integrated server, structure count = {}", data.size());
}

protected void addStructureData(ArrayListMultimap<StructureType, StructureData> data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;

import minihud.data.DataStorage;
import minihud.util.ChatUtils;

@Mixin(GuiScreen.class)
public abstract class GuiScreenMixin extends Gui
Expand All @@ -19,7 +19,7 @@ public abstract class GuiScreenMixin extends Gui
cancellable = true)
private void onSendMessage(String msg, boolean addToChat, CallbackInfo ci)
{
if (DataStorage.getInstance().onSendChatMessage(msg))
if (ChatUtils.onSendChatMessage(msg))
{
ci.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import minihud.data.DataStorage;
import minihud.data.MobCapDataHandler;
import minihud.data.TpsDataManager;
import minihud.util.ChatUtils;
import minihud.util.NotificationUtils;

@Mixin(NetHandlerPlayClient.class)
Expand All @@ -26,7 +27,7 @@ public abstract class NetHandlerPlayClientMixin
@Inject(method = "handleChat", at = @At("RETURN"))
private void onChatMessage(SPacketChat packet, CallbackInfo ci)
{
DataStorage.getInstance().onChatMessage(packet.getChatComponent());
ChatUtils.onReceiveChatMessage(packet.getChatComponent());
}

@Inject(method = "handleTimeUpdate", at = @At("RETURN"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import malilib.network.message.BasePacketHandler;
import malilib.registry.Registry;
import malilib.util.game.wrap.GameUtils;
import minihud.LiteModMiniHud;
import minihud.MiniHud;
import minihud.config.Configs;
import minihud.config.InfoLineToggle;
import minihud.config.RendererToggle;
Expand Down Expand Up @@ -199,7 +199,7 @@ else if (updateType == PACKET_C2S_UNSUBSCRIBE && this.subscriptions.contains(nod
if (Configs.Generic.DEBUG_MESSAGES.getBooleanValue())
{
String action = updateType == PACKET_C2S_SUBSCRIBE ? "sub" : "unsub";
LiteModMiniHud.logger.info("Action: '{}', nodes: '{}'", action, actionableNodes);
MiniHud.LOGGER.info("Action: '{}', nodes: '{}'", action, actionableNodes);
}

PacketBuffer buf = new PacketBuffer(Unpooled.buffer());
Expand Down
Loading

0 comments on commit a1641a8

Please sign in to comment.