[DEV] Fix up porting patches and configs

This commit is contained in:
2024-06-11 19:51:28 +02:00
parent 68fea1db1e
commit 1ffa879f17
1023 changed files with 38304 additions and 596 deletions

View File

@@ -0,0 +1,53 @@
package com.hypherionmc.craterlib.api.commands;
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
import com.hypherionmc.craterlib.nojang.commands.BridgedCommandSourceStack;
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
import com.hypherionmc.craterlib.utils.TriConsumer;
import com.mojang.brigadier.arguments.ArgumentType;
import lombok.Getter;
import net.minecraft.commands.arguments.GameProfileArgument;
import org.apache.commons.lang3.tuple.Pair;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.function.Consumer;
@Getter
public class CraterCommand {
private final HashMap<String, Pair<ArgumentType<?>, TriConsumer<?, ?, BridgedCommandSourceStack>>> arguments = new LinkedHashMap<>();
private Consumer<BridgedCommandSourceStack> executor;
private final String commandName;
private int permissionLevel = 4;
CraterCommand(String commandName) {
this.commandName = commandName;
}
public static CraterCommand literal(String commandName) {
return new CraterCommand(commandName);
}
public CraterCommand requiresPermission(int perm) {
this.permissionLevel = perm;
return this;
}
public CraterCommand withGameProfileArgument(String key, TriConsumer<BridgedPlayer, List<BridgedGameProfile>, BridgedCommandSourceStack> executor) {
arguments.put(key, Pair.of(GameProfileArgument.gameProfile(), executor));
return this;
}
public CraterCommand executes(Consumer<BridgedCommandSourceStack> ctx) {
executor = ctx;
return this;
}
public boolean hasArguments() {
return !arguments.isEmpty();
}
}

View File

@@ -0,0 +1,14 @@
package com.hypherionmc.craterlib.api.events.client;
import com.hypherionmc.craterlib.core.event.CraterEvent;
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedClientLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@Getter
public class CraterClientTickEvent extends CraterEvent {
private final BridgedClientLevel level;
}

View File

@@ -0,0 +1,21 @@
package com.hypherionmc.craterlib.api.events.client;
import com.hypherionmc.craterlib.core.event.CraterEvent;
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@Getter
public class CraterSinglePlayerEvent extends CraterEvent {
private final BridgedPlayer player;
public static class PlayerLogin extends CraterSinglePlayerEvent {
public PlayerLogin(BridgedPlayer player) {
super(player);
}
}
}

View File

@@ -0,0 +1,16 @@
package com.hypherionmc.craterlib.api.events.client;
import com.hypherionmc.craterlib.core.event.CraterEvent;
import com.hypherionmc.craterlib.nojang.client.BridgedMinecraft;
import com.hypherionmc.craterlib.nojang.client.BridgedOptions;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@Getter
public class LateInitEvent extends CraterEvent {
private final BridgedMinecraft minecraft;
private final BridgedOptions options;
}

View File

@@ -0,0 +1,14 @@
package com.hypherionmc.craterlib.api.events.client;
import com.hypherionmc.craterlib.core.event.CraterEvent;
import com.hypherionmc.craterlib.nojang.realmsclient.dto.BridgedRealmsServer;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@Getter
public class PlayerJoinRealmEvent extends CraterEvent {
private final BridgedRealmsServer server;
}

View File

@@ -0,0 +1,27 @@
package com.hypherionmc.craterlib.api.events.client;
import com.hypherionmc.craterlib.core.event.CraterEvent;
import com.hypherionmc.craterlib.nojang.client.gui.BridgedScreen;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
@Getter
@RequiredArgsConstructor
public class ScreenEvent extends CraterEvent {
private final BridgedScreen screen;
@Getter
public static class Opening extends ScreenEvent {
private final BridgedScreen currentScreen;
@Setter private BridgedScreen newScreen;
public Opening(BridgedScreen currentScreen, BridgedScreen newScreen) {
super(newScreen);
this.currentScreen = currentScreen;
this.newScreen = newScreen;
}
}
}

