Skip to content

Commit

Permalink
yo, check out this broken code
Browse files Browse the repository at this point in the history
  • Loading branch information
RealRTTV committed Jun 19, 2024
1 parent f416f2b commit 70aaf2a
Show file tree
Hide file tree
Showing 9 changed files with 1,239 additions and 58 deletions.
36 changes: 36 additions & 0 deletions src/main/java/net/earthcomputer/clientcommands/ClientCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.LongArrayTag;
import net.minecraft.nbt.NbtIo;
import org.slf4j.Logger;

import java.io.IOException;
Expand Down Expand Up @@ -64,6 +68,38 @@ public class ClientCommands implements ClientModInitializer {

@Override
public void onInitializeClient() {
try {
String file = new String(ClientCommands.class.getResourceAsStream("/villager_lattice_data.csv").readAllBytes());
file = file.substring(file.indexOf('\n') + 1);
CompoundTag root = new CompoundTag();
ListTag lattice = new ListTag();
ListTag lattice_inverse = new ListTag();
ListTag offset = new ListTag();
for (String line : file.split("\n")) {
String[] values = line.split(",");
long[] longs = new long[9];
for (int i = 0; i < 9; i++) {
longs[i] = Long.parseLong(values[i]);
}
lattice.add(new LongArrayTag(longs));
long[] inverse = new long[9];
for (int i = 0; i < 9; i++) {
inverse[i] = Long.parseLong(values[i + 9]);
}
lattice_inverse.add(new LongArrayTag(inverse));
long[] offsets = new long[2];
for (int i = 0; i < 2; i++) {
offsets[i] = Long.parseLong(values[i + 11]);
}
offset.add(new LongArrayTag(offsets));
}
root.put("lattices", lattice);
root.put("lattice_inverses", lattice_inverse);
root.put("offsets", offset);
NbtIo.write(root, Path.of("villager_lattice_data.nbt"));
} catch (IOException e) {
throw new RuntimeException(e);
}
// Config
configDir = FabricLoader.getInstance().getConfigDir().resolve("clientcommands");
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.earthcomputer.clientcommands.features;

import com.mojang.logging.LogUtils;
import net.earthcomputer.clientcommands.command.ClientCommandHelper;
import net.earthcomputer.clientcommands.interfaces.IVillager;
import net.minecraft.client.Minecraft;
Expand All @@ -15,6 +14,9 @@
import java.util.UUID;

public class VillagerCracker {
// This value was computed by brute forcing all seeds
public static final float MAX_ERROR = 0x1.4p-24f;

@Nullable
private static UUID villagerUuid = null;
@Nullable
Expand Down Expand Up @@ -59,21 +61,8 @@ public static void onSoundEventPlayed(ClientboundSoundPacket packet) {
return;
}

if (packet.getSound().value().getLocation().getPath().startsWith("item.armor.equip_")) {
long seed = packet.getSeed();
long[] possible = CrackVillagerRngGen.getSeeds(seed).toArray();
if (possible.length == 0) {
ClientCommandHelper.sendError(Component.translatable("commands.cvillager.crackFailed"));
} else {
((IVillager) targetVillager).clientcommands_setCrackedRandom(RandomSource.create(possible[0] ^ 0x5deece66dL));
// simulate a tick to advance it by one
((IVillager) targetVillager).clientcommands_getCrackedRandom().simulateTick();
ClientCommandHelper.sendFeedback("commands.cvillager.crackSuccess", Long.toHexString(possible[0]));
}
}

if (packet.getSound().value().getLocation().getPath().equals("entity.villager.ambient")) {
((IVillager) targetVillager).clientcommands_onAmbientSoundPlayed();
if (packet.getSound().value().getLocation().toString().equals("minecraft:entity.villager.ambient")) {
((IVillager) targetVillager).clientcommands_onAmbientSoundPlayed(packet.getPitch());
}
}

Expand Down
Loading

0 comments on commit 70aaf2a

Please sign in to comment.