Skip to content

Commit

Permalink
SignHistorian - Small fix for loading signs from a file.
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTas committed Jun 28, 2024
1 parent d39f180 commit 0e76b8f
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/main/java/dev/stardust/modules/SignHistorian.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import meteordevelopment.meteorclient.events.entity.player.InteractBlockEvent;
import meteordevelopment.meteorclient.systems.modules.render.blockesp.ESPBlockData;


/**
* @author Tas [0xTas] <root@0xTas.dev>
**/
Expand Down Expand Up @@ -264,7 +263,8 @@ private void initOrLoadFromSignFile() {
Path historianFolder = FabricLoader.getInstance().getGameDir().resolve("meteor-client/sign-historian");

try {
if (!historianFolder.toFile().mkdirs()) Stardust.LOG.warn("");
//noinspection ResultOfMethodCallIgnored
historianFolder.toFile().mkdirs();
ServerInfo server = mc.getNetworkHandler().getServerInfo();
if (server == null) return;

Expand All @@ -282,7 +282,7 @@ private void initOrLoadFromSignFile() {
readSignsFromFile(signsFile);
}
} catch (Exception err) {
Stardust.LOG.error("[Stardust] "+err);
Stardust.LOG.error(err.toString());
}
}

Expand All @@ -292,15 +292,15 @@ private void readSignsFromFile(Path signsFile) {
for (String sign : entries) {
try {
String[] parts = sign.split(" -\\|- ");
if (parts.length != 2) return;
if (parts.length != 2) continue;
NbtCompound reconstructed = StringNbtReader.parse(parts[0].trim());
NbtCompound stateReconstructed = StringNbtReader.parse(parts[1].trim());
BlockPos bPos = BlockEntity.posFromNbt(reconstructed);

DataResult<BlockState> result = BlockState.CODEC.parse(NbtOps.INSTANCE, stateReconstructed);
BlockState state = result.result().orElse(null);

if (state == null) return;
if (state == null) continue;
BlockEntity be = BlockEntity.createFromNbt(bPos, state, reconstructed);

if (be instanceof SignBlockEntity sbeReconstructed) {
Expand All @@ -309,11 +309,11 @@ private void readSignsFromFile(Path signsFile) {
}
}
} catch (Exception err) {
Stardust.LOG.error("[Stardust] Failed to parse SignBlockEntity Nbt: "+err);
Stardust.LOG.error("Failed to parse SignBlockEntity Nbt: "+err);
}
}
}catch (Exception e) {
Stardust.LOG.error("[Stardust] "+e);
Stardust.LOG.error(e.toString());
}
}

Expand Down Expand Up @@ -433,7 +433,7 @@ private BlockPos getTargetedSign() {
// Signs placed in 1.8 - 1.12 (the majority of them) are "technically" irreplaceable due to metadata differences.
// You might say that they're the *new* old signs. Either way you can tell that they've been (re)placed after 1.19.
// To compensate for this, I'll hide a SignHistorian watermark in the NBT data which should clear up any confusion :]
if (sbe.createNbt().toString().contains("{\"extra\":[{\"") && n == 3) {
if (sbe.createNbt().toString().contains("{\"extra\":[") && n == 3) {
StringBuilder sb = new StringBuilder();
int lineLen = mc.textRenderer.getWidth(sbe.getFrontText().getMessage(n, false).getString());
int spaceLeftHalved = (90 - lineLen) / 2; // center original text
Expand Down Expand Up @@ -677,13 +677,11 @@ else if (targeted == null) {
} else lastTargetedSign = targeted;
if (mc.currentScreen instanceof AbstractSignEditScreen) return;

if (timer == -1) {
if (dyeSlot != -1) {
if (dyeSlot < 9) InvUtils.swapBack();
else InvUtils.move().from(mc.player.getInventory().selectedSlot).to(dyeSlot);
dyeSlot = -1;
timer = 3;
}
if (timer == -1 && dyeSlot != -1) {
if (dyeSlot < 9) InvUtils.swapBack();
else InvUtils.move().from(mc.player.getInventory().selectedSlot).to(dyeSlot);
dyeSlot = -1;
timer = 3;
}

WaxAura waxAura = Modules.get().get(WaxAura.class);
Expand Down

0 comments on commit 0e76b8f

Please sign in to comment.