View File

@@ -0,0 +1,21 @@
package com.hypherionmc.craterlib.api.events.common;
import com.hypherionmc.craterlib.core.event.CraterEvent;
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
import com.hypherionmc.craterlib.utils.ChatUtils;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.kyori.adventure.text.Component;
import net.minecraft.world.damagesource.DamageSource;
@RequiredArgsConstructor
@Getter
public class CraterPlayerDeathEvent extends CraterEvent {
private final BridgedPlayer player;
private final DamageSource damageSource;
public Component getDeathMessage() {
return ChatUtils.mojangToAdventure(damageSource.getLocalizedDeathMessage(player.toMojang()));
}
}

View File

@@ -0,0 +1,34 @@
package com.hypherionmc.craterlib.api.events.server;
import com.hypherionmc.craterlib.core.event.CraterEvent;
import com.hypherionmc.craterlib.nojang.advancements.BridgedAdvancement;
import com.hypherionmc.craterlib.nojang.advancements.BridgedDisplayInfo;
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
import lombok.Getter;
import net.kyori.adventure.text.Component;
import java.util.Optional;
@Getter
public class CraterAdvancementEvent extends CraterEvent {
private final BridgedAdvancement advancement;
private final BridgedPlayer player;
private final Component title;
private final Component description;
public CraterAdvancementEvent(BridgedPlayer player, BridgedAdvancement advancement) {
this.advancement = advancement;
this.player = player;
Optional<BridgedDisplayInfo> displayInfo = advancement.displayInfo();
if (displayInfo.isPresent()) {
this.title = displayInfo.get().displayName();
this.description = displayInfo.get().description();
} else {
this.title = Component.text("Unknown");
this.description = Component.text("Unknown");
}
}
}

View File

@@ -0,0 +1,58 @@
package com.hypherionmc.craterlib.api.events.server;
import com.hypherionmc.craterlib.core.event.CraterEvent;
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
import com.hypherionmc.craterlib.utils.ChatUtils;
import com.mojang.brigadier.ParseResults;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.context.StringRange;
import lombok.Getter;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.ComponentArgument;
import net.minecraft.world.entity.player.Player;
import org.jetbrains.annotations.Nullable;
@Getter
public class CraterCommandEvent extends CraterEvent {
private final ParseResults<CommandSourceStack> parseResults;
@Setter private Throwable exception;
private final String command;
private CraterCommandEvent(ParseResults<CommandSourceStack> parseResults, String command) {
this.parseResults = parseResults;
this.command = command;
}
public static CraterCommandEvent of(ParseResults<CommandSourceStack> stack, String command) {
return new CraterCommandEvent(stack, command);
}
public String getCommandString() {
return parseResults.getReader().getString();
}
@Nullable
public BridgedPlayer getPlayer() {
try {
Player p = parseResults.getContext().getLastChild().getSource().getPlayer();
if (p != null)
return BridgedPlayer.of(p);
} catch (Exception ignored) {}
return null;
}
public String getTarget() {
CommandContext<CommandSourceStack> context = parseResults.getContext().build(parseResults.getReader().getString());
StringRange selector_range = parseResults.getContext().getArguments().get("targets").getRange();
return context.getInput().substring(selector_range.getStart(), selector_range.getEnd());
}
public Component getMessage() {
return ChatUtils.mojangToAdventure(ComponentArgument.getComponent(parseResults.getContext().build(parseResults.getReader().getString()), "message"));
}
}

View File

