Fix the block restore system. Begin final implementation of zschem

This commit is contained in:
Tara 2023-01-07 21:27:49 -07:00
parent b4c73493d4
commit cccb000add
10 changed files with 229 additions and 13 deletions

View file

@ -27,6 +27,9 @@ import dev.zontreck.otemod.commands.warps.RTPWarpCommand;
import dev.zontreck.otemod.commands.warps.SetWarpCommand;
import dev.zontreck.otemod.commands.warps.WarpCommand;
import dev.zontreck.otemod.commands.warps.WarpsCommand;
import dev.zontreck.otemod.commands.zschem.SaveSchem;
import dev.zontreck.otemod.commands.zschem.SetPos1;
import dev.zontreck.otemod.commands.zschem.SetPos2;
import dev.zontreck.otemod.configs.OTEServerConfig;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -121,6 +124,10 @@ public class CommandRegistry {
RTPWarpCommand.register(ev.getDispatcher());
WarpsCommand.register(ev.getDispatcher());
WarpCommand.register(ev.getDispatcher());
SetPos1.register(ev.getDispatcher());
SetPos2.register(ev.getDispatcher());
SaveSchem.register(ev.getDispatcher());
}

View file

@ -20,7 +20,6 @@ import net.minecraft.commands.Commands;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;

View file

@ -3,7 +3,6 @@ package dev.zontreck.otemod.commands.warps;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mojang.brigadier.CommandDispatcher;
@ -13,7 +12,6 @@ import dev.zontreck.libzontreck.chat.HoverTip;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.configs.Profile;
import dev.zontreck.otemod.database.TeleportDestination;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.ClickEvent;
@ -21,8 +19,6 @@ import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.Style;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
public class WarpsCommand {

View file

@ -1,5 +1,74 @@
package dev.zontreck.otemod.commands.zschem;
import java.util.ArrayList;
import java.util.List;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.zschem.MemoryHolder;
import dev.zontreck.otemod.zschem.MemoryHolder.Container;
import dev.zontreck.otemod.zschem.StoredBlock;
import net.minecraft.client.gui.components.ChatComponent;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
public class SaveSchem {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("savezschem").executes(c-> saveSchematicUsage(c.getSource())).then(Commands.argument("name", StringArgumentType.string()).executes(z->saveSchematic(z.getSource(), StringArgumentType.getString(z, "name")))));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int saveSchematic(CommandSourceStack source, String name) {
// Perform sanity checks
if(!source.isPlayer())return 1;
ServerPlayer play = source.getPlayer();
if(play==null)return 1;
if(MemoryHolder.hasPlayerCached(play))
{
Container cont = MemoryHolder.get(play);
if(cont == null)
{
saveSchematicUsage(source);
}else {
if(cont.Pos1 != null && cont.Pos2 != null)
{
// Lets go!
List<StoredBlock> blocks = new ArrayList<StoredBlock>();
// First we calculate every vector between pos1 and pos2.
// Then we subtract pos1 from the vector to acquire a relative position.
// Then we save the block with this relative position to the blocks list
// Once serialized, it is then possible to add the position. Note that this makes it impossible to rotate a zschem like with worldedit, but thats usually fine for our usecases. once in-game worldedit can be used to rotate.
// TODO: Also- It is possible that a rotational implementation can be added in the future
}
}
}
ChatServerOverride.broadcastTo(play.getUUID(), Component.literal(ChatColor.doColors("!Dark_Red! You must first set the positions")), OTEMod.THE_SERVER);
return 0;
}
private static int saveSchematicUsage(CommandSourceStack source)
{
String usage = OTEMod.OTEPrefix;
usage += ChatColor.doColors("!gold! /savezschem [string:name]");
ChatServerOverride.broadcastTo(source.getPlayer().getUUID(), Component.literal(usage), OTEMod.THE_SERVER);
return 0;
}
}

View file

@ -1,5 +1,27 @@
package dev.zontreck.otemod.commands.zschem;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.zschem.MemoryHolder;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
public class SetPos1 {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("zpos1").executes(c-> setzPos1(c.getSource())));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int setzPos1(CommandSourceStack source) {
MemoryHolder.setPos1(source.getPlayer(), new Vector3(source.getPosition()));
return 0;
}
}

View file

@ -1,5 +1,27 @@
package dev.zontreck.otemod.commands.zschem;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.zschem.MemoryHolder;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
public class SetPos2 {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("zpos2").executes(c-> setzPos2(c.getSource())));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int setzPos2(CommandSourceStack source) {
MemoryHolder.setPos2(source.getPlayer(), new Vector3(source.getPosition()));
return 0;
}
}