minor fixes/improvements

This commit is contained in:
dfsek 2021-01-09 22:26:39 -07:00
parent 9fbe117f78
commit a5dd4a63d1
5 changed files with 22 additions and 79 deletions

View File

@ -13,7 +13,6 @@ import com.dfsek.terra.api.structures.script.TerraImplementationArguments;
import com.dfsek.terra.api.structures.structure.RotationUtil;
import com.dfsek.terra.api.structures.structure.buffer.items.BufferedEntity;
import com.dfsek.terra.api.structures.tokenizer.Position;
import net.jafama.FastMath;
public class EntityFunction implements Function<Void> {
private final EntityType data;
@ -37,7 +36,7 @@ public class EntityFunction implements Function<Void> {
RotationUtil.rotateVector(xz, arguments.getRotation());
arguments.getBuffer().addItem(new BufferedEntity(data), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).intValue(), FastMath.roundToInt(xz.getZ())).toLocation(arguments.getBuffer().getOrigin().getWorld()));
arguments.getBuffer().addItem(new BufferedEntity(data), new Vector3(xz.getX(), y.apply(implementationArguments).doubleValue(), xz.getZ()).toLocation(arguments.getBuffer().getOrigin().getWorld()));
return null;
}

View File

@ -13,6 +13,6 @@ public class BufferedEntity implements BufferedItem {
@Override
public void paste(Location origin) {
origin.getWorld().spawnEntity(origin, type);
origin.clone().add(0.5, 0, 0.5).getWorld().spawnEntity(origin, type);
}
}

View File

@ -40,7 +40,7 @@ public class LoadCommand extends PlayerCommand implements DebugCommand {
@Override
public List<com.dfsek.terra.bukkit.command.Command> getSubCommands() {
return Arrays.asList(new LoadRawCommand(this), new LoadFullCommand(this, true), new LoadFullCommand(this, false));
return Arrays.asList(new LoadFullCommand(this, true), new LoadFullCommand(this, false));
}
@Override

View File

@ -1,6 +1,8 @@
package com.dfsek.terra.bukkit.command.command.structure.load;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.structures.script.StructureScript;
import com.dfsek.terra.api.structures.structure.Rotation;
import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.bukkit.command.DebugCommand;
@ -30,11 +32,22 @@ public class LoadFullCommand extends LoadCommand implements DebugCommand {
TerraWorld terraWorld = getMain().getWorld(BukkitAdapter.adapt(sender.getWorld()));
long t = System.nanoTime();
FastRandom chunk = PopulationUtil.getRandom(new BukkitChunk(sender.getLocation().getChunk()));
Rotation r;
try {
r = Rotation.fromDegrees(Integer.parseInt(args[1]));
} catch(Exception e) {
sender.sendMessage("Invalid rotation: " + args[1]);
return true;
}
StructureScript script = terraWorld.getConfig().getScriptRegistry().get(args[0]);
if(script == null) {
sender.sendMessage("Invalid structure: " + args[0]);
return true;
}
if(this.chunk) {
terraWorld.getConfig().getScriptRegistry().get(args[0]).execute(BukkitAdapter.adapt(sender.getLocation()), BukkitAdapter.adapt(sender.getLocation().getChunk()), chunk, Rotation.fromDegrees(90 * chunk.nextInt(4)));
script.execute(BukkitAdapter.adapt(sender.getLocation()), BukkitAdapter.adapt(sender.getLocation().getChunk()), chunk, r);
} else {
terraWorld.getConfig().getScriptRegistry().get(args[0]).execute(BukkitAdapter.adapt(sender.getLocation()), chunk, Rotation.fromDegrees(90 * chunk.nextInt(4)));
script.execute(BukkitAdapter.adapt(sender.getLocation()), chunk, r);
}
long l = System.nanoTime() - t;
@ -59,9 +72,11 @@ public class LoadFullCommand extends LoadCommand implements DebugCommand {
@Override
public List<String> getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] args) {
World w = BukkitAdapter.adapt(((Player) commandSender).getWorld());
if(!TerraWorld.isTerraWorld(w)) return Collections.emptyList();
switch(args.length) {
case 1:
return Collections.emptyList(); //getStructureNames().stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList());
return getMain().getWorld(w).getConfig().getScriptRegistry().entries().stream().map(StructureScript::getId).collect(Collectors.toList());
case 2:
return Stream.of("0", "90", "180", "270").filter(string -> string.toUpperCase().startsWith(args[1].toUpperCase())).collect(Collectors.toList());
}

View File

@ -1,71 +0,0 @@
package com.dfsek.terra.bukkit.command.command.structure.load;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.structures.structure.Rotation;
import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.bukkit.command.DebugCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.util.PopulationUtil;
import org.bukkit.block.Sign;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class LoadRawCommand extends LoadCommand implements DebugCommand {
public LoadRawCommand(com.dfsek.terra.bukkit.command.Command parent) {
super(parent);
}
private static void setTerraSign(Sign sign, String data) {
sign.setLine(0, "[TERRA]");
if(data.length() > 16) {
sign.setLine(2, data.substring(0, 16));
sign.setLine(3, data.substring(16));
} else sign.setLine(2, data);
}
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
TerraWorld terraWorld = getMain().getWorld(BukkitAdapter.adapt(sender.getWorld()));
long t = System.nanoTime();
FastRandom chunk = PopulationUtil.getRandom(BukkitAdapter.adapt(sender.getLocation().getChunk()));
boolean success = terraWorld.getConfig().getScriptRegistry().get(args[0]).execute(BukkitAdapter.adapt(sender.getLocation()), chunk, Rotation.fromDegrees(90 * chunk.nextInt(4)));
long l = System.nanoTime() - t;
sender.sendMessage("Took " + ((double) l) / 1000000 + "ms. Success: " + success);
return true;
}
@Override
public String getName() {
return "raw";
}
@Override
public List<com.dfsek.terra.bukkit.command.Command> getSubCommands() {
return Collections.emptyList();
}
@Override
public int arguments() {
return 1;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] args) {
if(args.length == 1) {
return getStructureNames(BukkitAdapter.adapt(((Player) commandSender).getWorld())).stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList());
}
return Collections.emptyList();
}
}