[MAJOR] Implement new NOJANG modding system
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -12,7 +12,7 @@
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="temurin-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@@ -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.mojang.brigadier.arguments.ArgumentType;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.commands.arguments.GameProfileArgument;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.logging.log4j.util.TriConsumer;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.event.client;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Cross Modloader Client Tick Event.
|
||||
*/
|
||||
public class CraterClientTickEvent extends CraterEvent {
|
||||
|
||||
private final ClientLevel level;
|
||||
|
||||
public CraterClientTickEvent(ClientLevel level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public ClientLevel getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.event.client;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public class CraterSinglePlayerEvent extends CraterEvent {
|
||||
|
||||
private final Player player;
|
||||
|
||||
public CraterSinglePlayerEvent(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class PlayerLogin extends CraterSinglePlayerEvent {
|
||||
|
||||
public PlayerLogin(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.event.client;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Options;
|
||||
|
||||
public class LateInitEvent extends CraterEvent {
|
||||
|
||||
private final Minecraft minecraft;
|
||||
private final Options options;
|
||||
|
||||
public LateInitEvent(Minecraft minecraft, Options options) {
|
||||
this.minecraft = minecraft;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
public Minecraft getMinecraft() {
|
||||
return minecraft;
|
||||
}
|
||||
|
||||
public Options getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.event.client;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import com.mojang.realmsclient.dto.RealmsServer;
|
||||
|
||||
public class PlayerJoinRealmEvent extends CraterEvent {
|
||||
|
||||
private final RealmsServer server;
|
||||
|
||||
public PlayerJoinRealmEvent(RealmsServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public RealmsServer getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.event.client;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ScreenEvent extends CraterEvent {
|
||||
|
||||
private final Screen screen;
|
||||
|
||||
protected ScreenEvent(Screen screen) {
|
||||
this.screen = Objects.requireNonNull(screen);
|
||||
}
|
||||
|
||||
public Screen getScreen() {
|
||||
return screen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class Opening extends ScreenEvent {
|
||||
|
||||
private final Screen currentScreen;
|
||||
private Screen newScreen;
|
||||
|
||||
public Opening(Screen currentScreen, Screen newScreen) {
|
||||
super(newScreen);
|
||||
this.currentScreen = currentScreen;
|
||||
this.newScreen = newScreen;
|
||||
}
|
||||
|
||||
public Screen getCurrentScreen() {
|
||||
return currentScreen;
|
||||
}
|
||||
|
||||
public Screen getNewScreen() {
|
||||
return newScreen;
|
||||
}
|
||||
|
||||
public void setNewScreen(Screen newScreen) {
|
||||
this.newScreen = newScreen;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.event.common;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
||||
public class CraterLivingDeathEvent extends CraterEvent {
|
||||
|
||||
private final DamageSource damageSource;
|
||||
private final LivingEntity entity;
|
||||
|
||||
public CraterLivingDeathEvent(LivingEntity entity, DamageSource source) {
|
||||
this.entity = entity;
|
||||
this.damageSource = source;
|
||||
}
|
||||
|
||||
public LivingEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public DamageSource getDamageSource() {
|
||||
return damageSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.event.server;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.DisplayInfo;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class CraterAdvancementEvent extends CraterEvent {
|
||||
|
||||
private final Advancement advancement;
|
||||
private final Player player;
|
||||
private final Component title;
|
||||
private final Component description;
|
||||
|
||||
public CraterAdvancementEvent(Player player, Advancement advancement) {
|
||||
this.player = player;
|
||||
this.advancement = advancement;
|
||||
|
||||
Optional<DisplayInfo> displayInfo = advancement.display();
|
||||
|
||||
if (displayInfo.isPresent()) {
|
||||
this.title = displayInfo.get().getTitle();
|
||||
this.description = displayInfo.get().getDescription();
|
||||
} else {
|
||||
this.title = Component.literal("Unknown");
|
||||
this.description = Component.literal("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
public Advancement getAdvancement() {
|
||||
return advancement;
|
||||
}
|
||||
|
||||
public Component getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public Component getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.event.server;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import com.mojang.brigadier.ParseResults;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
public class CraterCommandEvent extends CraterEvent {
|
||||
|
||||
private ParseResults<CommandSourceStack> parseResults;
|
||||
private Throwable exception;
|
||||
private String command;
|
||||
|
||||
public CraterCommandEvent(ParseResults<CommandSourceStack> parseResults, String command) {
|
||||
this.parseResults = parseResults;
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public ParseResults<CommandSourceStack> getParseResults() {
|
||||
return parseResults;
|
||||
}
|
||||
|
||||
public void setParseResults(ParseResults<CommandSourceStack> parseResults) {
|
||||
this.parseResults = parseResults;
|
||||
}
|
||||
|
||||
public Throwable getException() {
|
||||
return exception;
|
||||
}
|
||||
|
||||
public void setException(Throwable exception) {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public void setCommand(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,38 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.event.server;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class CraterPlayerEvent extends CraterEvent {
|
||||
|
||||
private final ServerPlayer player;
|
||||
|
||||
public CraterPlayerEvent(ServerPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public ServerPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class PlayerLoggedIn extends CraterPlayerEvent {
|
||||
|
||||
public PlayerLoggedIn(ServerPlayer player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class PlayerLoggedOut extends CraterPlayerEvent {
|
||||
|
||||
public PlayerLoggedOut(ServerPlayer player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.event.server;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
public class CraterRegisterCommandEvent extends CraterEvent {
|
||||
|
||||
private final CommandDispatcher<CommandSourceStack> dispatcher;
|
||||
|
||||
public CraterRegisterCommandEvent(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
this.dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public CommandDispatcher<CommandSourceStack> getDispatcher() {
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.event.server;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class CraterServerChatEvent extends CraterEvent {
|
||||
|
||||
private final String message, username;
|
||||
private final ServerPlayer player;
|
||||
private Component component;
|
||||
|
||||
public CraterServerChatEvent(ServerPlayer player, String message, Component component) {
|
||||
this.message = message;
|
||||
this.player = player;
|
||||
this.username = player.getGameProfile().getName();
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
public Component getComponent() {
|
||||
return component;
|
||||
}
|
||||
|
||||
public void setComponent(Component component) {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public ServerPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.event.server;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class CraterServerLifecycleEvent extends CraterEvent {
|
||||
|
||||
public CraterServerLifecycleEvent() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class Starting extends CraterServerLifecycleEvent {
|
||||
|
||||
private final MinecraftServer server;
|
||||
|
||||
public Starting(MinecraftServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public MinecraftServer getServer() {
|
||||
return server;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Started extends CraterServerLifecycleEvent {
|
||||
|
||||
public Started() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Stopping extends CraterServerLifecycleEvent {
|
||||
|
||||
public Stopping() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Stopped extends CraterServerLifecycleEvent {
|
||||
|
||||
public Stopped() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.event.server;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class MessageBroadcastEvent extends CraterEvent {
|
||||
|
||||
private final Component component;
|
||||
private final Function<ServerPlayer, Component> function;
|
||||
private final boolean bl;
|
||||
private final String threadName;
|
||||
|
||||
public MessageBroadcastEvent(Component component, Function<ServerPlayer, Component> function, boolean bl, String threadName) {
|
||||
this.component = component;
|
||||
this.function = function;
|
||||
this.bl = bl;
|
||||
this.threadName = threadName;
|
||||
}
|
||||
|
||||
public Component getComponent() {
|
||||
return component;
|
||||
}
|
||||
|
||||
public boolean isBl() {
|
||||
return bl;
|
||||
}
|
||||
|
||||
public Function<ServerPlayer, Component> getFunction() {
|
||||
return function;
|
||||
}
|
||||
|
||||
public String getThreadName() {
|
||||
return threadName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
package com.hypherionmc.craterlib.api.event.server;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
public class PlayerPreLoginEvent extends CraterEvent {
|
||||
|
||||
private final SocketAddress address;
|
||||
private final GameProfile gameProfile;
|
||||
private Component message;
|
||||
|
||||
public PlayerPreLoginEvent(SocketAddress address, GameProfile profile) {
|
||||
this.address = address;
|
||||
this.gameProfile = profile;
|
||||
}
|
||||
|
||||
public Component getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(Component message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public GameProfile getGameProfile() {
|
||||
return gameProfile;
|
||||
}
|
||||
|
||||
public SocketAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
|
||||
}
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -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;
|
||||
|
||||
}
|
@@ -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;
|
||||
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package com.hypherionmc.craterlib.api.events.client;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
|
||||
// TODO NOJANG
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class ScreenEvent extends CraterEvent {
|
||||
|
||||
private final Screen screen;
|
||||
|
||||
@Getter
|
||||
public static class Opening extends ScreenEvent {
|
||||
|
||||
private final Screen currentScreen;
|
||||
@Setter private Screen newScreen;
|
||||
|
||||
public Opening(Screen currentScreen, Screen newScreen) {
|
||||
super(newScreen);
|
||||
this.currentScreen = currentScreen;
|
||||
this.newScreen = newScreen;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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()));
|
||||
}
|
||||
}
|
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
@@ -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"));
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
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.RequiredArgsConstructor;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
@@ -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;
|
||||
|
||||
}
|
@@ -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;
|
||||
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
package com.hypherionmc.craterlib.api.networking;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -14,15 +14,15 @@ public interface CraterNetworkHandler {
|
||||
|
||||
<T> void sendToServer(T packet, boolean ignoreCheck);
|
||||
|
||||
<T> void sendToClient(T packet, ServerPlayer player);
|
||||
<T> void sendToClient(T packet, BridgedPlayer player);
|
||||
|
||||
default <T> void sendToClients(T packet, List<ServerPlayer> players) {
|
||||
for (ServerPlayer player : players) {
|
||||
default <T> void sendToClients(T packet, List<BridgedPlayer> players) {
|
||||
for (BridgedPlayer player : players) {
|
||||
sendToClient(packet, player);
|
||||
}
|
||||
}
|
||||
|
||||
default <T> void sendToAllClients(T packet, MinecraftServer server) {
|
||||
sendToClients(packet, server.getPlayerList().getPlayers());
|
||||
default <T> void sendToAllClients(T packet, BridgedMinecraftServer server) {
|
||||
sendToClients(packet, server.getPlayers());
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package com.hypherionmc.craterlib.core.config;
|
||||
|
||||
import com.hypherionmc.craterlib.CraterConstants;
|
||||
import lombok.Getter;
|
||||
import me.hypherionmc.moonconfig.core.file.FileWatcher;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@@ -16,6 +17,7 @@ public final class ConfigController implements Serializable {
|
||||
/**
|
||||
* Cache of registered configs
|
||||
*/
|
||||
@Getter
|
||||
private static final HashMap<Object, FileWatcher> monitoredConfigs = new HashMap<>();
|
||||
|
||||
/**
|
||||
@@ -44,7 +46,4 @@ public final class ConfigController implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public static HashMap<Object, FileWatcher> getMonitoredConfigs() {
|
||||
return monitoredConfigs;
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,15 @@
|
||||
package com.hypherionmc.craterlib.core.event;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.annot.Cancellable;
|
||||
import com.hypherionmc.craterlib.core.event.exception.CraterEventCancellationException;
|
||||
|
||||
public abstract class CraterEvent {
|
||||
public class CraterEvent {
|
||||
|
||||
private boolean canceled = false;
|
||||
|
||||
public abstract boolean canCancel();
|
||||
private boolean canCancel() {
|
||||
return this.getClass().isAnnotationPresent(Cancellable.class);
|
||||
}
|
||||
|
||||
public void cancelEvent() {
|
||||
try {
|
||||
@@ -24,4 +27,4 @@ public abstract class CraterEvent {
|
||||
return this.canceled;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -238,4 +238,4 @@ public final class CraterEventBus {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -10,4 +10,4 @@ public class CraterEventPriority {
|
||||
public static final int HIGHER = 2;
|
||||
public static final int HIGHEST = 3;
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.hypherionmc.craterlib.core.event.annot;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Cancellable {
|
||||
}
|
@@ -8,4 +8,4 @@ import java.lang.annotation.RetentionPolicy;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CraterEventListener {
|
||||
int priority() default CraterEventPriority.NORMAL;
|
||||
}
|
||||
}
|
@@ -6,4 +6,4 @@ public class CraterEventCancellationException extends Exception {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -28,7 +28,7 @@ public interface CraterNetworkHandler {
|
||||
}
|
||||
|
||||
default void sendToAll(CraterPacket<?> packet) {
|
||||
CommonPlatform.INSTANCE.getMCServer().getPlayerList().broadcastAll(this.toClientBound(packet));
|
||||
CommonPlatform.INSTANCE.getMCServer().toMojang().getPlayerList().broadcastAll(this.toClientBound(packet));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package com.hypherionmc.craterlib.core.networking;
|
||||
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
@@ -30,7 +30,7 @@ public class CraterPacketNetwork {
|
||||
return delayedHandler;
|
||||
}
|
||||
|
||||
public static <T> PacketRegistrar registerPacket(ResourceLocation id, Class<T> messageType, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
||||
public static <T> PacketRegistrar registerPacket(ResourceIdentifier id, Class<T> messageType, BiConsumer<T, BridgedFriendlyByteBuf> encoder, Function<BridgedFriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
||||
if (INSTANCE != null) {
|
||||
return INSTANCE.packetRegistry.registerPacket(id, messageType, encoder, decoder, handler);
|
||||
} else {
|
||||
@@ -41,4 +41,4 @@ public class CraterPacketNetwork {
|
||||
public PacketRegistry getPacketRegistry() {
|
||||
return packetRegistry;
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,8 +3,8 @@ package com.hypherionmc.craterlib.core.networking;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -25,7 +25,7 @@ public class DeferredPacketRegistrar implements PacketRegistrar {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> PacketRegistrar registerPacket(ResourceLocation packetIdentifier, Class<T> messageType, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
||||
public <T> PacketRegistrar registerPacket(ResourceIdentifier packetIdentifier, Class<T> messageType, BiConsumer<T, BridgedFriendlyByteBuf> encoder, Function<BridgedFriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
||||
PacketHolder<T> container = new PacketHolder<>(packetIdentifier, messageType, encoder, decoder, handler);
|
||||
QUEUED_PACKET_MAP.put(messageType, container);
|
||||
return this;
|
||||
@@ -38,4 +38,4 @@ public class DeferredPacketRegistrar implements PacketRegistrar {
|
||||
QUEUED_PACKET_MAP.forEach((aClass, container) -> packetRegistration.registerPacket(container));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,8 +2,8 @@ package com.hypherionmc.craterlib.core.networking;
|
||||
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
@@ -16,6 +16,6 @@ public interface PacketRegistrar {
|
||||
|
||||
PacketSide side();
|
||||
|
||||
<T> PacketRegistrar registerPacket(ResourceLocation id, Class<T> messageType, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler);
|
||||
<T> PacketRegistrar registerPacket(ResourceIdentifier id, Class<T> messageType, BiConsumer<T, BridgedFriendlyByteBuf> encoder, Function<BridgedFriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler);
|
||||
|
||||
}
|
||||
}
|
@@ -4,8 +4,8 @@ import com.hypherionmc.craterlib.api.networking.CraterNetworkHandler;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -26,7 +26,7 @@ public abstract class PacketRegistry implements CraterNetworkHandler, PacketRegi
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
public <T> PacketRegistrar registerPacket(ResourceLocation id, Class<T> messageType, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
||||
public <T> PacketRegistrar registerPacket(ResourceIdentifier id, Class<T> messageType, BiConsumer<T, BridgedFriendlyByteBuf> encoder, Function<BridgedFriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
||||
PacketHolder<T> holder = new PacketHolder<>(id, messageType, encoder, decoder, handler);
|
||||
PACKET_MAP.put(messageType, holder);
|
||||
registerPacket(holder);
|
||||
@@ -38,4 +38,4 @@ public abstract class PacketRegistry implements CraterNetworkHandler, PacketRegi
|
||||
}
|
||||
|
||||
protected abstract <T> void registerPacket(PacketHolder<T> packetHolder);
|
||||
}
|
||||
}
|
@@ -1,15 +1,15 @@
|
||||
package com.hypherionmc.craterlib.core.networking.data;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
*/
|
||||
public record PacketContext<T>(@Nullable Player sender, T message, PacketSide side) {
|
||||
public record PacketContext<T>(@Nullable BridgedPlayer sender, T message, PacketSide side) {
|
||||
|
||||
public PacketContext(T message, PacketSide side) {
|
||||
this(null, message, side);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
package com.hypherionmc.craterlib.core.networking.data;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
@@ -10,9 +10,9 @@ import java.util.function.Function;
|
||||
/**
|
||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
*/
|
||||
public record PacketHolder<T>(ResourceLocation packetId,
|
||||
public record PacketHolder<T>(ResourceIdentifier packetId,
|
||||
Class<T> messageType,
|
||||
BiConsumer<T, FriendlyByteBuf> encoder,
|
||||
Function<FriendlyByteBuf, T> decoder,
|
||||
BiConsumer<T, BridgedFriendlyByteBuf> encoder,
|
||||
Function<BridgedFriendlyByteBuf, T> decoder,
|
||||
Consumer<PacketContext<T>> handler) {
|
||||
}
|
||||
}
|
@@ -10,4 +10,4 @@ public enum PacketSide {
|
||||
|
||||
return CLIENT;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,23 +1,23 @@
|
||||
package com.hypherionmc.craterlib.core.platform;
|
||||
|
||||
import com.hypherionmc.craterlib.util.ServiceUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import com.hypherionmc.craterlib.nojang.client.BridgedMinecraft;
|
||||
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedClientLevel;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.InternalServiceUtil;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
public interface ClientPlatform {
|
||||
|
||||
public final ClientPlatform INSTANCE = ServiceUtil.load(ClientPlatform.class);
|
||||
public final ClientPlatform INSTANCE = InternalServiceUtil.load(ClientPlatform.class);
|
||||
|
||||
Minecraft getClientInstance();
|
||||
BridgedMinecraft getClientInstance();
|
||||
|
||||
Player getClientPlayer();
|
||||
BridgedPlayer getClientPlayer();
|
||||
|
||||
Level getClientLevel();
|
||||
BridgedClientLevel getClientLevel();
|
||||
|
||||
Connection getClientConnection();
|
||||
}
|
||||
}
|
@@ -1,22 +1,15 @@
|
||||
package com.hypherionmc.craterlib.core.platform;
|
||||
|
||||
import com.hypherionmc.craterlib.core.network.CraterNetworkHandler;
|
||||
import com.hypherionmc.craterlib.util.ServiceUtil;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
||||
import com.hypherionmc.craterlib.utils.InternalServiceUtil;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
public interface CommonPlatform {
|
||||
|
||||
public CommonPlatform INSTANCE = ServiceUtil.load(CommonPlatform.class);
|
||||
public CommonPlatform INSTANCE = InternalServiceUtil.load(CommonPlatform.class);
|
||||
|
||||
default CraterNetworkHandler createPacketHandler(String modid) {
|
||||
return this.createPacketHandler(modid, true, true);
|
||||
}
|
||||
BridgedMinecraftServer getMCServer();
|
||||
|
||||
CraterNetworkHandler createPacketHandler(String modid, boolean requiredClient, boolean requiredServer);
|
||||
|
||||
MinecraftServer getMCServer();
|
||||
|
||||
}
|
||||
}
|
@@ -15,4 +15,4 @@ public enum Environment {
|
||||
public boolean isServer() {
|
||||
return this == SERVER;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
package com.hypherionmc.craterlib.core.platform;
|
||||
|
||||
import com.hypherionmc.craterlib.util.ServiceUtil;
|
||||
import com.hypherionmc.craterlib.utils.InternalServiceUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.io.File;
|
||||
*/
|
||||
public interface ModloaderEnvironment {
|
||||
|
||||
public final ModloaderEnvironment INSTANCE = ServiceUtil.load(ModloaderEnvironment.class);
|
||||
public final ModloaderEnvironment INSTANCE = InternalServiceUtil.load(ModloaderEnvironment.class);
|
||||
|
||||
boolean isFabric();
|
||||
|
||||
@@ -29,4 +29,4 @@ public interface ModloaderEnvironment {
|
||||
boolean isDevEnv();
|
||||
|
||||
int getModCount();
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
package com.hypherionmc.craterlib.mixin.events;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.hypherionmc.craterlib.api.event.server.CraterCommandEvent;
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterCommandEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.mojang.brigadier.ParseResults;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
@@ -21,7 +21,7 @@ public class CommandMixin {
|
||||
), cancellable = true
|
||||
)
|
||||
private void injectCommandEvent(ParseResults<CommandSourceStack> stackParseResults, String command, CallbackInfo ci) {
|
||||
CraterCommandEvent commandEvent = new CraterCommandEvent(stackParseResults, command);
|
||||
CraterCommandEvent commandEvent = CraterCommandEvent.of(stackParseResults, command);
|
||||
CraterEventBus.INSTANCE.postEvent(commandEvent);
|
||||
if (commandEvent.wasCancelled()) {
|
||||
ci.cancel();
|
||||
|
@@ -1,23 +0,0 @@
|
||||
package com.hypherionmc.craterlib.mixin.events;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.common.CraterLivingDeathEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
public class LivingEntityMixin {
|
||||
|
||||
@Inject(method = "die", at = @At("HEAD"), cancellable = true)
|
||||
private void injectPlayerDeathEvent(DamageSource damageSource, CallbackInfo ci) {
|
||||
CraterLivingDeathEvent event = new CraterLivingDeathEvent(((LivingEntity) (Object) this), damageSource);
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
if (event.wasCancelled())
|
||||
ci.cancel();
|
||||
}
|
||||
|
||||
}
|
@@ -1,7 +1,9 @@
|
||||
package com.hypherionmc.craterlib.mixin.events;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.server.CraterAdvancementEvent;
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterAdvancementEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.advancements.BridgedAdvancement;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.server.PlayerAdvancements;
|
||||
@@ -20,12 +22,10 @@ public class PlayerAdvancementsMixin {
|
||||
|
||||
@Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V", shift = At.Shift.AFTER))
|
||||
private void injectAdvancementEvent(AdvancementHolder advancementHolder, String string, CallbackInfoReturnable<Boolean> cir) {
|
||||
CraterAdvancementEvent event = new CraterAdvancementEvent(this.player, advancementHolder.value());
|
||||
|
||||
Advancement advancement = advancementHolder.value();
|
||||
|
||||
if (advancement.display().isPresent() && advancement.display().get().shouldAnnounceChat()) {
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterAdvancementEvent(BridgedPlayer.of(this.player), BridgedAdvancement.of(advancementHolder.value())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,12 @@
|
||||
package com.hypherionmc.craterlib.mixin.events;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.server.CraterPlayerEvent;
|
||||
import com.hypherionmc.craterlib.api.event.server.MessageBroadcastEvent;
|
||||
import com.hypherionmc.craterlib.api.event.server.PlayerPreLoginEvent;
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterPlayerEvent;
|
||||
import com.hypherionmc.craterlib.api.events.server.MessageBroadcastEvent;
|
||||
import com.hypherionmc.craterlib.api.events.server.PlayerPreLoginEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -25,28 +28,26 @@ public class PlayerListMixin {
|
||||
@Inject(method = "broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Ljava/util/function/Function;Z)V", at = @At("HEAD"))
|
||||
private void injectBroadcastEvent(Component component, Function<ServerPlayer, Component> function, boolean bl, CallbackInfo ci) {
|
||||
String thread = Thread.currentThread().getStackTrace()[3].getClassName();
|
||||
MessageBroadcastEvent event = new MessageBroadcastEvent(component, function, bl, thread);
|
||||
MessageBroadcastEvent event = new MessageBroadcastEvent(ChatUtils.mojangToAdventure(component), (f) -> ChatUtils.mojangToAdventure(component), bl, thread);
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
}
|
||||
|
||||
@Inject(method = "placeNewPlayer", at = @At("TAIL"))
|
||||
private void injectPlayerLoginEvent(Connection connection, ServerPlayer serverPlayer, CommonListenerCookie commonListenerCookie, CallbackInfo ci) {
|
||||
CraterPlayerEvent.PlayerLoggedIn loggedIn = new CraterPlayerEvent.PlayerLoggedIn(serverPlayer);
|
||||
CraterEventBus.INSTANCE.postEvent(loggedIn);
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer)));
|
||||
}
|
||||
|
||||
@Inject(method = "remove", at = @At("HEAD"))
|
||||
private void injectPlayerLogoutEvent(ServerPlayer player, CallbackInfo ci) {
|
||||
CraterPlayerEvent.PlayerLoggedOut loggedOut = new CraterPlayerEvent.PlayerLoggedOut(player);
|
||||
CraterEventBus.INSTANCE.postEvent(loggedOut);
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(player)));
|
||||
}
|
||||
|
||||
@Inject(method = "canPlayerLogin", at = @At("HEAD"), cancellable = true)
|
||||
private void injectPreLoginEvent(SocketAddress address, GameProfile gameProfile, CallbackInfoReturnable<Component> cir) {
|
||||
PlayerPreLoginEvent event = new PlayerPreLoginEvent(address, gameProfile);
|
||||
PlayerPreLoginEvent event = new PlayerPreLoginEvent(address, BridgedGameProfile.of(gameProfile));
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
if (event.getMessage() != null) {
|
||||
cir.setReturnValue(event.getMessage());
|
||||
cir.setReturnValue(ChatUtils.adventureToMojang(event.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,8 @@
|
||||
package com.hypherionmc.craterlib.mixin.events;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.common.CraterLivingDeathEvent;
|
||||
import com.hypherionmc.craterlib.api.events.common.CraterPlayerDeathEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -12,12 +13,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(Player.class)
|
||||
public class PlayerMixin {
|
||||
|
||||
@Inject(method = "die", at = @At("HEAD"), cancellable = true)
|
||||
@Inject(method = "die", at = @At("HEAD"))
|
||||
private void injectPlayerDeathEvent(DamageSource damageSource, CallbackInfo ci) {
|
||||
CraterLivingDeathEvent event = new CraterLivingDeathEvent(((Player) (Object) this), damageSource);
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
if (event.wasCancelled())
|
||||
ci.cancel();
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerDeathEvent(BridgedPlayer.of(((Player) (Object) this)), damageSource));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,8 @@
|
||||
package com.hypherionmc.craterlib.mixin.events;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.common.CraterLivingDeathEvent;
|
||||
import com.hypherionmc.craterlib.api.events.common.CraterPlayerDeathEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -12,12 +13,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(ServerPlayer.class)
|
||||
public class ServerPlayerMixin {
|
||||
|
||||
@Inject(method = "die", at = @At("HEAD"), cancellable = true)
|
||||
@Inject(method = "die", at = @At("HEAD"))
|
||||
private void injectPlayerDeathEvent(DamageSource damageSource, CallbackInfo ci) {
|
||||
CraterLivingDeathEvent event = new CraterLivingDeathEvent(((ServerPlayer) (Object) this), damageSource);
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
if (event.wasCancelled())
|
||||
ci.cancel();
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerDeathEvent(BridgedPlayer.of(((ServerPlayer) (Object) this)), damageSource));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,8 @@
|
||||
package com.hypherionmc.craterlib.mixin.events.client;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.client.CraterSinglePlayerEvent;
|
||||
import com.hypherionmc.craterlib.api.events.client.CraterSinglePlayerEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
@@ -16,7 +17,7 @@ public class ClientLevelMixin {
|
||||
@Inject(method = "addEntity", at = @At("HEAD"))
|
||||
private void injectSinglePlayerJoinEvent(Entity entity, CallbackInfo ci) {
|
||||
if (entity instanceof Player player) {
|
||||
CraterSinglePlayerEvent.PlayerLogin playerLogin = new CraterSinglePlayerEvent.PlayerLogin(player);
|
||||
CraterSinglePlayerEvent.PlayerLogin playerLogin = new CraterSinglePlayerEvent.PlayerLogin(BridgedPlayer.of(player));
|
||||
CraterEventBus.INSTANCE.postEvent(playerLogin);
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.hypherionmc.craterlib.mixin.events.client;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.client.ScreenEvent;
|
||||
import com.hypherionmc.craterlib.api.events.client.ScreenEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
@@ -11,6 +11,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
// TODO NOJANG
|
||||
@Mixin(Minecraft.class)
|
||||
public class MinecraftMixin {
|
||||
|
||||
|
@@ -1,7 +1,8 @@
|
||||
package com.hypherionmc.craterlib.mixin.events.client;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.client.PlayerJoinRealmEvent;
|
||||
import com.hypherionmc.craterlib.api.events.client.PlayerJoinRealmEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.realmsclient.dto.BridgedRealmsServer;
|
||||
import com.mojang.realmsclient.RealmsMainScreen;
|
||||
import com.mojang.realmsclient.dto.RealmsServer;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
@@ -13,9 +14,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(RealmsMainScreen.class)
|
||||
public class RealmsMainScreenMixin {
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "play")
|
||||
private static void play(RealmsServer serverData, Screen parent, CallbackInfo ci) {
|
||||
PlayerJoinRealmEvent playerJoinRealm = new PlayerJoinRealmEvent(serverData);
|
||||
@Inject(at = @At("HEAD"), method = "play(Lcom/mojang/realmsclient/dto/RealmsServer;Lnet/minecraft/client/gui/screens/Screen;Z)V")
|
||||
private static void play(RealmsServer serverData, Screen arg2, boolean bl, CallbackInfo ci) {
|
||||
PlayerJoinRealmEvent playerJoinRealm = new PlayerJoinRealmEvent(BridgedRealmsServer.of(serverData));
|
||||
CraterEventBus.INSTANCE.postEvent(playerJoinRealm);
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,21 @@
|
||||
package com.hypherionmc.craterlib.nojang.advancements;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedAdvancement {
|
||||
|
||||
private final Advancement internal;
|
||||
|
||||
public Optional<BridgedDisplayInfo> displayInfo() {
|
||||
if (internal.display().isPresent()) {
|
||||
return Optional.of(BridgedDisplayInfo.of(internal.display().get()));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.hypherionmc.craterlib.nojang.advancements;
|
||||
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.advancements.DisplayInfo;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedDisplayInfo {
|
||||
|
||||
private final DisplayInfo internal;
|
||||
|
||||
public boolean shouldDisplay() {
|
||||
return internal.shouldAnnounceChat();
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return internal.isHidden();
|
||||
}
|
||||
|
||||
public Component displayName() {
|
||||
return ChatUtils.mojangToAdventure(internal.getTitle());
|
||||
}
|
||||
|
||||
public Component description() {
|
||||
return ChatUtils.mojangToAdventure(internal.getDescription());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.hypherionmc.craterlib.nojang.authlib;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedGameProfile {
|
||||
|
||||
private final GameProfile internal;
|
||||
|
||||
public static BridgedGameProfile mojang(UUID id, String name) {
|
||||
return new BridgedGameProfile(new GameProfile(id, name));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return internal.getName();
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return internal.getId();
|
||||
}
|
||||
|
||||
public GameProfile toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package com.hypherionmc.craterlib.nojang.client;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class BridgedMinecraft {
|
||||
|
||||
private final Minecraft internal = Minecraft.getInstance();
|
||||
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package com.hypherionmc.craterlib.nojang.client;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.client.Options;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedOptions {
|
||||
|
||||
private final Options internal;
|
||||
|
||||
public String getLanguage() {
|
||||
return internal.languageCode;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package com.hypherionmc.craterlib.nojang.client.multiplayer;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedClientLevel {
|
||||
|
||||
private final ClientLevel internal;
|
||||
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package com.hypherionmc.craterlib.nojang.commands;
|
||||
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedCommandSourceStack {
|
||||
|
||||
private final CommandSourceStack internal;
|
||||
|
||||
public void sendSuccess(Supplier<Component> supplier, boolean bl) {
|
||||
internal.sendSuccess(() -> ChatUtils.adventureToMojang(supplier.get()), bl);
|
||||
}
|
||||
|
||||
public CommandSourceStack toMojang() {
|
||||
return internal;
|
||||
}
|
||||
}
|
@@ -0,0 +1,81 @@
|
||||
package com.hypherionmc.craterlib.nojang.commands;
|
||||
|
||||
import com.hypherionmc.craterlib.api.commands.CraterCommand;
|
||||
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.GameProfileArgument;
|
||||
import org.apache.commons.lang3.function.TriConsumer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class CommandsRegistry {
|
||||
|
||||
public static final CommandsRegistry INSTANCE = new CommandsRegistry();
|
||||
|
||||
private final List<CraterCommand> commands = new ArrayList<>();
|
||||
|
||||
public void registerCommand(CraterCommand cmd) {
|
||||
commands.add(cmd);
|
||||
}
|
||||
|
||||
public void registerCommands(CommandDispatcher<CommandSourceStack> stack) {
|
||||
commands.forEach(cmd -> {
|
||||
if (cmd.hasArguments()) {
|
||||
CommandWithArguments.register(cmd, stack);
|
||||
} else {
|
||||
CommandWithoutArguments.register(cmd, stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static class CommandWithoutArguments {
|
||||
|
||||
public static void register(CraterCommand cmd, CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
LiteralArgumentBuilder<CommandSourceStack> command = Commands.literal(cmd.getCommandName())
|
||||
.requires(source -> source.hasPermission(cmd.getPermissionLevel()))
|
||||
.executes(context -> {
|
||||
cmd.getExecutor().accept(BridgedCommandSourceStack.of(context.getSource()));
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static class CommandWithArguments {
|
||||
|
||||
public static void register(CraterCommand cmd, CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
LiteralArgumentBuilder<CommandSourceStack> command = Commands.literal(cmd.getCommandName())
|
||||
.requires(source -> source.hasPermission(cmd.getPermissionLevel()));
|
||||
|
||||
cmd.getArguments().forEach((key, pair) -> command.then(Commands.argument(key, pair.getLeft()).executes(context -> {
|
||||
|
||||
// This is FUCKING UGLY.... Need to improve this in the future
|
||||
if (pair.getLeft() instanceof GameProfileArgument) {
|
||||
Collection<GameProfile> profiles = GameProfileArgument.getGameProfiles(context, key);
|
||||
List<BridgedGameProfile> bridgedGameProfiles = new ArrayList<>();
|
||||
|
||||
profiles.forEach(p -> bridgedGameProfiles.add(BridgedGameProfile.of(p)));
|
||||
|
||||
((TriConsumer<BridgedPlayer, List<BridgedGameProfile>, BridgedCommandSourceStack>) pair.getRight())
|
||||
.accept(BridgedPlayer.of(context.getSource().getPlayer()), bridgedGameProfiles, BridgedCommandSourceStack.of(context.getSource()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
})));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
package com.hypherionmc.craterlib.nojang.nbt;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedCompoundTag {
|
||||
|
||||
private final CompoundTag internal;
|
||||
|
||||
public static BridgedCompoundTag empty() {
|
||||
return new BridgedCompoundTag(new CompoundTag());
|
||||
}
|
||||
|
||||
public BridgedCompoundTag getCompound(String key) {
|
||||
return BridgedCompoundTag.of(internal.getCompound(key));
|
||||
}
|
||||
|
||||
public Set<String> getAllKeys() {
|
||||
return internal.getAllKeys();
|
||||
}
|
||||
|
||||
public String getString(String key) {
|
||||
return internal.getString(key);
|
||||
}
|
||||
|
||||
public boolean getBoolean(String key) {
|
||||
return internal.getBoolean(key);
|
||||
}
|
||||
|
||||
public void putString(String key, String value) {
|
||||
internal.putString(key, value);
|
||||
}
|
||||
|
||||
public void put(String key, BridgedCompoundTag value) {
|
||||
internal.put(key, value.toMojang());
|
||||
}
|
||||
|
||||
public void putBoolean(String key, boolean value) {
|
||||
internal.putBoolean(key, value);
|
||||
}
|
||||
|
||||
public CompoundTag toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
package com.hypherionmc.craterlib.nojang.network;
|
||||
|
||||
import com.hypherionmc.craterlib.nojang.nbt.BridgedCompoundTag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedFriendlyByteBuf {
|
||||
|
||||
private final FriendlyByteBuf internal;
|
||||
|
||||
public BridgedCompoundTag readNbt() {
|
||||
return BridgedCompoundTag.of(internal.readNbt());
|
||||
}
|
||||
|
||||
public BridgedFriendlyByteBuf writeNbt(BridgedCompoundTag tag) {
|
||||
internal.writeNbt(tag.toMojang());
|
||||
return BridgedFriendlyByteBuf.of(internal);
|
||||
}
|
||||
|
||||
public FriendlyByteBuf toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* This package, called NoJang, exposes various wrapped API's.
|
||||
* Using this api, a mod can essentially run on ANY minecraft version this library
|
||||
* supports, from one code base.
|
||||
* IMPORTANT NOTE: THESE API'S MUST NEVER EXPOSE ANY MINECRAFT CLASSES OR CODE!!!!
|
||||
* THEY MUST ALWAYS BE HANDLED INTERNALLY AND ONLY RETURN WRAPPED VARIANTS
|
||||
*/
|
||||
package com.hypherionmc.craterlib.nojang;
|
@@ -0,0 +1,11 @@
|
||||
package com.hypherionmc.craterlib.nojang.realmsclient.dto;
|
||||
|
||||
import com.mojang.realmsclient.dto.RealmsServer;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedRealmsServer {
|
||||
|
||||
private final RealmsServer internal;
|
||||
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package com.hypherionmc.craterlib.nojang.resources;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class ResourceIdentifier {
|
||||
|
||||
private final ResourceLocation internal;
|
||||
|
||||
public ResourceIdentifier(String namespace, String path) {
|
||||
this.internal = new ResourceLocation(namespace, path);
|
||||
}
|
||||
|
||||
public ResourceIdentifier(String path) {
|
||||
this.internal = new ResourceLocation(path);
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return internal.getNamespace();
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return internal.getPath();
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return internal.toString();
|
||||
}
|
||||
|
||||
public ResourceLocation toMojang() {
|
||||
return internal;
|
||||
}
|
||||
}
|
@@ -0,0 +1,86 @@
|
||||
package com.hypherionmc.craterlib.nojang.server;
|
||||
|
||||
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.players.UserBanListEntry;
|
||||
import net.minecraft.server.players.UserWhiteListEntry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedMinecraftServer {
|
||||
|
||||
private final MinecraftServer internal;
|
||||
|
||||
public boolean isUsingWhitelist() {
|
||||
return internal.getPlayerList().isUsingWhitelist();
|
||||
}
|
||||
|
||||
public int getPlayerCount() {
|
||||
return internal.getPlayerList().getPlayerCount();
|
||||
}
|
||||
|
||||
public int getMaxPlayers() {
|
||||
return internal.getPlayerList().getMaxPlayers();
|
||||
}
|
||||
|
||||
public String getServerModName() {
|
||||
return internal.getServerModName();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return SharedConstants.getCurrentVersion().getName();
|
||||
}
|
||||
|
||||
public boolean usesAuthentication() {
|
||||
return internal.usesAuthentication();
|
||||
}
|
||||
|
||||
public void broadcastSystemMessage(Component text, boolean bl) {
|
||||
internal.getPlayerList().broadcastSystemMessage(ChatUtils.adventureToMojang(text), bl);
|
||||
}
|
||||
|
||||
public boolean isPlayerBanned(BridgedGameProfile profile) {
|
||||
return internal.getPlayerList().getBans().isBanned(profile.toMojang());
|
||||
}
|
||||
|
||||
public void whitelistPlayer(BridgedGameProfile gameProfile) {
|
||||
if (!internal.getPlayerList().isUsingWhitelist())
|
||||
return;
|
||||
|
||||
internal.getPlayerList().getWhiteList().add(new UserWhiteListEntry(gameProfile.toMojang()));
|
||||
}
|
||||
|
||||
public void unWhitelistPlayer(BridgedGameProfile gameProfile) {
|
||||
if (!internal.getPlayerList().isUsingWhitelist())
|
||||
return;
|
||||
|
||||
internal.getPlayerList().getWhiteList().remove(new UserWhiteListEntry(gameProfile.toMojang()));
|
||||
}
|
||||
|
||||
public List<BridgedPlayer> getPlayers() {
|
||||
List<BridgedPlayer> profiles = new ArrayList<>();
|
||||
|
||||
if (internal.getPlayerList() == null)
|
||||
return profiles;
|
||||
|
||||
internal.getPlayerList().getPlayers().forEach(p -> profiles.add(BridgedPlayer.of(p)));
|
||||
|
||||
return profiles;
|
||||
}
|
||||
|
||||
public void banPlayer(BridgedGameProfile profile) {
|
||||
internal.getPlayerList().getBans().add(new UserBanListEntry(profile.toMojang()));
|
||||
}
|
||||
|
||||
public MinecraftServer toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
package com.hypherionmc.craterlib.nojang.world.entity.player;
|
||||
|
||||
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedPlayer {
|
||||
|
||||
private final Player internal;
|
||||
|
||||
public Component getDisplayName() {
|
||||
return ChatUtils.mojangToAdventure(internal.getDisplayName());
|
||||
}
|
||||
|
||||
public Component getName() {
|
||||
return ChatUtils.mojangToAdventure(internal.getName());
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return internal.getUUID();
|
||||
}
|
||||
|
||||
public String getStringUUID() {
|
||||
return internal.getStringUUID();
|
||||
}
|
||||
|
||||
public BridgedGameProfile getGameProfile() {
|
||||
return BridgedGameProfile.of(internal.getGameProfile());
|
||||
}
|
||||
|
||||
public boolean isServerPlayer() {
|
||||
return internal instanceof ServerPlayer;
|
||||
}
|
||||
|
||||
public Player toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ServerGamePacketListenerImpl getConnection() {
|
||||
if (isServerPlayer()) {
|
||||
return ((ServerPlayer) internal).connection;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ServerPlayer toMojangServerPlayer() {
|
||||
return (ServerPlayer) internal;
|
||||
}
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
package com.hypherionmc.craterlib.util;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Utility class to handle Translation Keys and Formatting
|
||||
*/
|
||||
public class LangUtils {
|
||||
|
||||
public static Component getTooltipTitle(String key) {
|
||||
return Component.literal(ChatFormatting.YELLOW + Component.translatable(key).getString());
|
||||
}
|
||||
|
||||
public static String resolveTranslation(String key) {
|
||||
return Component.translatable(key).getString();
|
||||
}
|
||||
|
||||
public static Component getTranslation(String key) {
|
||||
return Component.translatable(key);
|
||||
}
|
||||
|
||||
public static Component makeComponent(String text) {
|
||||
return Component.translatable(text);
|
||||
}
|
||||
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
package com.hypherionmc.craterlib.util;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Utility class to handle various mathematical functions
|
||||
*/
|
||||
public class MathUtils {
|
||||
|
||||
public static VoxelShape rotateShape(Direction from, Direction to, VoxelShape shape) {
|
||||
VoxelShape[] buffer = new VoxelShape[]{shape, Shapes.empty()};
|
||||
|
||||
int times = (to.ordinal() - from.ordinal() + 4) % 4;
|
||||
for (int i = 0; i < times; i++) {
|
||||
buffer[0].forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = Shapes.or(buffer[1], Shapes.box(1 - maxZ, minY, minX, 1 - minZ, maxY, maxX)));
|
||||
buffer[0] = buffer[1];
|
||||
buffer[1] = Shapes.empty();
|
||||
}
|
||||
return buffer[0];
|
||||
}
|
||||
|
||||
public static void writeBlockPosToNBT(BlockPos pos, CompoundTag tag) {
|
||||
tag.putInt("block_x", pos.getX());
|
||||
tag.putInt("block_y", pos.getY());
|
||||
tag.putInt("block_z", pos.getZ());
|
||||
}
|
||||
|
||||
public static BlockPos readBlockPosFromNBT(CompoundTag tag) {
|
||||
int x, y, z;
|
||||
x = tag.getInt("block_x");
|
||||
y = tag.getInt("block_y");
|
||||
z = tag.getInt("block_z");
|
||||
return new BlockPos(x, y, z);
|
||||
}
|
||||
|
||||
}
|
@@ -1,70 +0,0 @@
|
||||
package com.hypherionmc.craterlib.util;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Utility class for various rendering functions
|
||||
*/
|
||||
public class RenderUtils {
|
||||
|
||||
public static Vector4f colorIntToRGBA(int color) {
|
||||
float a = 1.0F;
|
||||
float r = (color >> 16 & 0xFF) / 255.0F;
|
||||
float g = (color >> 8 & 0xFF) / 255.0F;
|
||||
float b = (color & 0xFF) / 255.0F;
|
||||
|
||||
return new Vector4f(r, g, b, a);
|
||||
}
|
||||
|
||||
public static Component getFluidAmount(long amount, long capacity) {
|
||||
amount = amount / 81;
|
||||
capacity = capacity / 81;
|
||||
String text = String.valueOf((int) (((float) amount / capacity) * 100));
|
||||
return amount > 0 ? Component.literal(ChatFormatting.AQUA + text + "%") : Component.literal(text + "%");
|
||||
}
|
||||
|
||||
public static Component getTimeDisplayString(double value) {
|
||||
long seconds = Math.round((value / 20));
|
||||
long minutes = Math.round(seconds / 60);
|
||||
if (seconds >= 60) {
|
||||
String appendString = (minutes == 1) ? "Minute" : "Minutes";
|
||||
String doSeconds = ((seconds - (minutes * 60)) > 0) ? ", " + (seconds - (minutes * 60)) + " Seconds" : "";
|
||||
return Component.literal(minutes + " " + appendString + doSeconds);
|
||||
} else {
|
||||
return Component.literal(seconds + " Seconds");
|
||||
}
|
||||
}
|
||||
|
||||
public static int renderColorFromDye(DyeColor color) {
|
||||
return color.getMapColor().col | 0xFF000000;
|
||||
}
|
||||
|
||||
public static int alphaColorFromDye(DyeColor color, float alpha) {
|
||||
float[] colors = color.getTextureDiffuseColors();
|
||||
return new Color(colors[0], colors[1], colors[2], alpha).getRGB();
|
||||
}
|
||||
|
||||
public static class ARGB32 {
|
||||
public static int alpha(int pPackedColor) {
|
||||
return pPackedColor >>> 24;
|
||||
}
|
||||
|
||||
public static int red(int pPackedColor) {
|
||||
return pPackedColor >> 16 & 255;
|
||||
}
|
||||
|
||||
public static int green(int pPackedColor) {
|
||||
return pPackedColor >> 8 & 255;
|
||||
}
|
||||
|
||||
public static int blue(int pPackedColor) {
|
||||
return pPackedColor & 255;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,80 @@
|
||||
package com.hypherionmc.craterlib.utils;
|
||||
|
||||
import me.hypherionmc.mcdiscordformatter.discord.DiscordSerializer;
|
||||
import me.hypherionmc.mcdiscordformatter.minecraft.MinecraftSerializer;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
|
||||
public class ChatUtils {
|
||||
|
||||
public static Component adventureToMojang(net.kyori.adventure.text.Component inComponent) {
|
||||
final String serialised = GsonComponentSerializer.gson().serialize(inComponent);
|
||||
return Component.Serializer.fromJson(serialised);
|
||||
}
|
||||
|
||||
public static net.kyori.adventure.text.Component mojangToAdventure(Component inComponent) {
|
||||
final String serialised = Component.Serializer.toJson(inComponent);
|
||||
return GsonComponentSerializer.gson().deserialize(serialised);
|
||||
}
|
||||
|
||||
// Some text components contain duplicate text, resulting in duplicate messages
|
||||
// sent back to discord. This should help fix those issues
|
||||
public static Component safeCopy(Component inComponent) {
|
||||
String value = inComponent.getString();
|
||||
Style style = inComponent.getStyle();
|
||||
return Component.literal(value).withStyle(style);
|
||||
}
|
||||
|
||||
public static String strip(String inString, String... toStrip) {
|
||||
String finalString = inString;
|
||||
|
||||
for (String strip : toStrip) {
|
||||
if (finalString.startsWith(strip))
|
||||
finalString = finalString.replaceFirst(strip, "");
|
||||
|
||||
if (finalString.startsWith(" "))
|
||||
finalString = finalString.replaceFirst(" ", "");
|
||||
}
|
||||
|
||||
return finalString;
|
||||
}
|
||||
|
||||
public static String resolve(net.kyori.adventure.text.Component component, boolean formatted) {
|
||||
Component c = adventureToMojang(component);
|
||||
String returnVal = ChatFormatting.stripFormatting(c.getString());
|
||||
|
||||
if (formatted) {
|
||||
returnVal = DiscordSerializer.INSTANCE.serialize(safeCopy(c).copy());
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
public static net.kyori.adventure.text.Component resolve(String component, boolean formatted) {
|
||||
Component returnVal = Component.literal(component);
|
||||
if (formatted) {
|
||||
returnVal = MinecraftSerializer.INSTANCE.serialize(component);
|
||||
}
|
||||
|
||||
return mojangToAdventure(returnVal);
|
||||
}
|
||||
|
||||
public static net.kyori.adventure.text.Component getTooltipTitle(String key) {
|
||||
return net.kyori.adventure.text.Component.text(NamedTextColor.YELLOW + net.kyori.adventure.text.Component.translatable(key).key());
|
||||
}
|
||||
|
||||
public static String resolveTranslation(String key) {
|
||||
return net.kyori.adventure.text.Component.translatable(key).key();
|
||||
}
|
||||
|
||||
public static net.kyori.adventure.text.Component getTranslation(String key) {
|
||||
return net.kyori.adventure.text.Component.translatable(key);
|
||||
}
|
||||
|
||||
public static net.kyori.adventure.text.Component makeComponent(String text) {
|
||||
return net.kyori.adventure.text.Component.translatable(text);
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package com.hypherionmc.craterlib.util;
|
||||
package com.hypherionmc.craterlib.utils;
|
||||
|
||||
import com.hypherionmc.craterlib.CraterConstants;
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.ServiceLoader;
|
||||
* @author HypherionSA
|
||||
* Utility class to handle SPI loading
|
||||
*/
|
||||
public class ServiceUtil {
|
||||
public class InternalServiceUtil {
|
||||
|
||||
/**
|
||||
* Try to load a service
|
||||
@@ -17,7 +17,6 @@ public class ServiceUtil {
|
||||
* @return The loaded class
|
||||
*/
|
||||
public static <T> T load(Class<T> clazz) {
|
||||
|
||||
final T loadedService = ServiceLoader.load(clazz)
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
|
||||
@@ -25,4 +24,4 @@ public class ServiceUtil {
|
||||
return loadedService;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package com.hypherionmc.craterlib.util;
|
||||
package com.hypherionmc.craterlib.utils;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -43,4 +43,4 @@ public class OptifineUtils {
|
||||
return hasOptifine;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -13,10 +13,8 @@
|
||||
],
|
||||
"server": [
|
||||
"events.CommandMixin",
|
||||
"events.LivingEntityMixin",
|
||||
"events.PlayerAdvancementsMixin",
|
||||
"events.PlayerListMixin",
|
||||
"events.ServerGamePacketListenerImplMixin",
|
||||
"events.ServerPlayerMixin"
|
||||
],
|
||||
"injectors": {
|
||||
|
@@ -1,12 +1,14 @@
|
||||
package com.hypherionmc.craterlib;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.server.CraterRegisterCommandEvent;
|
||||
import com.hypherionmc.craterlib.api.event.server.CraterServerLifecycleEvent;
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterRegisterCommandEvent;
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterServerLifecycleEvent;
|
||||
import com.hypherionmc.craterlib.common.FabricCommonPlatform;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.core.networking.CraterPacketNetwork;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import com.hypherionmc.craterlib.network.CraterFabricNetworkHandler;
|
||||
import com.hypherionmc.craterlib.nojang.commands.CommandsRegistry;
|
||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
@@ -16,17 +18,19 @@ public class CraterLibInitializer implements ModInitializer {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
new CraterPacketNetwork(new CraterFabricNetworkHandler(PacketSide.SERVER));
|
||||
CommandRegistrationCallback.EVENT.register(
|
||||
(dispatcher, registryAccess, environment) -> CraterEventBus.INSTANCE.postEvent(new CraterRegisterCommandEvent(dispatcher)));
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterRegisterCommandEvent());
|
||||
CommandsRegistry.INSTANCE.registerCommands(dispatcher);
|
||||
});
|
||||
|
||||
|
||||
ServerLifecycleEvents.SERVER_STARTING.register(server -> {
|
||||
FabricCommonPlatform.server = server;
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Starting(server));
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Starting(BridgedMinecraftServer.of(server)));
|
||||
});
|
||||
|
||||
ServerLifecycleEvents.SERVER_STARTED.register(li -> CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Started()));
|
||||
ServerLifecycleEvents.SERVER_STOPPING.register(server -> CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Stopping()));
|
||||
ServerLifecycleEvents.SERVER_STOPPED.register(server -> CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Stopped()));
|
||||
ServerLifecycleEvents.SERVER_STARTED.register(li -> CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Started(BridgedMinecraftServer.of(li))));
|
||||
ServerLifecycleEvents.SERVER_STOPPING.register(server -> CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Stopping(BridgedMinecraftServer.of(server))));
|
||||
ServerLifecycleEvents.SERVER_STOPPED.register(server -> CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Stopped(BridgedMinecraftServer.of(server))));
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,11 @@
|
||||
package com.hypherionmc.craterlib.client;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.client.CraterClientTickEvent;
|
||||
import com.hypherionmc.craterlib.api.events.client.CraterClientTickEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.core.networking.CraterPacketNetwork;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import com.hypherionmc.craterlib.network.CraterFabricNetworkHandler;
|
||||
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedClientLevel;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
|
||||
@@ -14,7 +15,7 @@ public class CraterLibClientInitializer implements ClientModInitializer {
|
||||
public void onInitializeClient() {
|
||||
new CraterPacketNetwork(new CraterFabricNetworkHandler(PacketSide.CLIENT));
|
||||
ClientTickEvents.START_CLIENT_TICK.register((listener) -> {
|
||||
CraterClientTickEvent event = new CraterClientTickEvent(listener.level);
|
||||
CraterClientTickEvent event = new CraterClientTickEvent(BridgedClientLevel.of(listener.level));
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
});
|
||||
|
||||
|
@@ -1,6 +1,9 @@
|
||||
package com.hypherionmc.craterlib.client;
|
||||
|
||||
import com.hypherionmc.craterlib.core.platform.ClientPlatform;
|
||||
import com.hypherionmc.craterlib.nojang.client.BridgedMinecraft;
|
||||
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedClientLevel;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
@@ -12,18 +15,18 @@ import net.minecraft.world.level.Level;
|
||||
public class FabricClientPlatform implements ClientPlatform {
|
||||
|
||||
@Override
|
||||
public Minecraft getClientInstance() {
|
||||
return Minecraft.getInstance();
|
||||
public BridgedMinecraft getClientInstance() {
|
||||
return new BridgedMinecraft();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getClientPlayer() {
|
||||
return Minecraft.getInstance().player;
|
||||
public BridgedPlayer getClientPlayer() {
|
||||
return BridgedPlayer.of(Minecraft.getInstance().player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Level getClientLevel() {
|
||||
return Minecraft.getInstance().level;
|
||||
public BridgedClientLevel getClientLevel() {
|
||||
return BridgedClientLevel.of(Minecraft.getInstance().level);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,8 +1,7 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.core.network.CraterNetworkHandler;
|
||||
import com.hypherionmc.craterlib.core.platform.CommonPlatform;
|
||||
import com.hypherionmc.craterlib.network.FabricNetworkHandler;
|
||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
/**
|
||||
@@ -13,12 +12,7 @@ public class FabricCommonPlatform implements CommonPlatform {
|
||||
public static MinecraftServer server;
|
||||
|
||||
@Override
|
||||
public CraterNetworkHandler createPacketHandler(String modid, boolean requireClient, boolean requireServer) {
|
||||
return FabricNetworkHandler.of(modid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinecraftServer getMCServer() {
|
||||
return server;
|
||||
public BridgedMinecraftServer getMCServer() {
|
||||
return BridgedMinecraftServer.of(server);
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,9 @@
|
||||
package com.hypherionmc.craterlib.mixin.events;
|
||||
package com.hypherionmc.craterlib.mixin;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.server.CraterServerChatEvent;
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterServerChatEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.PlayerChatMessage;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@@ -25,7 +27,7 @@ public class ServerGamePacketListenerImplMixin {
|
||||
cancellable = true
|
||||
)
|
||||
private void injectChatEvent(PlayerChatMessage arg, Component arg2, FilteredText arg3, CallbackInfo ci) {
|
||||
CraterServerChatEvent event = new CraterServerChatEvent(this.player, arg.decoratedContent().getString(), arg.decoratedContent());
|
||||
CraterServerChatEvent event = new CraterServerChatEvent(BridgedPlayer.of(this.player), arg.decoratedContent().getString(), ChatUtils.mojangToAdventure(arg.decoratedContent()));
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
if (event.wasCancelled())
|
||||
ci.cancel();
|
@@ -1,7 +1,9 @@
|
||||
package com.hypherionmc.craterlib.mixin;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.client.LateInitEvent;
|
||||
import com.hypherionmc.craterlib.api.events.client.LateInitEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.client.BridgedMinecraft;
|
||||
import com.hypherionmc.craterlib.nojang.client.BridgedOptions;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Options;
|
||||
import net.minecraft.client.tutorial.Tutorial;
|
||||
@@ -15,7 +17,7 @@ public class TutorialMixin {
|
||||
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
private void injectEarlyInitEvent(Minecraft minecraft, Options options, CallbackInfo ci) {
|
||||
LateInitEvent event = new LateInitEvent(minecraft, options);
|
||||
LateInitEvent event = new LateInitEvent(new BridgedMinecraft(), BridgedOptions.of(options));
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
}
|
||||
|
||||
|
@@ -5,6 +5,9 @@ import com.hypherionmc.craterlib.core.networking.PacketRegistry;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
@@ -32,17 +35,17 @@ public class CraterFabricNetworkHandler extends PacketRegistry {
|
||||
CHANNELS.put(holder.messageType(), new Message<>(holder.packetId(), holder.encoder()));
|
||||
|
||||
if (PacketSide.CLIENT.equals(this.side)) {
|
||||
ClientPlayNetworking.registerGlobalReceiver(holder.packetId(), ((client, listener, buf, responseSender) -> {
|
||||
ClientPlayNetworking.registerGlobalReceiver(holder.packetId().toMojang(), ((client, listener, buf, responseSender) -> {
|
||||
buf.readByte();
|
||||
T message = holder.decoder().apply(buf);
|
||||
T message = holder.decoder().apply(BridgedFriendlyByteBuf.of(buf));
|
||||
client.execute(() -> holder.handler().accept(new PacketContext<>(message, PacketSide.CLIENT)));
|
||||
}));
|
||||
} else {
|
||||
|
||||
ServerPlayNetworking.registerGlobalReceiver(holder.packetId(), ((server, player, listener, buf, responseSender) -> {
|
||||
ServerPlayNetworking.registerGlobalReceiver(holder.packetId().toMojang(), ((server, player, listener, buf, responseSender) -> {
|
||||
buf.readByte();
|
||||
T message = holder.decoder().apply(buf);
|
||||
server.execute(() -> holder.handler().accept(new PacketContext<>(player, message, PacketSide.SERVER)));
|
||||
T message = holder.decoder().apply(BridgedFriendlyByteBuf.of(buf));
|
||||
server.execute(() -> holder.handler().accept(new PacketContext<>(BridgedPlayer.of(player), message, PacketSide.SERVER)));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -58,24 +61,24 @@ public class CraterFabricNetworkHandler extends PacketRegistry {
|
||||
public <T> void sendToServer(T packet, boolean ignoreCheck) {
|
||||
Message<T> message = (Message<T>) CHANNELS.get(packet.getClass());
|
||||
|
||||
if (ClientPlayNetworking.canSend(message.id()) || ignoreCheck) {
|
||||
if (ClientPlayNetworking.canSend(message.id().toMojang()) || ignoreCheck) {
|
||||
FriendlyByteBuf buf = PacketByteBufs.create();
|
||||
buf.writeByte(0);
|
||||
message.encoder().accept(packet, buf);
|
||||
ClientPlayNetworking.send(message.id(), buf);
|
||||
message.encoder().accept(packet, BridgedFriendlyByteBuf.of(buf));
|
||||
ClientPlayNetworking.send(message.id().toMojang(), buf);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void sendToClient(T packet, ServerPlayer player) {
|
||||
public <T> void sendToClient(T packet, BridgedPlayer player) {
|
||||
Message<T> message = (Message<T>) CHANNELS.get(packet.getClass());
|
||||
if (ServerPlayNetworking.canSend(player, message.id()))
|
||||
if (ServerPlayNetworking.canSend(player.toMojangServerPlayer(), message.id().toMojang()))
|
||||
{
|
||||
FriendlyByteBuf buf = PacketByteBufs.create();
|
||||
buf.writeByte(0);
|
||||
message.encoder().accept(packet, buf);
|
||||
ServerPlayNetworking.send(player, message.id(), buf);
|
||||
message.encoder().accept(packet, BridgedFriendlyByteBuf.of(buf));
|
||||
ServerPlayNetworking.send(player.toMojangServerPlayer(), message.id().toMojang(), buf);
|
||||
}
|
||||
}
|
||||
|
||||
public record Message<T>(ResourceLocation id, BiConsumer<T, FriendlyByteBuf> encoder) { }
|
||||
public record Message<T>(ResourceIdentifier id, BiConsumer<T, BridgedFriendlyByteBuf> encoder) { }
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@
|
||||
"TutorialMixin"
|
||||
],
|
||||
"server": [
|
||||
"ServerGamePacketListenerImplMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
@@ -1,11 +1,13 @@
|
||||
package com.hypherionmc.craterlib;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.client.LateInitEvent;
|
||||
import com.hypherionmc.craterlib.api.events.client.LateInitEvent;
|
||||
import com.hypherionmc.craterlib.common.ForgeServerEvents;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.core.networking.CraterPacketNetwork;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import com.hypherionmc.craterlib.network.CraterForgeNetworkHandler;
|
||||
import com.hypherionmc.craterlib.nojang.client.BridgedMinecraft;
|
||||
import com.hypherionmc.craterlib.nojang.client.BridgedOptions;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
@@ -26,7 +28,7 @@ public class CraterLib {
|
||||
public void commonSetup(FMLCommonSetupEvent evt) {
|
||||
new CraterPacketNetwork(new CraterForgeNetworkHandler(FMLLoader.getDist().isClient() ? PacketSide.CLIENT : PacketSide.SERVER));
|
||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
LateInitEvent event = new LateInitEvent(Minecraft.getInstance(), Minecraft.getInstance().options);
|
||||
LateInitEvent event = new LateInitEvent(new BridgedMinecraft(), BridgedOptions.of(Minecraft.getInstance().options));
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
});
|
||||
}
|
||||
|
@@ -1,8 +1,9 @@
|
||||
package com.hypherionmc.craterlib.client;
|
||||
|
||||
import com.hypherionmc.craterlib.CraterConstants;
|
||||
import com.hypherionmc.craterlib.api.event.client.CraterClientTickEvent;
|
||||
import com.hypherionmc.craterlib.api.events.client.CraterClientTickEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedClientLevel;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
@@ -14,7 +15,7 @@ public class ForgeClientEvents {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void clientTick(TickEvent.LevelTickEvent event) {
|
||||
CraterClientTickEvent craterClientTickEvent = new CraterClientTickEvent(Minecraft.getInstance().level);
|
||||
CraterClientTickEvent craterClientTickEvent = new CraterClientTickEvent(BridgedClientLevel.of(Minecraft.getInstance().level));
|
||||
CraterEventBus.INSTANCE.postEvent(craterClientTickEvent);
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,9 @@
|
||||
package com.hypherionmc.craterlib.client;
|
||||
|
||||
import com.hypherionmc.craterlib.core.platform.ClientPlatform;
|
||||
import com.hypherionmc.craterlib.nojang.client.BridgedMinecraft;
|
||||
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedClientLevel;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
@@ -18,18 +21,18 @@ public class ForgeClientHelper implements ClientPlatform {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Minecraft getClientInstance() {
|
||||
return Minecraft.getInstance();
|
||||
public BridgedMinecraft getClientInstance() {
|
||||
return new BridgedMinecraft();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getClientPlayer() {
|
||||
return Minecraft.getInstance().player;
|
||||
public BridgedPlayer getClientPlayer() {
|
||||
return BridgedPlayer.of(Minecraft.getInstance().player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Level getClientLevel() {
|
||||
return Minecraft.getInstance().level;
|
||||
public BridgedClientLevel getClientLevel() {
|
||||
return BridgedClientLevel.of(Minecraft.getInstance().level);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,10 +1,8 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.core.network.CraterNetworkHandler;
|
||||
import com.hypherionmc.craterlib.core.platform.CommonPlatform;
|
||||
import com.hypherionmc.craterlib.network.ForgeNetworkHandler;
|
||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
|
||||
@@ -22,12 +20,7 @@ public class ForgeCommonHelper implements CommonPlatform {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraterNetworkHandler createPacketHandler(String modid, boolean requiredClient, boolean requiredServer) {
|
||||
return ForgeNetworkHandler.of(modid, requiredClient, requiredServer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinecraftServer getMCServer() {
|
||||
return ServerLifecycleHooks.getCurrentServer();
|
||||
public BridgedMinecraftServer getMCServer() {
|
||||
return BridgedMinecraftServer.of(ServerLifecycleHooks.getCurrentServer());
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,10 @@
|
||||
package com.hypherionmc.craterlib.common;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.server.CraterRegisterCommandEvent;
|
||||
import com.hypherionmc.craterlib.api.event.server.CraterServerLifecycleEvent;
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterRegisterCommandEvent;
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterServerLifecycleEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.commands.CommandsRegistry;
|
||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.event.server.ServerStartedEvent;
|
||||
import net.minecraftforge.event.server.ServerStartingEvent;
|
||||
@@ -14,27 +16,28 @@ public class ForgeServerEvents {
|
||||
|
||||
@SubscribeEvent
|
||||
public void serverStarting(ServerStartingEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Starting(event.getServer()));
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Starting(BridgedMinecraftServer.of(event.getServer())));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void serverStarted(ServerStartedEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Started());
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Started(BridgedMinecraftServer.of(event.getServer())));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void serverStopping(ServerStoppingEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Stopping());
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Stopping(BridgedMinecraftServer.of(event.getServer())));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void serverStopped(ServerStoppedEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Stopped());
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Stopped(BridgedMinecraftServer.of(event.getServer())));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onCommandRegister(RegisterCommandsEvent event) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterRegisterCommandEvent(event.getDispatcher()));
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterRegisterCommandEvent());
|
||||
CommandsRegistry.INSTANCE.registerCommands(event.getDispatcher());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -25,8 +25,6 @@ public class ConfigScreenHandlerMixin {
|
||||
/**
|
||||
* Inject Auto Generated config Screens into forge
|
||||
*
|
||||
* @param selectedMod
|
||||
* @param cir
|
||||
*/
|
||||
@Inject(at = @At("RETURN"), method = "getScreenFactoryFor", cancellable = true, remap = false)
|
||||
private static void injectConfigScreen(IModInfo selectedMod, CallbackInfoReturnable<Optional<BiFunction<Minecraft, Screen, Screen>>> cir) {
|
||||
|
@@ -0,0 +1,36 @@
|
||||
package com.hypherionmc.craterlib.mixin;
|
||||
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterServerChatEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.PlayerChatMessage;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.FilteredText;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(value = ServerGamePacketListenerImpl.class, priority = Integer.MIN_VALUE)
|
||||
public class ServerGamePacketListenerImplMixin {
|
||||
|
||||
@Shadow
|
||||
public ServerPlayer player;
|
||||
|
||||
@Inject(
|
||||
method = "lambda$handleChat$6",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true
|
||||
)
|
||||
private void injectChatEvent(Component component, PlayerChatMessage arg, FilteredText p_296589_, CallbackInfo ci) {
|
||||
CraterServerChatEvent event = new CraterServerChatEvent(BridgedPlayer.of(this.player), arg.decoratedContent().getString(), ChatUtils.mojangToAdventure(arg.decoratedContent()));
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
if (event.wasCancelled())
|
||||
ci.cancel();
|
||||
}
|
||||
|
||||
}
|
@@ -5,9 +5,13 @@ import com.hypherionmc.craterlib.core.networking.PacketRegistry;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraftforge.event.network.CustomPayloadEvent;
|
||||
import net.minecraftforge.network.ChannelBuilder;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
@@ -17,6 +21,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
@@ -31,15 +36,15 @@ public class CraterForgeNetworkHandler extends PacketRegistry {
|
||||
protected <T> void registerPacket(PacketHolder<T> holder) {
|
||||
if (CHANNELS.get(holder.messageType()) == null) {
|
||||
SimpleChannel channel = ChannelBuilder
|
||||
.named(holder.packetId())
|
||||
.named(holder.packetId().toMojang())
|
||||
.clientAcceptedVersions((a, b) -> true)
|
||||
.serverAcceptedVersions((a, b) -> true)
|
||||
.networkProtocolVersion(1)
|
||||
.simpleChannel();
|
||||
|
||||
channel.messageBuilder(holder.messageType())
|
||||
.decoder(holder.decoder())
|
||||
.encoder(holder.encoder())
|
||||
.decoder(mojangDecoder(holder.decoder()))
|
||||
.encoder(mojangEncoder(holder.encoder()))
|
||||
.consumerNetworkThread(buildHandler(holder.handler()))
|
||||
.add();
|
||||
|
||||
@@ -61,21 +66,31 @@ public class CraterForgeNetworkHandler extends PacketRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void sendToClient(T packet, ServerPlayer player) {
|
||||
public <T> void sendToClient(T packet, BridgedPlayer player) {
|
||||
SimpleChannel channel = CHANNELS.get(packet.getClass());
|
||||
Connection connection = player.connection.getConnection();
|
||||
if (channel.isRemotePresent(connection)) {
|
||||
channel.send(packet, PacketDistributor.PLAYER.with(player));
|
||||
ServerGamePacketListenerImpl connection = player.getConnection();
|
||||
if (connection == null)
|
||||
return;
|
||||
|
||||
if (channel.isRemotePresent(connection.getConnection())) {
|
||||
channel.send(packet, PacketDistributor.PLAYER.with(player.toMojangServerPlayer()));
|
||||
}
|
||||
}
|
||||
|
||||
private <T> Function<FriendlyByteBuf, T> mojangDecoder(Function<BridgedFriendlyByteBuf, T> handler) {
|
||||
return byteBuf -> handler.apply(BridgedFriendlyByteBuf.of(byteBuf));
|
||||
}
|
||||
|
||||
private <T> BiConsumer<T, FriendlyByteBuf> mojangEncoder(BiConsumer<T, BridgedFriendlyByteBuf> handler) {
|
||||
return ((t, byteBuf) -> handler.accept(t, BridgedFriendlyByteBuf.of(byteBuf)));
|
||||
}
|
||||
|
||||
private <T> BiConsumer<T, CustomPayloadEvent.Context> buildHandler(Consumer<PacketContext<T>> handler) {
|
||||
return (message, ctx) -> {
|
||||
ctx.enqueueWork(() -> {
|
||||
PacketSide side = ctx.getDirection().getReceptionSide().isServer() ? PacketSide.SERVER : PacketSide.CLIENT;
|
||||
ServerPlayer player = ctx.getSender();
|
||||
handler.accept(new PacketContext<>(player, message, side));
|
||||
handler.accept(new PacketContext<>(BridgedPlayer.of(player), message, side));
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
};
|
||||
|
@@ -93,7 +93,7 @@ public class ForgeNetworkHandler implements CraterNetworkHandler {
|
||||
sup.enqueueWork(() -> {
|
||||
Player player;
|
||||
if (packetDirection == PacketDirection.TO_CLIENT) {
|
||||
player = ClientPlatform.INSTANCE.getClientPlayer();
|
||||
player = ClientPlatform.INSTANCE.getClientPlayer().toMojangServerPlayer();
|
||||
} else {
|
||||
player = sup.getSender();
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@
|
||||
"ConfigScreenHandlerMixin"
|
||||
],
|
||||
"server": [
|
||||
"ServerGamePacketListenerImplMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
@@ -1,17 +1,18 @@
|
||||
package com.hypherionmc.craterlib;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.client.LateInitEvent;
|
||||
import com.hypherionmc.craterlib.api.events.client.LateInitEvent;
|
||||
import com.hypherionmc.craterlib.common.NeoForgeServerEvents;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.core.networking.CraterPacketNetwork;
|
||||
import com.hypherionmc.craterlib.core.networking.PacketRegistry;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import com.hypherionmc.craterlib.network.CraterNeoForgeNetworkHandler;
|
||||
import com.hypherionmc.craterlib.nojang.client.BridgedMinecraft;
|
||||
import com.hypherionmc.craterlib.nojang.client.BridgedOptions;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.neoforged.fml.loading.FMLEnvironment;
|
||||
import net.neoforged.fml.loading.FMLLoader;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
@@ -23,14 +24,14 @@ public class CraterLib {
|
||||
|
||||
public CraterLib(IEventBus eventBus) {
|
||||
NeoForge.EVENT_BUS.register(new NeoForgeServerEvents());
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::commonSetup);
|
||||
eventBus.addListener(this::commonSetup);
|
||||
handler = new CraterNeoForgeNetworkHandler(FMLLoader.getDist().isClient() ? PacketSide.CLIENT : PacketSide.SERVER);
|
||||
}
|
||||
|
||||
public void commonSetup(FMLCommonSetupEvent evt) {
|
||||
new CraterPacketNetwork(handler);
|
||||
if (FMLEnvironment.dist.isClient()) {
|
||||
LateInitEvent event = new LateInitEvent(Minecraft.getInstance(), Minecraft.getInstance().options);
|
||||
LateInitEvent event = new LateInitEvent(new BridgedMinecraft(), BridgedOptions.of(Minecraft.getInstance().options));
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user