Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to Mojmap #596

Merged
merged 9 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
102 changes: 77 additions & 25 deletions src/main/java/net/earthcomputer/clientcommands/ClientCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,72 @@
import com.mojang.logging.LogUtils;
import dev.xpple.betterconfig.api.ModConfigBuilder;
import io.netty.buffer.Unpooled;
import net.earthcomputer.clientcommands.command.*;
import net.earthcomputer.clientcommands.command.AliasCommand;
import net.earthcomputer.clientcommands.command.AreaStatsCommand;
import net.earthcomputer.clientcommands.command.AuditMixinsCommand;
import net.earthcomputer.clientcommands.command.BookCommand;
import net.earthcomputer.clientcommands.command.CEnchantCommand;
import net.earthcomputer.clientcommands.command.CFunctionCommand;
import net.earthcomputer.clientcommands.command.CGiveCommand;
import net.earthcomputer.clientcommands.command.CParticleCommand;
import net.earthcomputer.clientcommands.command.CPlaySoundCommand;
import net.earthcomputer.clientcommands.command.CStopSoundCommand;
import net.earthcomputer.clientcommands.command.CTeleportCommand;
import net.earthcomputer.clientcommands.command.CTellRawCommand;
import net.earthcomputer.clientcommands.command.CTimeCommand;
import net.earthcomputer.clientcommands.command.CTitleCommand;
import net.earthcomputer.clientcommands.command.CalcCommand;
import net.earthcomputer.clientcommands.command.CalcStackCommand;
import net.earthcomputer.clientcommands.command.ChatCommand;
import net.earthcomputer.clientcommands.command.ChorusCommand;
import net.earthcomputer.clientcommands.command.CrackRNGCommand;
import net.earthcomputer.clientcommands.command.FindBlockCommand;
import net.earthcomputer.clientcommands.command.FindCommand;
import net.earthcomputer.clientcommands.command.FindItemCommand;
import net.earthcomputer.clientcommands.command.FishCommand;
import net.earthcomputer.clientcommands.command.FovCommand;
import net.earthcomputer.clientcommands.command.GammaCommand;
import net.earthcomputer.clientcommands.command.GetDataCommand;
import net.earthcomputer.clientcommands.command.GhostBlockCommand;
import net.earthcomputer.clientcommands.command.GlowCommand;
import net.earthcomputer.clientcommands.command.HotbarCommand;
import net.earthcomputer.clientcommands.command.ItemGroupCommand;
import net.earthcomputer.clientcommands.command.KitCommand;
import net.earthcomputer.clientcommands.command.LookCommand;
import net.earthcomputer.clientcommands.command.MoteCommand;
import net.earthcomputer.clientcommands.command.NoteCommand;
import net.earthcomputer.clientcommands.command.PermissionLevelCommand;
import net.earthcomputer.clientcommands.command.PingCommand;
import net.earthcomputer.clientcommands.command.PluginsCommand;
import net.earthcomputer.clientcommands.command.PosCommand;
import net.earthcomputer.clientcommands.command.RelogCommand;
import net.earthcomputer.clientcommands.command.RenderCommand;
import net.earthcomputer.clientcommands.command.ShrugCommand;
import net.earthcomputer.clientcommands.command.SignSearchCommand;
import net.earthcomputer.clientcommands.command.SnakeCommand;
import net.earthcomputer.clientcommands.command.StartupCommand;
import net.earthcomputer.clientcommands.command.TaskCommand;
import net.earthcomputer.clientcommands.command.TooltipCommand;
import net.earthcomputer.clientcommands.command.TranslateCommand;
import net.earthcomputer.clientcommands.command.UsageTreeCommand;
import net.earthcomputer.clientcommands.command.UuidCommand;
import net.earthcomputer.clientcommands.command.VarCommand;
import net.earthcomputer.clientcommands.command.WeatherCommand;
import net.earthcomputer.clientcommands.command.WhisperEncryptedCommand;
import net.earthcomputer.clientcommands.command.WikiCommand;
import net.earthcomputer.clientcommands.render.RenderQueue;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
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 +88,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 +118,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 +149,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 +165,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 +175,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 +215,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
Loading
Loading