Skip to content

Commit

Permalink
Port to Mojmap (#596)
Browse files Browse the repository at this point in the history
* Initial port

* Optimize imports

* Rename things to match Mojmap

* Always use wildcard imports for import static, as per CONTRIBUTING.md

* Update Parchment

* Replace a few more names

* More renames

* Use a star import in ClientCommands

* Fix some more names
  • Loading branch information
Gaming32 authored Feb 11, 2024
1 parent 0840f87 commit e23b216
Show file tree
Hide file tree
Showing 200 changed files with 3,545 additions and 3,458 deletions.
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ repositories {
maven {
url = "https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1"
}
maven {
url = "https://maven.parchmentmc.org"
}
}

loom {
Expand All @@ -35,7 +38,12 @@ loom {

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
mappings loom.layered {
officialMojangMappings {
nameSyntheticMembers = true
}
parchment("org.parchmentmc.data:parchment-1.20.3:2023.12.31@zip")
}
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

Expand Down
48 changes: 24 additions & 24 deletions src/main/java/net/cortex/clientAddon/cracker/SeedCracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import net.earthcomputer.clientcommands.command.ClientCommandHelper;
import net.earthcomputer.clientcommands.features.EnchantmentCracker;
import net.earthcomputer.clientcommands.features.PlayerRandCracker;
import net.earthcomputer.clientcommands.mixin.CheckedRandomAccessor;
import net.earthcomputer.clientcommands.mixin.LegacyRandomSourceAccessor;
import net.earthcomputer.clientcommands.task.LongTask;
import net.earthcomputer.clientcommands.task.TaskManager;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
import net.minecraft.text.*;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.random.Random;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.EntityType;

public class SeedCracker {
public interface OnCrack {void callback(long seed); }
Expand All @@ -30,13 +30,13 @@ public interface OnCrack {void callback(long seed); }
//returns True on success or false on failer
private static boolean throwItems()
{
ClientPlayerEntity player = MinecraftClient.getInstance().player;
player.refreshPositionAndAngles(player.getX(), player.getY(), player.getZ(), 0, 90);
MinecraftClient.getInstance().getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(0, 90, true)); // point to correct location
LocalPlayer player = Minecraft.getInstance().player;
player.moveTo(player.getX(), player.getY(), player.getZ(), 0, 90);
Minecraft.getInstance().getConnection().send(new ServerboundMovePlayerPacket.Rot(0, 90, true)); // point to correct location
for (int i = 0; i < 20; i++) {
boolean success = PlayerRandCracker.throwItem();
if (!success) {
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.translatable("itemCrack.notEnoughItems").formatted(Formatting.RED));
Minecraft.getInstance().gui.getChat().addMessage(Component.translatable("itemCrack.notEnoughItems").withStyle(ChatFormatting.RED));
EnchantmentCracker.LOGGER.info("Unable to use rng SeedCracker |not enough items|");
return false;
}
Expand All @@ -51,8 +51,8 @@ public static void attemptCrack()
{
attemptCount++;
if (attemptCount > MAX_ATTEMPTS) {
ClientCommandHelper.sendError(Text.translatable("commands.ccrackrng.failed"));
ClientCommandHelper.sendHelp(Text.translatable("commands.ccrackrng.failed.help"));
ClientCommandHelper.sendError(Component.translatable("commands.ccrackrng.failed"));
ClientCommandHelper.sendHelp(Component.translatable("commands.ccrackrng.failed.help"));
Configs.playerCrackState = PlayerRandCracker.CrackState.UNCRACKED;
} else {
SeedCracker.doCrack(SeedCracker.callback);
Expand All @@ -63,11 +63,11 @@ public static void attemptCrack()

Configs.playerCrackState = PlayerRandCracker.CrackState.CRACKED;

Random rand=Random.create(seed ^ 0x5deece66dL);
RandomSource rand=RandomSource.create(seed ^ 0x5deece66dL);
rand.nextFloat();
rand.nextFloat();
//rand.nextFloat();

/*
for(int i=0;i<13;i++) {
long x = (((long) (rand.nextFloat() * ((float) (1 << 24)))) >> (24 - 4))&0xFL;
Expand All @@ -77,7 +77,7 @@ public static void attemptCrack()
System.out.print(padLeftZeros(Long.toBinaryString((((long) (rand.nextFloat() * ((float) (1 << 24)))) >> (24 - 4))&0xFL), 4)+" \n");
}*/

callback.callback(((CheckedRandomAccessor) rand).getSeed().get());//extract seed and call callback
callback.callback(((LegacyRandomSourceAccessor) rand).getSeed().get());//extract seed and call callback
}

public static void crack(OnCrack callback) {
Expand All @@ -87,28 +87,28 @@ public static void crack(OnCrack callback) {

private static void doCrack(OnCrack Callback){
callback=Callback;
ClientCommandHelper.addOverlayMessage(Text.translatable("commands.ccrackrng.retries", attemptCount, MAX_ATTEMPTS), 100);
ClientCommandHelper.addOverlayMessage(Component.translatable("commands.ccrackrng.retries", attemptCount, MAX_ATTEMPTS), 100);
if(throwItems())
{
Configs.playerCrackState = PlayerRandCracker.CrackState.CRACKING;
expectedItems=20;
if (currentTask == null) {
currentTask = new SeedCrackTask();
String taskName = TaskManager.addTask("ccrackrng", currentTask);
Text message = Text.translatable("commands.ccrackrng.starting")
Component message = Component.translatable("commands.ccrackrng.starting")
.append(" ")
.append(ClientCommandHelper.getCommandTextComponent("commands.client.cancel", "/ctask stop " + taskName));
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(message);
Minecraft.getInstance().gui.getChat().addMessage(message);
}
} else {
Configs.playerCrackState = PlayerRandCracker.CrackState.UNCRACKED;
}
}

public static void onEntityCreation(EntitySpawnS2CPacket packet) {
if (packet.getEntityType() == EntityType.ITEM && Configs.playerCrackState == PlayerRandCracker.CrackState.CRACKING) {
public static void onEntityCreation(ClientboundAddEntityPacket packet) {
if (packet.getType() == EntityType.ITEM && Configs.playerCrackState == PlayerRandCracker.CrackState.CRACKING) {
if (SeedCracker.expectedItems > 0) {
long rand_val = (long) ((Math.atan2(packet.getVelocityZ(), packet.getVelocityX()) + Math.PI) / (Math.PI * 2) * ((float) (1 << 24)));
long rand_val = (long) ((Math.atan2(packet.getZa(), packet.getXa()) + Math.PI) / (Math.PI * 2) * ((float) (1 << 24)));
long top_bits = rand_val;
short value = (short) (((top_bits >> (24 - 4)) ^ 0x8L )&0xFL);//INSTEAD OF ^0x8L MAYBE DO +math.pi OR SOMETHING ELSE
SeedCracker.bits[20-SeedCracker.expectedItems]=(long)value;//could be improved
Expand Down
48 changes: 24 additions & 24 deletions src/main/java/net/earthcomputer/clientcommands/ClientCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.math.Vec3d;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.phys.Vec3;
import org.slf4j.Logger;

import java.io.IOException;
Expand All @@ -36,11 +36,11 @@ public class ClientCommands implements ClientModInitializer {
private static final Logger LOGGER = LogUtils.getLogger();
public static Path configDir;
private static final Set<String> clientcommandsCommands = new HashSet<>();
public static final Identifier COMMAND_EXECUTION_PACKET_ID = new Identifier("clientcommands", "command_execution");
public static final ResourceLocation COMMAND_EXECUTION_PACKET_ID = new ResourceLocation("clientcommands", "command_execution");
private static final Set<String> COMMANDS_TO_NOT_SEND_TO_SERVER = Set.of("cwe", "cnote"); // could contain private information

public static final boolean SCRAMBLE_WINDOW_TITLE = Util.make(() -> {
String playerUUID = String.valueOf(MinecraftClient.getInstance().getSession().getUuidOrNull());
String playerUUID = String.valueOf(Minecraft.getInstance().getUser().getProfileId());

Set<String> victims = Set.of(
"fa68270b-1071-46c6-ac5c-6c4a0b777a96", // Earthcomputer
Expand All @@ -66,13 +66,13 @@ public void onInitializeClient() {
ClientCommandRegistrationCallback.EVENT.register(ClientCommands::registerCommands);

WorldRenderEvents.AFTER_ENTITIES.register(context -> {
context.matrixStack().push();
context.matrixStack().pushPose();

Vec3d cameraPos = context.camera().getPos();
Vec3 cameraPos = context.camera().getPosition();
context.matrixStack().translate(-cameraPos.x, -cameraPos.y, -cameraPos.z);
RenderQueue.render(RenderQueue.Layer.ON_TOP, Objects.requireNonNull(context.consumers()).getBuffer(RenderQueue.NO_DEPTH_LAYER), context.matrixStack(), context.tickDelta());

context.matrixStack().pop();
context.matrixStack().popPose();
});

configDir = FabricLoader.getInstance().getConfigDir().resolve("clientcommands");
Expand All @@ -97,14 +97,14 @@ public static void sendCommandExecutionToServer(String command) {
String theCommand = reader.readUnquotedString();
if (clientcommandsCommands.contains(theCommand) && !COMMANDS_TO_NOT_SEND_TO_SERVER.contains(theCommand)) {
if (ClientPlayNetworking.canSend(COMMAND_EXECUTION_PACKET_ID)) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeString(command);
FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
buf.writeUtf(command);
ClientPlayNetworking.send(COMMAND_EXECUTION_PACKET_ID, buf);
}
}
}

public static void registerCommands(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
public static void registerCommands(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandBuildContext context) {
Set<String> existingCommands = getCommands(dispatcher);

AuditMixinsCommand.register(dispatcher);
Expand All @@ -113,8 +113,8 @@ public static void registerCommands(CommandDispatcher<FabricClientCommandSource>
NoteCommand.register(dispatcher);
ShrugCommand.register(dispatcher);
FindCommand.register(dispatcher);
FindBlockCommand.register(dispatcher, registryAccess);
FindItemCommand.register(dispatcher, registryAccess);
FindBlockCommand.register(dispatcher, context);
FindItemCommand.register(dispatcher, context);
TaskCommand.register(dispatcher);
CalcCommand.register(dispatcher);
RenderCommand.register(dispatcher);
Expand All @@ -123,34 +123,34 @@ public static void registerCommands(CommandDispatcher<FabricClientCommandSource>
CEnchantCommand.register(dispatcher);
GlowCommand.register(dispatcher);
GetDataCommand.register(dispatcher);
CalcStackCommand.register(dispatcher, registryAccess);
CalcStackCommand.register(dispatcher, context);
GammaCommand.register(dispatcher);
MoteCommand.register(dispatcher);
ChorusCommand.register(dispatcher);
FishCommand.register(dispatcher, registryAccess);
FishCommand.register(dispatcher, context);
SignSearchCommand.register(dispatcher);
GhostBlockCommand.register(dispatcher, registryAccess);
GhostBlockCommand.register(dispatcher, context);
RelogCommand.register(dispatcher);
CGiveCommand.register(dispatcher, registryAccess);
CGiveCommand.register(dispatcher, context);
CPlaySoundCommand.register(dispatcher);
CStopSoundCommand.register(dispatcher);
FovCommand.register(dispatcher);
HotbarCommand.register(dispatcher);
KitCommand.register(dispatcher);
ItemGroupCommand.register(dispatcher, registryAccess);
ItemGroupCommand.register(dispatcher, context);
CParticleCommand.register(dispatcher);
PermissionLevelCommand.register(dispatcher);
CTellRawCommand.register(dispatcher);
CTimeCommand.register(dispatcher);
AliasCommand.register(dispatcher);
AreaStatsCommand.register(dispatcher, registryAccess);
AreaStatsCommand.register(dispatcher, context);
CTeleportCommand.register(dispatcher);
// PlayerInfoCommand.register(dispatcher);
PingCommand.register(dispatcher);
UuidCommand.register(dispatcher);
SnakeCommand.register(dispatcher);
CTitleCommand.register(dispatcher);
TooltipCommand.register(dispatcher, registryAccess);
TooltipCommand.register(dispatcher, context);
TranslateCommand.register(dispatcher);
VarCommand.register(dispatcher);
CFunctionCommand.register(dispatcher);
Expand All @@ -163,7 +163,7 @@ public static void registerCommands(CommandDispatcher<FabricClientCommandSource>

Calendar calendar = Calendar.getInstance();
boolean registerChatCommand = calendar.get(Calendar.MONTH) == Calendar.APRIL && calendar.get(Calendar.DAY_OF_MONTH) == 1;
registerChatCommand |= CHAT_COMMAND_USERS.contains(String.valueOf(MinecraftClient.getInstance().getSession().getUuidOrNull()));
registerChatCommand |= CHAT_COMMAND_USERS.contains(String.valueOf(Minecraft.getInstance().getUser().getProfileId()));
registerChatCommand |= Boolean.getBoolean("clientcommands.debugChatCommand");
if (registerChatCommand) {
ChatCommand.register(dispatcher);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.earthcomputer.clientcommands;

import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.c2s.play.QueryBlockNbtC2SPacket;
import net.minecraft.network.packet.c2s.play.QueryEntityNbtC2SPacket;
import net.minecraft.util.math.BlockPos;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.game.ServerboundBlockEntityTagQuery;
import net.minecraft.network.protocol.game.ServerboundEntityTagQuery;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
Expand All @@ -13,18 +13,18 @@
import java.util.function.Consumer;

public class ClientcommandsDataQueryHandler {
private final ClientPlayNetworkHandler networkHandler;
private final ClientPacketListener packetListener;
private final List<CallbackEntry> callbacks = new ArrayList<>();

public ClientcommandsDataQueryHandler(ClientPlayNetworkHandler networkHandler) {
this.networkHandler = networkHandler;
public ClientcommandsDataQueryHandler(ClientPacketListener packetListener) {
this.packetListener = packetListener;
}

public static ClientcommandsDataQueryHandler get(ClientPlayNetworkHandler networkHandler) {
return ((IClientPlayNetworkHandler) networkHandler).clientcommands_getCCDataQueryHandler();
public static ClientcommandsDataQueryHandler get(ClientPacketListener packetListener) {
return ((IClientPlayNetworkHandler) packetListener).clientcommands_getCCDataQueryHandler();
}

public boolean handleQueryResponse(int transactionId, @Nullable NbtCompound nbt) {
public boolean handleQueryResponse(int transactionId, @Nullable CompoundTag nbt) {
Iterator<CallbackEntry> callbacks = this.callbacks.iterator();
while (callbacks.hasNext()) {
CallbackEntry callback = callbacks.next();
Expand All @@ -40,23 +40,23 @@ public boolean handleQueryResponse(int transactionId, @Nullable NbtCompound nbt)
return false;
}

private int nextQuery(Consumer<@Nullable NbtCompound> callback) {
int transactionId = ++networkHandler.getDataQueryHandler().expectedTransactionId;
private int nextQuery(Consumer<@Nullable CompoundTag> callback) {
int transactionId = ++packetListener.getDebugQueryHandler().transactionId;
callbacks.add(new CallbackEntry(transactionId, callback));
return transactionId;
}

public void queryEntityNbt(int entityNetworkId, Consumer<@Nullable NbtCompound> callback) {
public void queryEntityNbt(int entityNetworkId, Consumer<@Nullable CompoundTag> callback) {
int transactionId = nextQuery(callback);
networkHandler.sendPacket(new QueryEntityNbtC2SPacket(transactionId, entityNetworkId));
packetListener.send(new ServerboundEntityTagQuery(transactionId, entityNetworkId));
}

public void queryBlockNbt(BlockPos pos, Consumer<@Nullable NbtCompound> callback) {
public void queryBlockNbt(BlockPos pos, Consumer<@Nullable CompoundTag> callback) {
int transactionId = nextQuery(callback);
networkHandler.sendPacket(new QueryBlockNbtC2SPacket(transactionId, pos));
packetListener.send(new ServerboundBlockEntityTagQuery(transactionId, pos));
}

private record CallbackEntry(int transactionId, Consumer<@Nullable NbtCompound> callback) {
private record CallbackEntry(int transactionId, Consumer<@Nullable CompoundTag> callback) {
}

public interface IClientPlayNetworkHandler {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/earthcomputer/clientcommands/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import net.earthcomputer.clientcommands.features.EnchantmentCracker;
import net.earthcomputer.clientcommands.features.FishingCracker;
import net.earthcomputer.clientcommands.features.PlayerRandCracker;
import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.Mth;
import net.minecraft.util.StringRepresentable;

import java.util.Locale;

Expand Down Expand Up @@ -35,13 +35,13 @@ public static void setEnchantingPrediction(boolean enchantingPrediction) {
}
}

public enum FishingManipulation implements StringIdentifiable {
public enum FishingManipulation implements StringRepresentable {
OFF,
MANUAL,
AFK;

@Override
public String asString() {
public String getSerializedName() {
return this.name().toLowerCase(Locale.ROOT);
}

Expand Down Expand Up @@ -76,7 +76,7 @@ public static int getMaxEnchantItemThrows() {
return maxEnchantItemThrows;
}
public static void setMaxEnchantItemThrows(int maxEnchantItemThrows) {
Configs.maxEnchantItemThrows = MathHelper.clamp(maxEnchantItemThrows, 0, 1000000);
Configs.maxEnchantItemThrows = Mth.clamp(maxEnchantItemThrows, 0, 1000000);
}

@Config(setter = @Config.Setter("setChorusManipulation"), temporary = true)
Expand All @@ -98,7 +98,7 @@ public static int getMaxChorusItemThrows() {
return maxChorusItemThrows;
}
public static void setMaxChorusItemThrows(int maxChorusItemThrows) {
Configs.maxChorusItemThrows = MathHelper.clamp(maxChorusItemThrows, 0, 1000000);
Configs.maxChorusItemThrows = Mth.clamp(maxChorusItemThrows, 0, 1000000);
}

@Config(temporary = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.earthcomputer.clientcommands;

import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screens.Screen;

import java.util.ArrayList;
import java.util.Iterator;
Expand Down
Loading

0 comments on commit e23b216

Please sign in to comment.