@@ -0,0 +1,30 @@
package com.hypherionmc.craterlib.api.events.server;
import com.hypherionmc.craterlib.core.event.CraterEvent;
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@Getter
public class CraterPlayerEvent extends CraterEvent {
private final BridgedPlayer player;
public static class PlayerLoggedIn extends CraterPlayerEvent {
public PlayerLoggedIn(BridgedPlayer player) {
super(player);
}
}
public static class PlayerLoggedOut extends CraterPlayerEvent {
public PlayerLoggedOut(BridgedPlayer player) {
super(player);
}
}
}

View File

@@ -0,0 +1,15 @@
package com.hypherionmc.craterlib.api.events.server;
import com.hypherionmc.craterlib.api.commands.CraterCommand;
import com.hypherionmc.craterlib.core.event.CraterEvent;
import com.hypherionmc.craterlib.nojang.commands.CommandsRegistry;
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class CraterRegisterCommandEvent extends CraterEvent {
public void registerCommand(CraterCommand cmd) {
CommandsRegistry.INSTANCE.registerCommand(cmd);
}
}

View File

@@ -0,0 +1,25 @@
package com.hypherionmc.craterlib.api.events.server;
import com.hypherionmc.craterlib.core.event.CraterEvent;
import com.hypherionmc.craterlib.core.event.annot.Cancellable;
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
import lombok.Getter;
import lombok.Setter;
import net.kyori.adventure.text.Component;
@Cancellable
@Getter
public class CraterServerChatEvent extends CraterEvent {
public final String message, username;
public final BridgedPlayer player;
@Setter private Component component;
public CraterServerChatEvent(BridgedPlayer player, String message, Component component) {
this.message = message;
this.player = player;
this.username = player.getGameProfile().getName();
this.component = component;
}
}

View File

@@ -0,0 +1,34 @@
package com.hypherionmc.craterlib.api.events.server;
import com.hypherionmc.craterlib.core.event.CraterEvent;
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
public class CraterServerLifecycleEvent extends CraterEvent {
@RequiredArgsConstructor
@Getter
public static class Starting extends CraterServerLifecycleEvent {
private final BridgedMinecraftServer server;
}
@RequiredArgsConstructor
@Getter
public static class Started extends CraterServerLifecycleEvent {
private final BridgedMinecraftServer server;
}
@RequiredArgsConstructor
@Getter
public static class Stopping extends CraterServerLifecycleEvent {
private final BridgedMinecraftServer server;
}
@RequiredArgsConstructor
@Getter
public static class Stopped extends CraterServerLifecycleEvent {
private final BridgedMinecraftServer server;
}
}

View File

@@ -0,0 +1,20 @@
package com.hypherionmc.craterlib.api.events.server;
import com.hypherionmc.craterlib.core.event.CraterEvent;
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.kyori.adventure.text.Component;
import java.util.function.Function;
@RequiredArgsConstructor
@Getter
public class MessageBroadcastEvent extends CraterEvent {
private final Component component;
private final Function<BridgedPlayer, Component> function;
private final boolean bl;
private final String threadName;
}

View File

@@ -0,0 +1,20 @@
package com.hypherionmc.craterlib.api.events.server;
import com.hypherionmc.craterlib.core.event.CraterEvent;
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import java.net.SocketAddress;
@RequiredArgsConstructor
@Getter
public class PlayerPreLoginEvent extends CraterEvent {
private final SocketAddress address;
private final BridgedGameProfile gameProfile;
@Setter private Component message;
}

View File

@@ -0,0 +1,28 @@
package com.hypherionmc.craterlib.api.networking;
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
import java.util.List;
/**
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
*/
public interface CraterNetworkHandler {
<T> void sendToServer(T packet);
<T> void sendToServer(T packet, boolean ignoreCheck);
<T> void sendToClient(T packet, BridgedPlayer player);
default <T> void sendToClients(T packet, List<BridgedPlayer> players) {
for (BridgedPlayer player : players) {
sendToClient(packet, player);
}
}
default <T> void sendToAllClients(T packet, BridgedMinecraftServer server) {
sendToClients(packet, server.getPlayers());
}
}