Skip to content

Commit

Permalink
Fixes and Modlist packet option
Browse files Browse the repository at this point in the history
  • Loading branch information
UselessBullets committed Dec 16, 2023
1 parent 397931e commit 1ef2ac9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/main/java/turniplabs/halplibe/HalpLibe.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@
public class HalpLibe implements ModInitializer, PreLaunchEntrypoint {
public static final String MOD_ID = "halplibe";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static boolean sendModlist;
public static final TomlConfigHandler CONFIG;
static {
Toml toml = new Toml();
toml.addCategory("Experimental");
toml.addEntry("Experimental.AtlasWidth", "Dynamically resized the Terrain and Item atlases, value must be an integer greater than or equal to 32",32);
toml.addCategory("Network");
toml.addEntry("Network.SendModlistPack", "This sends a modlist packet to clients that join the server when enabled, however it may cause issues if the clients do not have halplibe installed", true);


CONFIG = new TomlConfigHandler(MOD_ID, toml);

Global.TEXTURE_ATLAS_WIDTH_TILES = Math.max(32, CONFIG.getInt("Experimental.AtlasWidth"));
sendModlist = CONFIG.getBoolean("Network.SendModlistPack");

// Initialize Block and Item static fields
try {
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/turniplabs/halplibe/helper/RegistryHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import java.util.function.Consumer;

public class RegistryHelper {
private static final ArrayList<Runnable> regsitryFunctions = new ArrayList<>();
private static final ArrayList<Runnable> configuredRegsitryFunctions = new ArrayList<>();
private static final ArrayList<Runnable> smartRregsitryFunctions = new ArrayList<>();
private static final ArrayList<Runnable> registryFunctions = new ArrayList<>();
private static final ArrayList<Runnable> configuredRegistryFunctions = new ArrayList<>();
private static final ArrayList<Runnable> smartRegistryFunctions = new ArrayList<>();

/**
* Only intended for internal use from {@link BlockHelper#reserveRuns(Toml, int, Consumer)} and {@link ItemHelper#reserveRuns(Toml, int, Consumer)}
Expand All @@ -17,7 +17,7 @@ public class RegistryHelper {
* @param function the function to run on registry handling
*/
public static void scheduleSmartRegistry(Runnable function) {
smartRregsitryFunctions.add(function);
smartRegistryFunctions.add(function);
}

/**
Expand All @@ -32,14 +32,14 @@ public static void scheduleSmartRegistry(Runnable function) {
* @param function the function to run upon registering stuff
*/
public static void scheduleRegistry(boolean configured, Runnable function) {
if (configured) configuredRegsitryFunctions.add(function);
else regsitryFunctions.add(function);
if (configured) configuredRegistryFunctions.add(function);
else registryFunctions.add(function);
}

@SuppressWarnings("unused")
private static void runRegistry() {
for (Runnable regsitryFunction : configuredRegsitryFunctions) regsitryFunction.run();
for (Runnable regsitryFunction : smartRregsitryFunctions) regsitryFunction.run();
for (Runnable regsitryFunction : regsitryFunctions) regsitryFunction.run();
for (Runnable registryFunction : configuredRegistryFunctions) registryFunction.run();
for (Runnable registryFunction : smartRegistryFunctions) registryFunction.run();
for (Runnable registryFunction : registryFunctions) registryFunction.run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import turniplabs.halplibe.HalpLibe;
import turniplabs.halplibe.helper.ModVersionHelper;
import turniplabs.halplibe.util.version.IVersionPackets;
import turniplabs.halplibe.util.version.ModInfo;
import turniplabs.halplibe.util.version.PacketModList;

import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import turniplabs.halplibe.HalpLibe;
import turniplabs.halplibe.helper.ModVersionHelper;
import turniplabs.halplibe.util.version.PacketModList;

@Mixin(value = NetLoginHandler.class, remap = false)
public class NetLoginHandlerMixin {
@Inject(method = "doLogin(Lnet/minecraft/core/net/packet/Packet1Login;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/net/handler/NetServerHandler;sendPacket(Lnet/minecraft/core/net/packet/Packet;)V", ordinal = 6, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
private void modlistPacket(Packet1Login packet1login, CallbackInfo ci, EntityPlayerMP entityplayermp){
entityplayermp.playerNetServerHandler.sendPacket(new PacketModList(ModVersionHelper.getLocalModlist()));
if (HalpLibe.sendModlist){
entityplayermp.playerNetServerHandler.sendPacket(new PacketModList(ModVersionHelper.getLocalModlist()));
}
}
}
10 changes: 9 additions & 1 deletion src/main/java/turniplabs/halplibe/util/TextureHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void update() {

for (int i = 0; i < this.resolution * scale; ++i) {
for (int j = 0; j < this.resolution * scale; ++j) {
//transferPixel(this.frames, (int) (this.elapsedTicks * this.resolution * this.resolution * scale * scale + j * this.resolution * scale + i), this.imageData, (int) (j * this.resolution * scale + i));
transferPixel(this.frames, (int) (this.elapsedTicks * this.resolution * this.resolution * scale * scale + j * this.resolution * scale + i), this.imageData, (int) (j * this.resolution * scale + i));
}
}

Expand All @@ -89,4 +89,12 @@ public static int getAtlasResolution(String textureName, int defaultResolution){
}
return defaultResolution;
}

// Copied the old method from 7.0 since it was deleted in 7.1-pre1
public static void transferPixel(byte[] array1, int i, byte[] array2, int j) {
array2[j * 4 + 0] = array1[i * 4 + 0];
array2[j * 4 + 1] = array1[i * 4 + 1];
array2[j * 4 + 2] = array1[i * 4 + 2];
array2[j * 4 + 3] = array1[i * 4 + 3];
}
}

0 comments on commit 1ef2ac9

Please sign in to comment.