[WIP] Initial abstraction layer work

This commit is contained in:
2023-07-20 19:37:17 +02:00
parent a8f61bc143
commit 3fcd6edb2a
4 changed files with 91 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
package com.hypherionmc.craterlib.core.abstraction.commands;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.MutableComponent;
public class AbstractCommand {
public static void replySuccess(CommandContext<CommandSourceStack> stack, MutableComponent message) {
stack.getSource().sendSuccess(() -> message, false);
}
public static void replyFailure(CommandContext<CommandSourceStack> stack, MutableComponent message) {
stack.getSource().sendFailure(message);
}
}

View File

@@ -0,0 +1,40 @@
package com.hypherionmc.craterlib.core.abstraction.server;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import java.util.UUID;
import java.util.function.Supplier;
public class AbstractFakePlayer extends CommandSourceStack {
private final UUID uuid;
public AbstractFakePlayer(MinecraftServer server, String name, MutableComponent displayName, UUID uuid) {
super(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, server.overworld(), 4, name, displayName, server, null);
this.uuid = uuid;
}
public void onSuccess(Component component, boolean bl) {
}
@Override
public void sendSuccess(Supplier<Component> component, boolean bl) {
this.onSuccess(component.get(), bl);
}
@Override
public void sendFailure(Component component) {
sendSuccess(() -> component, false);
}
public UUID getUuid() {
return uuid;
}
}

View File

@@ -0,0 +1,12 @@
package com.hypherionmc.craterlib.core.abstraction.server;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.server.MinecraftServer;
public class AbstractServer {
public static void broadcastMessage(MinecraftServer server, MutableComponent message) {
server.getPlayerList().broadcastSystemMessage(message, false);
}
}

View File

@@ -0,0 +1,23 @@
package com.hypherionmc.craterlib.core.abstraction.text;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
public class AbstractComponent {
public static MutableComponent literal(String component) {
return Component.literal(component);
}
public static MutableComponent translatable(String component) {
return Component.translatable(component);
}
public static Component safeCopy(Component inComponent) {
String value = inComponent.getString();
Style style = inComponent.getStyle();
return Component.literal(value).withStyle(style);
}
}