Ship update to OTEMod
This commit is contained in:
parent
9a73e1161c
commit
172c9b51ed
14 changed files with 480 additions and 30 deletions
|
@ -38,6 +38,7 @@ import net.minecraftforge.registries.ForgeRegistries;
|
|||
import org.slf4j.Logger;
|
||||
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.otemod.blocks.ModBlocks;
|
||||
import dev.zontreck.otemod.chat.ChatServerOverride;
|
||||
import dev.zontreck.otemod.commands.CommandRegistry;
|
||||
|
@ -57,6 +58,7 @@ import dev.zontreck.otemod.ore.Modifier.ModifierOfBiomes;
|
|||
@Mod(OTEMod.MOD_ID)
|
||||
public class OTEMod
|
||||
{
|
||||
public static final Vector3 ZERO_VECTOR = new Vector3(0,0,0);
|
||||
// Directly reference a slf4j logger
|
||||
public static final Logger LOGGER = LogUtils.getLogger();
|
||||
public static final String FIRST_JOIN_TAG = "dev.zontreck.otemod.firstjoin";
|
||||
|
|
|
@ -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.LoadSchem;
|
||||
import dev.zontreck.otemod.commands.zschem.Place;
|
||||
import dev.zontreck.otemod.commands.zschem.PlaceAsAir;
|
||||
import dev.zontreck.otemod.commands.zschem.SaveSchem;
|
||||
import dev.zontreck.otemod.commands.zschem.SetPos1;
|
||||
import dev.zontreck.otemod.commands.zschem.SetPos2;
|
||||
|
@ -128,7 +131,8 @@ public class CommandRegistry {
|
|||
SetPos1.register(ev.getDispatcher());
|
||||
SetPos2.register(ev.getDispatcher());
|
||||
SaveSchem.register(ev.getDispatcher());
|
||||
LoadSchem.register(ev.getDispatcher());
|
||||
Place.register(ev.getDispatcher());
|
||||
PlaceAsAir.register(ev.getDispatcher());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,10 +7,8 @@ import dev.zontreck.libzontreck.chat.ChatColor;
|
|||
import dev.zontreck.otemod.OTEMod;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.contents.TranslatableContents;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
|
||||
public class FlyCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
|
@ -34,22 +32,22 @@ public class FlyCommand {
|
|||
if(! ctx.isPlayer())
|
||||
{
|
||||
|
||||
ctx.sendFailure(MutableComponent.create( new TranslatableContents("dev.zontreck.otemod.msgs.only_player")));
|
||||
return 1;
|
||||
}
|
||||
ServerPlayer p = ctx.getPlayer();
|
||||
if(p==null)return 1;
|
||||
|
||||
if(p.getAbilities().mayfly){
|
||||
p.getAbilities().mayfly=false;
|
||||
p.getAbilities().flying=false;
|
||||
p.onUpdateAbilities();
|
||||
|
||||
ctx.sendSuccess(Component.literal(OTEMod.OTEPrefix + ChatColor.DARK_PURPLE + "Your ability to fly has been disabled"), false);
|
||||
ctx.sendSuccess(Component.literal(OTEMod.OTEPrefix + ChatColor.DARK_PURPLE + " Your ability to fly has been disabled"), false);
|
||||
}else {
|
||||
p.getAbilities().mayfly=true;
|
||||
p.onUpdateAbilities();
|
||||
|
||||
ctx.sendSuccess(Component.literal(OTEMod.OTEPrefix + ChatColor.DARK_PURPLE + "You can now fly"), false);
|
||||
ctx.sendSuccess(Component.literal(OTEMod.OTEPrefix + ChatColor.DARK_PURPLE + " You can now fly"), false);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -1,5 +1,134 @@
|
|||
package dev.zontreck.otemod.commands.zschem;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.libzontreck.vectors.WorldPosition;
|
||||
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.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.fml.loading.FMLConfig;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
|
||||
public class LoadSchem {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("loadzschem").executes(c-> loadSchematicUsage(c.getSource())).then(Commands.argument("name", StringArgumentType.string()).executes(z->loadSchematic(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 loadSchematic(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.getContainer(play);
|
||||
if(cont == null)
|
||||
{
|
||||
|
||||
loadSchematicUsage(source);
|
||||
}else {
|
||||
if(cont.Pos1 != OTEMod.ZERO_VECTOR)
|
||||
{
|
||||
// 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
|
||||
|
||||
Path configDir = FMLPaths.GAMEDIR.get().resolve(FMLConfig.defaultConfigPath());
|
||||
configDir = configDir.resolve("ZSchems");
|
||||
File X = configDir.toFile();
|
||||
if(!X.exists())
|
||||
{
|
||||
X.mkdir();
|
||||
}
|
||||
configDir = configDir.resolve(name+"-zschem.nbt");
|
||||
|
||||
if(configDir.toFile().exists()){
|
||||
CompoundTag CT=new CompoundTag();
|
||||
try {
|
||||
CT = NbtIo.readCompressed(configDir.toFile());
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return 1;
|
||||
}
|
||||
|
||||
ListTag blst = CT.getList("blocks", CompoundTag.TAG_COMPOUND);
|
||||
Iterator<Tag> tags = blst.iterator();
|
||||
while(tags.hasNext())
|
||||
{
|
||||
CompoundTag nxt = (CompoundTag)tags.next();
|
||||
StoredBlock sb = new StoredBlock(nxt);
|
||||
ServerLevel pasteLvl = cont.lvl;
|
||||
sb.updateWorld(pasteLvl);
|
||||
|
||||
WorldPosition wp = sb.getWorldPosition();
|
||||
Vector3 superPos = cont.Pos1;
|
||||
wp.Position = superPos.add(wp.Position);
|
||||
sb.setPosition(wp.Position);
|
||||
|
||||
|
||||
blocks.add(sb);
|
||||
|
||||
}
|
||||
|
||||
MemoryHolder.setBlocks(play, blocks);
|
||||
|
||||
}else {
|
||||
ChatServerOverride.broadcastTo(play.getUUID(), Component.literal(OTEMod.OTEPrefix + ChatColor.doColors(" !Dark_Red!No such ZSchem exists!")), source.getServer());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
ChatServerOverride.broadcastTo(play.getUUID(), Component.literal(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!ZSchem loaded from disk!")), OTEMod.THE_SERVER);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
ChatServerOverride.broadcastTo(play.getUUID(), Component.literal(ChatColor.doColors("!Dark_Red! You must set the first position")), OTEMod.THE_SERVER);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int loadSchematicUsage(CommandSourceStack source)
|
||||
{
|
||||
String usage = OTEMod.OTEPrefix;
|
||||
usage += ChatColor.doColors("!gold! /loadzschem [string:name]");
|
||||
ServerPlayer play=source.getPlayer();
|
||||
if(play==null)return 1;
|
||||
ChatServerOverride.broadcastTo(play.getUUID(), Component.literal(usage), OTEMod.THE_SERVER);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,70 @@
|
|||
package dev.zontreck.otemod.commands.zschem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
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.StoredBlock;
|
||||
import dev.zontreck.otemod.zschem.WorldProp;
|
||||
import dev.zontreck.otemod.zschem.MemoryHolder.Container;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
// This command will place the loaded schematic in world. The schematic will originate from position 1. The positions are relative and are added onto position 1.
|
||||
public class Place {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("placezschem").executes(c-> place(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 place(CommandSourceStack source) {
|
||||
|
||||
ServerPlayer play = source.getPlayer();
|
||||
if(play==null)return 1;
|
||||
|
||||
if(!MemoryHolder.hasPlayerCached(play)){
|
||||
|
||||
ChatServerOverride.broadcastTo(play.getUUID(), Component.literal(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You must first load the zschem!")), OTEMod.THE_SERVER);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Container cont = MemoryHolder.getContainer(play);
|
||||
List<StoredBlock> blocks = cont.blocks;
|
||||
|
||||
if(cont.Pos1 != OTEMod.ZERO_VECTOR)
|
||||
{
|
||||
WorldProp system = WorldProp.acquire(cont.lvl);
|
||||
// Begin the process
|
||||
for (StoredBlock storedBlock : blocks) {
|
||||
// alter the stored block and send it off to the queue system for the relevant world!
|
||||
|
||||
system.customEnqueue(storedBlock);
|
||||
}
|
||||
|
||||
}else {
|
||||
|
||||
ChatServerOverride.broadcastTo(play.getUUID(), Component.literal(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You must first load the zschem!")), OTEMod.THE_SERVER);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
ChatServerOverride.broadcastTo(play.getUUID(), Component.literal(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Enqueued!")), OTEMod.THE_SERVER);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
package dev.zontreck.otemod.commands.zschem;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
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.StoredBlock;
|
||||
import dev.zontreck.otemod.zschem.WorldProp;
|
||||
import dev.zontreck.otemod.zschem.MemoryHolder.Container;
|
||||
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.level.block.Blocks;
|
||||
|
||||
// This command will place the loaded schematic in world. The schematic will originate from position 1. The positions are relative and are added onto position 1.
|
||||
public class PlaceAsAir {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("zsetair").executes(c-> place(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 place(CommandSourceStack source) {
|
||||
|
||||
ServerPlayer play = source.getPlayer();
|
||||
if(play==null)return 1;
|
||||
|
||||
if(!MemoryHolder.hasPlayerCached(play)){
|
||||
|
||||
ChatServerOverride.broadcastTo(play.getUUID(), Component.literal(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You must first set the positions!")), OTEMod.THE_SERVER);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Container cont = MemoryHolder.getContainer(play);
|
||||
|
||||
if(cont.Pos1 != OTEMod.ZERO_VECTOR && cont.Pos2 != OTEMod.ZERO_VECTOR)
|
||||
{
|
||||
WorldProp system = WorldProp.acquire(cont.lvl);
|
||||
// Begin the process
|
||||
List<Vector3> positions = cont.Pos1.makeCube(cont.Pos2);
|
||||
Iterator<Vector3> v3 = positions.iterator();
|
||||
while(v3.hasNext())
|
||||
{
|
||||
Vector3 pos = v3.next();
|
||||
StoredBlock sb = new StoredBlock(pos.asBlockPos(), Blocks.AIR.defaultBlockState(), source.getLevel());
|
||||
system.customEnqueue(sb);
|
||||
}
|
||||
|
||||
|
||||
}else {
|
||||
|
||||
ChatServerOverride.broadcastTo(play.getUUID(), Component.literal(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You must first set the positions!")), OTEMod.THE_SERVER);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
ChatServerOverride.broadcastTo(play.getUUID(), Component.literal(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Enqueued!")), OTEMod.THE_SERVER);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
package dev.zontreck.otemod.commands.zschem;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
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;
|
||||
|
@ -14,12 +16,16 @@ 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.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.fml.loading.FMLConfig;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
|
||||
public class SaveSchem {
|
||||
|
||||
|
@ -41,13 +47,13 @@ public class SaveSchem {
|
|||
if(play==null)return 1;
|
||||
if(MemoryHolder.hasPlayerCached(play))
|
||||
{
|
||||
Container cont = MemoryHolder.get(play);
|
||||
Container cont = MemoryHolder.getContainer(play);
|
||||
if(cont == null)
|
||||
{
|
||||
|
||||
saveSchematicUsage(source);
|
||||
}else {
|
||||
if(cont.Pos1 != null && cont.Pos2 != null)
|
||||
if(cont.Pos1 != OTEMod.ZERO_VECTOR && cont.Pos2 != OTEMod.ZERO_VECTOR)
|
||||
{
|
||||
// Lets go!
|
||||
List<StoredBlock> blocks = new ArrayList<StoredBlock>();
|
||||
|
@ -56,6 +62,45 @@ public class SaveSchem {
|
|||
// 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
|
||||
|
||||
List<Vector3> positions = cont.Pos1.makeCube(cont.Pos2);
|
||||
|
||||
for (Vector3 vector3 : positions) {
|
||||
Vector3 v3 = vector3.subtract(cont.Pos1);
|
||||
|
||||
BlockPos current = vector3.asBlockPos();
|
||||
|
||||
StoredBlock sb = new StoredBlock(current, cont.lvl.getBlockState(current), cont.lvl);
|
||||
sb.setPosition(v3);
|
||||
|
||||
blocks.add(sb);
|
||||
}
|
||||
|
||||
CompoundTag savedSchem = new CompoundTag();
|
||||
ListTag lst = new ListTag();
|
||||
for (StoredBlock sBlock : blocks) {
|
||||
lst.add(sBlock.serialize());
|
||||
}
|
||||
savedSchem.put("blocks", lst);
|
||||
|
||||
|
||||
Path configDir = FMLPaths.GAMEDIR.get().resolve(FMLConfig.defaultConfigPath());
|
||||
configDir = configDir.resolve("ZSchems");
|
||||
File X = configDir.toFile();
|
||||
if(!X.exists())
|
||||
{
|
||||
X.mkdir();
|
||||
}
|
||||
configDir = configDir.resolve(name+"-zschem.nbt");
|
||||
|
||||
// Save file!
|
||||
try {
|
||||
NbtIo.writeCompressed(savedSchem, configDir.toFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ChatServerOverride.broadcastTo(play.getUUID(), Component.literal(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!ZSchem saved to disk!")), OTEMod.THE_SERVER);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +113,9 @@ public class SaveSchem {
|
|||
{
|
||||
String usage = OTEMod.OTEPrefix;
|
||||
usage += ChatColor.doColors("!gold! /savezschem [string:name]");
|
||||
ChatServerOverride.broadcastTo(source.getPlayer().getUUID(), Component.literal(usage), OTEMod.THE_SERVER);
|
||||
ServerPlayer play=source.getPlayer();
|
||||
if(play==null)return 1;
|
||||
ChatServerOverride.broadcastTo(play.getUUID(), Component.literal(usage), OTEMod.THE_SERVER);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,15 @@ package dev.zontreck.otemod.commands.zschem;
|
|||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
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 net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class SetPos1 {
|
||||
|
||||
|
@ -20,7 +25,14 @@ public class SetPos1 {
|
|||
}
|
||||
|
||||
private static int setzPos1(CommandSourceStack source) {
|
||||
MemoryHolder.setPos1(source.getPlayer(), new Vector3(source.getPosition()));
|
||||
|
||||
ServerPlayer play = source.getPlayer();
|
||||
if(play==null)return 1;
|
||||
|
||||
MemoryHolder.setPos1(play, new Vector3(source.getPosition()));
|
||||
MemoryHolder.setLevel(play, source.getLevel());
|
||||
|
||||
ChatServerOverride.broadcastTo(play.getUUID(), Component.literal(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Position 1 set!")), OTEMod.THE_SERVER);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,10 +2,15 @@ package dev.zontreck.otemod.commands.zschem;
|
|||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
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 net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class SetPos2 {
|
||||
|
||||
|
@ -20,7 +25,13 @@ public class SetPos2 {
|
|||
}
|
||||
|
||||
private static int setzPos2(CommandSourceStack source) {
|
||||
MemoryHolder.setPos2(source.getPlayer(), new Vector3(source.getPosition()));
|
||||
ServerPlayer play = source.getPlayer();
|
||||
if(play==null)return 1;
|
||||
|
||||
MemoryHolder.setPos2(play, new Vector3(source.getPosition()));
|
||||
MemoryHolder.setLevel(play, source.getLevel());
|
||||
|
||||
ChatServerOverride.broadcastTo(play.getUUID(), Component.literal(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Position 2 set!")), OTEMod.THE_SERVER);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -82,10 +82,10 @@ public class BlockContainerList {
|
|||
if(bs.is(storedBlock.getState().getBlock()) || storedBlock.getTries() >= OTEServerConfig.MAX_TRIES_HEAL.get())
|
||||
{
|
||||
|
||||
HealRunner.scheduleHeal(storedBlock);
|
||||
//HealRunner.scheduleHeal(storedBlock);
|
||||
isb.remove();
|
||||
|
||||
wp.getActualDimension().playSound(null, wp.Position.asBlockPos(), SoundEvents.ANVIL_USE, SoundSource.NEUTRAL, new Random().nextFloat(0.75f,1.0f), new Random().nextFloat(1));
|
||||
//wp.getActualDimension().playSound(null, wp.Position.asBlockPos(), SoundEvents.ANVIL_USE, SoundSource.NEUTRAL, new Random().nextFloat(0.75f,1.0f), new Random().nextFloat(1));
|
||||
|
||||
}else {
|
||||
HealRunner.scheduleHeal(storedBlock);
|
||||
|
@ -117,7 +117,7 @@ public class BlockContainerList {
|
|||
public static BlockContainerList load(CompoundTag tag){
|
||||
BlockContainerList lst = new BlockContainerList();
|
||||
|
||||
ListTag xlst = tag.getList("blocks", CompoundTag.TAG_BYTE);
|
||||
ListTag xlst = tag.getList("blocks", CompoundTag.TAG_COMPOUND);
|
||||
ListIterator<Tag> it = xlst.listIterator();
|
||||
while(it.hasNext()){
|
||||
Tag tg = it.next();
|
||||
|
|
|
@ -72,6 +72,8 @@ public class EventHandler {
|
|||
if(wp!=null){
|
||||
wp.onTick();
|
||||
}
|
||||
|
||||
MemoryHolder.tick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,27 +2,61 @@ package dev.zontreck.otemod.zschem;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.chat.ChatServerOverride;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public class MemoryHolder {
|
||||
// This class holds the temporary memory related to zschem data
|
||||
// We also store position information here.
|
||||
private static final MemoryHolder INSTANCE = new MemoryHolder();
|
||||
|
||||
public static MemoryHolder get(){
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public class Container{
|
||||
// Contains the position and block lists!
|
||||
public Vector3 Pos1;
|
||||
public Vector3 Pos2;
|
||||
public List<StoredBlock> blocks;
|
||||
public ServerLevel lvl;
|
||||
|
||||
private int tick = 0;
|
||||
|
||||
public void tick(){
|
||||
this.tick--;
|
||||
}
|
||||
|
||||
public boolean isExpired(){
|
||||
if(tick <= 0){
|
||||
return true;
|
||||
}else return false;
|
||||
}
|
||||
|
||||
public Container(){
|
||||
tick = 15000;
|
||||
Pos1 = OTEMod.ZERO_VECTOR;
|
||||
Pos2 = OTEMod.ZERO_VECTOR;
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
tick=15000;
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<UUID, Container> playerContainers = new HashMap<UUID,Container>();
|
||||
private Map<UUID, Container> playerContainers = new HashMap<UUID,Container>();
|
||||
private static final Lock lck = new ReentrantLock();
|
||||
|
||||
public static boolean hasPlayerCached(Player P)
|
||||
|
@ -31,20 +65,65 @@ public class MemoryHolder {
|
|||
try{
|
||||
|
||||
UUID id = P.getUUID();
|
||||
return playerContainers.containsKey(id);
|
||||
return get().playerContainers.containsKey(id);
|
||||
}finally{
|
||||
lck.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public static void tick()
|
||||
{
|
||||
lck.lock();
|
||||
try{
|
||||
Iterator<Map.Entry<UUID,Container>> imeuc = get().playerContainers.entrySet().iterator();
|
||||
while(imeuc.hasNext())
|
||||
{
|
||||
Map.Entry<UUID,Container> entry = imeuc.next();
|
||||
Container c = entry.getValue();
|
||||
c.tick();
|
||||
|
||||
if(c.isExpired()){
|
||||
imeuc.remove();
|
||||
|
||||
ChatServerOverride.broadcastTo(entry.getKey(), Component.literal(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!ZSchem Session expired")), c.lvl.getServer());
|
||||
}
|
||||
}
|
||||
}finally{
|
||||
lck.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private static void makeCachedPlayer(Player p){
|
||||
if(!hasPlayerCached(p)){
|
||||
|
||||
Container c = INSTANCE.new Container();
|
||||
get().playerContainers.put(p.getUUID(), c);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setPos1(Player p, Vector3 pos)
|
||||
{
|
||||
makeCachedPlayer(p);
|
||||
if(hasPlayerCached(p))
|
||||
{
|
||||
Container c = playerContainers.get(p.getUUID());
|
||||
Container c = get().playerContainers.get(p.getUUID());
|
||||
c.Pos1 = pos;
|
||||
c.reset();
|
||||
|
||||
playerContainers.put(p.getUUID(), c);
|
||||
get().playerContainers.put(p.getUUID(), c);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setLevel(Player p, ServerLevel lvl)
|
||||
{
|
||||
makeCachedPlayer(p);
|
||||
if(hasPlayerCached(p))
|
||||
{
|
||||
Container c = get().playerContainers.get(p.getUUID());
|
||||
c.lvl = lvl;
|
||||
c.reset();
|
||||
|
||||
get().playerContainers.put(p.getUUID(), c);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,29 +131,33 @@ public class MemoryHolder {
|
|||
{
|
||||
if(hasPlayerCached(p))
|
||||
{
|
||||
playerContainers.remove(p.getUUID());
|
||||
get().playerContainers.remove(p.getUUID());
|
||||
}
|
||||
}
|
||||
|
||||
public static void setPos2(Player p, Vector3 pos)
|
||||
{
|
||||
makeCachedPlayer(p);
|
||||
if(hasPlayerCached(p))
|
||||
{
|
||||
Container c = playerContainers.get(p.getUUID());
|
||||
Container c = get().playerContainers.get(p.getUUID());
|
||||
c.Pos2 = pos;
|
||||
c.reset();
|
||||
|
||||
playerContainers.put(p.getUUID(), c);
|
||||
get().playerContainers.put(p.getUUID(), c);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBlocks(Player p, List<StoredBlock> blk)
|
||||
{
|
||||
makeCachedPlayer(p);
|
||||
if(hasPlayerCached(p))
|
||||
{
|
||||
Container c = playerContainers.get(p.getUUID());
|
||||
Container c = get().playerContainers.get(p.getUUID());
|
||||
c.blocks=blk;
|
||||
c.reset();
|
||||
|
||||
playerContainers.put(p.getUUID(), c);
|
||||
get().playerContainers.put(p.getUUID(), c);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,14 +165,14 @@ public class MemoryHolder {
|
|||
{
|
||||
if(hasPlayerCached(p))
|
||||
{
|
||||
return playerContainers.get(p.getUUID()).blocks;
|
||||
return get().playerContainers.get(p.getUUID()).blocks;
|
||||
}else return new ArrayList<StoredBlock>();
|
||||
}
|
||||
|
||||
public static Container get(Player p)
|
||||
public static Container getContainer(Player p)
|
||||
{
|
||||
if(hasPlayerCached(p)){
|
||||
return playerContainers.get(p.getUUID());
|
||||
return get().playerContainers.get(p.getUUID());
|
||||
}else return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,17 @@ public class StoredBlock
|
|||
private int tries;
|
||||
|
||||
|
||||
public void setPosition(Vector3 pos)
|
||||
{
|
||||
position.Position=pos;
|
||||
}
|
||||
|
||||
public void updateWorld(ServerLevel lv)
|
||||
{
|
||||
position = new WorldPosition(position.Position, lv);
|
||||
}
|
||||
|
||||
|
||||
public void tick(){
|
||||
this.tick--;
|
||||
}
|
||||
|
@ -37,6 +48,11 @@ public class StoredBlock
|
|||
return tick <= 0;
|
||||
}
|
||||
|
||||
public void replaceBlockState(BlockState state)
|
||||
{
|
||||
this.state=state;
|
||||
}
|
||||
|
||||
|
||||
public StoredBlock(final BlockPos pos, final BlockState toSave, final ServerLevel lvl)
|
||||
{
|
||||
|
|
|
@ -54,6 +54,13 @@ public class WorldProp implements Supplier<Object>
|
|||
}
|
||||
}
|
||||
|
||||
public void customEnqueue(StoredBlock sb)
|
||||
{
|
||||
int ticks = task.getNewLongestTick();
|
||||
sb.setTick(ticks);
|
||||
task.add(sb);
|
||||
}
|
||||
|
||||
private void addHeal(BlockPos p, BlockState s, Level w, int tick)
|
||||
{
|
||||
StoredBlock sb = new StoredBlock(p, s, (ServerLevel)w);
|
||||
|
|
Reference in a new issue