Begin to add vaults. Add RTP
This commit is contained in:
parent
b51cd270d4
commit
280b8dbde6
6 changed files with 312 additions and 1 deletions
|
@ -63,7 +63,7 @@ public class OTEMod
|
|||
public static MinecraftServer THE_SERVER;
|
||||
private static boolean ALIVE;
|
||||
|
||||
public static boolean DEVELOPER=true;
|
||||
public static boolean DEVELOPER=false;
|
||||
|
||||
public OTEMod()
|
||||
{
|
||||
|
|
|
@ -6,11 +6,13 @@ import dev.zontreck.otemod.commands.profilecmds.NameColorCommand;
|
|||
import dev.zontreck.otemod.commands.profilecmds.NickCommand;
|
||||
import dev.zontreck.otemod.commands.profilecmds.PrefixColorCommand;
|
||||
import dev.zontreck.otemod.commands.profilecmds.PrefixCommand;
|
||||
import dev.zontreck.otemod.commands.teleport.RTPCommand;
|
||||
import dev.zontreck.otemod.commands.teleport.TPACommand;
|
||||
import dev.zontreck.otemod.commands.teleport.TPAHereCommand;
|
||||
import dev.zontreck.otemod.commands.teleport.TPAcceptCommand;
|
||||
import dev.zontreck.otemod.commands.teleport.TPCancelCommand;
|
||||
import dev.zontreck.otemod.commands.teleport.TPDenyCommand;
|
||||
import dev.zontreck.otemod.commands.vaults.VaultCommand;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
@ -40,6 +42,10 @@ public class CommandRegistry {
|
|||
TPDenyCommand.register(ev.getDispatcher());
|
||||
TPAcceptCommand.register(ev.getDispatcher());
|
||||
TPAHereCommand.register(ev.getDispatcher());
|
||||
RTPCommand.register(ev.getDispatcher());
|
||||
|
||||
|
||||
VaultCommand.register(ev.getDispatcher());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
package dev.zontreck.otemod.commands.teleport;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.chat.ChatColor;
|
||||
import dev.zontreck.otemod.chat.ChatServerOverride;
|
||||
import dev.zontreck.otemod.containers.Vector3;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class RTPCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("rtp").executes(c->rtp(c.getSource())));
|
||||
|
||||
//executes(c -> doCancel(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 rtp(CommandSourceStack source) {
|
||||
ServerPlayer pla = source.getPlayer();
|
||||
TeleportContainer cont = new TeleportContainer(pla, null, source.getPlayer().getRotationVector(), source.getLevel());
|
||||
|
||||
Vector3 v = new Vector3();
|
||||
// RTP is not designed to be safe really, but we at least want to check if where we are putting the player is air
|
||||
|
||||
Vec3 pos = pla.position();
|
||||
|
||||
boolean found_place= false;
|
||||
|
||||
int tries=0;
|
||||
|
||||
while(!found_place){
|
||||
// Take our current position, and send us in a random direction
|
||||
Random rng = new Random((long) (pos.x+pos.y+pos.z));
|
||||
v.y = 500;
|
||||
v.x = rng.nextDouble(0xffff);
|
||||
v.z = rng.nextDouble(0xffff);
|
||||
|
||||
// Begin to scan for ground
|
||||
while(v.y != 0)
|
||||
{
|
||||
// check block above and below
|
||||
BlockState b = source.getLevel().getBlockState(new BlockPos(v.asMinecraftVector()));
|
||||
BlockState b2 = source.getLevel().getBlockState(new BlockPos(v.moveUp().asMinecraftVector()));
|
||||
BlockState b3 = source.getLevel().getBlockState(new BlockPos(v.moveDown().asMinecraftVector()));
|
||||
Block bx = b.getBlock();
|
||||
|
||||
if(b.isAir()){
|
||||
if(b2.isAir()){
|
||||
if(!b3.isAir()){
|
||||
found_place = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
v =v.moveDown();
|
||||
|
||||
}
|
||||
if(tries>=5)
|
||||
{
|
||||
// Aborting RTP
|
||||
ChatServerOverride.broadcastTo(pla.getUUID(), Component.literal(ChatColor.DARK_RED+"Could not find a suitable location after 5 tries. Giving up on RTP"), source.getServer());
|
||||
return 0;
|
||||
}
|
||||
tries++;
|
||||
}
|
||||
|
||||
ChatServerOverride.broadcastTo(pla.getUUID(), Component.literal(ChatColor.DARK_GRAY + "["+ChatColor.DARK_GREEN + "OTEMOD" + ChatColor.DARK_GRAY + "] "+ChatColor.DARK_PURPLE+" A suitable location has been found. Wormhole opening now!"), source.getServer());
|
||||
|
||||
// Apply the effect
|
||||
TeleportActioner.ApplyTeleportEffect(pla);
|
||||
cont.Position=v.asMinecraftVector();
|
||||
|
||||
TeleportActioner.PerformTeleport(cont);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int doCancel(CommandSourceStack source, String TPID) {
|
||||
UUID teleporter = UUID.fromString(TPID);
|
||||
for(TeleportContainer cont : OTEMod.TeleportRegistry){
|
||||
if(cont.TeleportID.equals(teleporter)){
|
||||
// Accepting!
|
||||
|
||||
ServerPlayer from = source.getServer().getPlayerList().getPlayer(cont.FromPlayer);
|
||||
ServerPlayer to = source.getServer().getPlayerList().getPlayer(cont.ToPlayer);
|
||||
|
||||
Component comp = Component.literal(ChatColor.DARK_GRAY + "["+ ChatColor.DARK_GREEN+ "OTEMOD" + ChatColor.DARK_GRAY+"] " + ChatColor.DARK_PURPLE+"Teleport request was accepted. Opening wormhole!");
|
||||
|
||||
ChatServerOverride.broadcastTo(cont.FromPlayer, comp, source.getServer());
|
||||
ChatServerOverride.broadcastTo(cont.ToPlayer, comp, source.getServer());
|
||||
|
||||
OTEMod.TeleportRegistry.remove(cont);
|
||||
|
||||
|
||||
cont.PlayerInst = from;
|
||||
cont.Position = to.position();
|
||||
cont.Rotation = to.getRotationVector();
|
||||
cont.Dimension = to.getLevel();
|
||||
|
||||
TeleportActioner.ApplyTeleportEffect(from);
|
||||
TeleportActioner.PerformTeleport(cont);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Component comp = Component.literal(ChatColor.DARK_RED+"The teleport was not found, perhaps the request expired or was already cancelled/denied");
|
||||
|
||||
ChatServerOverride.broadcastTo(source.getPlayer().getUUID(), comp, source.getServer());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package dev.zontreck.otemod.commands.vaults;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
|
||||
import dev.zontreck.otemod.chat.ChatColor;
|
||||
import dev.zontreck.otemod.chat.ChatServerOverride;
|
||||
import dev.zontreck.otemod.containers.VaultContainer;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
public class VaultCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("pv").executes(c-> vault(c.getSource(), 0)).then(Commands.argument("number", IntegerArgumentType.integer()).executes(c -> vault(c.getSource(), IntegerArgumentType.getInteger(c, "number")))));
|
||||
dispatcher.register(Commands.literal("vault").executes(c-> vault(c.getSource(), 0)).then(Commands.argument("number", IntegerArgumentType.integer()).executes(c -> vault(c.getSource(), IntegerArgumentType.getInteger(c, "number")))));
|
||||
|
||||
//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 vault(CommandSourceStack source, int i) {
|
||||
VaultContainer cont = new VaultContainer(i, source.getPlayer().getUUID());
|
||||
cont.startOpen(source.getPlayer());
|
||||
|
||||
ChatServerOverride.broadcastTo(source.getPlayer().getUUID(), Component.literal(ChatColor.DARK_RED + "Vaults are not yet implemented"), source.getServer());
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package dev.zontreck.otemod.containers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class VaultContainer implements Container
|
||||
{
|
||||
public int VaultID;
|
||||
public UUID VaultOwner;
|
||||
public ItemStack[] Contents=new ItemStack[64];
|
||||
|
||||
public VaultContainer(int num, UUID owner)
|
||||
{
|
||||
VaultID = num;
|
||||
VaultOwner = owner;
|
||||
Contents = new ItemStack[64];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContent() {
|
||||
for(int i=0; i< Contents.length; i++)
|
||||
{
|
||||
Contents[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContainerSize() {
|
||||
return 64; // Double chest
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
for(ItemStack is : Contents)
|
||||
{
|
||||
if(is == null)continue;
|
||||
else return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int p_18941_) {
|
||||
return Contents[p_18941_];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItem(int p_18942_, int p_18943_) {
|
||||
// TODO debug this!
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItemNoUpdate(int p_18951_) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int p_18944_, ItemStack p_18945_) {
|
||||
Contents[p_18944_] = p_18945_;
|
||||
setChanged(); // mark the contents to be uploaded to the server
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChanged() {
|
||||
// Enqueue upload to the database
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player p_18946_) {
|
||||
return true; // The inventory is always valid for this container type. There is no circumstance where the container could be destroyed.
|
||||
}
|
||||
|
||||
public void downloadContentsToChest(Vec3 pos)
|
||||
{
|
||||
// Player is standing on a chest and wants us to download the vault into the chest.
|
||||
// TODO
|
||||
}
|
||||
|
||||
}
|
53
src/main/java/dev/zontreck/otemod/containers/Vector3.java
Normal file
53
src/main/java/dev/zontreck/otemod/containers/Vector3.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
package dev.zontreck.otemod.containers;
|
||||
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class Vector3
|
||||
{
|
||||
public double x;
|
||||
public double y;
|
||||
public double z;
|
||||
|
||||
public Vec3 asMinecraftVector(){
|
||||
return new Vec3(x, y, z);
|
||||
}
|
||||
|
||||
public Vector3()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Vector3(double x, double y, double z)
|
||||
{
|
||||
this.x=x;
|
||||
this.y=y;
|
||||
this.z=z;
|
||||
}
|
||||
|
||||
public Vector3(Vec3 pos)
|
||||
{
|
||||
x=pos.x;
|
||||
y=pos.y;
|
||||
z=pos.z;
|
||||
}
|
||||
|
||||
public Vector3 moveUp()
|
||||
{
|
||||
Vector3 up = Clone();
|
||||
up.y+=1;
|
||||
return up;
|
||||
}
|
||||
public Vector3 moveDown()
|
||||
{
|
||||
Vector3 up = Clone();
|
||||
up.y-=1;
|
||||
return up;
|
||||
}
|
||||
|
||||
|
||||
public Vector3 Clone()
|
||||
{
|
||||
Vector3 n = new Vector3(x, y, z);
|
||||
return n;
|
||||
}
|
||||
}
|
Reference in a new issue