move clipboard classes

This commit is contained in:
Sen 2025-05-13 17:19:40 +02:00
parent 6e77090c5b
commit a3e8566ca2
12 changed files with 23 additions and 23 deletions

View file

@ -86,6 +86,8 @@ import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import server.clipboard.ReorderRegistry;
import server.clipboard.RotationRegistry;
import server.command.CommandEnvironment;
import server.command.FixedExecutor;
import server.network.HandshakeHandler;
@ -142,6 +144,8 @@ public final class Server implements IThreadListener {
public static void main(String[] args) {
Util.checkOs();
Registry.setup("Server thread");
RotationRegistry.register();
ReorderRegistry.register();
boolean debug = System.getProperty("server.debug", null) != null;
boolean ipc = System.getProperty("server.pipe", null) != null;
int port = Integer.parseInt(System.getProperty("server.port", "" + Config.PORT));

View file

@ -0,0 +1,111 @@
package server.clipboard;
public class BlockTransform {
private double m00, m01, m02, m03;
private double m10, m11, m12, m13;
private double m20, m21, m22, m23;
public BlockTransform() {
m00 = m11 = m22 = 1;
m01 = m02 = m03 = 0;
m10 = m12 = m13 = 0;
m20 = m21 = m23 = 0;
}
private BlockTransform(double xx, double yx, double zx, double tx,
double xy, double yy, double zy, double ty, double xz, double yz,
double zz, double tz) {
m00 = xx;
m01 = yx;
m02 = zx;
m03 = tx;
m10 = xy;
m11 = yy;
m12 = zy;
m13 = ty;
m20 = xz;
m21 = yz;
m22 = zz;
m23 = tz;
}
private BlockTransform concatenate(BlockTransform that) {
double n00 = m00 * that.m00 + m01 * that.m10 + m02 * that.m20;
double n01 = m00 * that.m01 + m01 * that.m11 + m02 * that.m21;
double n02 = m00 * that.m02 + m01 * that.m12 + m02 * that.m22;
double n03 = m00 * that.m03 + m01 * that.m13 + m02 * that.m23 + m03;
double n10 = m10 * that.m00 + m11 * that.m10 + m12 * that.m20;
double n11 = m10 * that.m01 + m11 * that.m11 + m12 * that.m21;
double n12 = m10 * that.m02 + m11 * that.m12 + m12 * that.m22;
double n13 = m10 * that.m03 + m11 * that.m13 + m12 * that.m23 + m13;
double n20 = m20 * that.m00 + m21 * that.m10 + m22 * that.m20;
double n21 = m20 * that.m01 + m21 * that.m11 + m22 * that.m21;
double n22 = m20 * that.m02 + m21 * that.m12 + m22 * that.m22;
double n23 = m20 * that.m03 + m21 * that.m13 + m22 * that.m23 + m23;
return new BlockTransform(
n00, n01, n02, n03,
n10, n11, n12, n13,
n20, n21, n22, n23);
}
public BlockTransform rotateY(int theta) {
double cot = dCos(theta);
double sit = dSin(theta);
return concatenate(
new BlockTransform(
cot, 0, sit, 0,
0, 1, 0, 0,
-sit, 0, cot, 0));
}
public BlockTransform scale(Vector vec) {
return concatenate(new BlockTransform(vec.getX(), 0, 0, 0, 0, vec.getY(), 0, 0, 0, 0, vec.getZ(), 0));
}
public Vector apply(Vector vector) {
return new Vector(
vector.getX() * m00 + vector.getY() * m01 + vector.getZ() * m02 + m03,
vector.getX() * m10 + vector.getY() * m11 + vector.getZ() * m12 + m13,
vector.getX() * m20 + vector.getY() * m21 + vector.getZ() * m22 + m23);
}
private static double dSin(int degrees) {
if (degrees % 90 == 0) {
degrees %= 360;
if (degrees < 0) {
degrees += 360;
}
switch (degrees) {
case 0:
return 0.0;
case 90:
return 1.0;
case 180:
return 0.0;
case 270:
return -1.0;
}
}
return Math.cos(Math.toRadians(degrees));
}
private static double dCos(int degrees) {
if (degrees % 90 == 0) {
degrees %= 360;
if (degrees < 0) {
degrees += 360;
}
switch (degrees) {
case 0:
return 1.0;
case 90:
return 0.0;
case 180:
return -1.0;
case 270:
return 0.0;
}
}
return Math.cos(Math.toRadians(degrees));
}
}

View file

@ -0,0 +1,33 @@
package server.clipboard;
import common.nbt.NBTTagCompound;
import common.tileentity.TileEntity;
import common.world.State;
public class ClipboardBlock {
private State state;
private NBTTagCompound nbt;
public ClipboardBlock(State state) {
this.state = state;
}
public ClipboardBlock(State data, TileEntity tile) {
this(data);
NBTTagCompound tag = new NBTTagCompound();
tile.writeToNBT(tag);
this.nbt = tag;
}
public State getState() {
return this.state;
}
public void setState(State state) {
this.state = state;
}
public NBTTagCompound getNbtData() {
return this.nbt;
}
}

View file

@ -12,10 +12,8 @@ import common.block.Block;
import common.block.BlockDoor;
import common.block.BlockRailBase;
import common.block.ITileEntityProvider;
import common.clipboard.ClipboardBlock;
import common.collect.Lists;
import common.init.Blocks;
import common.init.ReorderRegistry;
import common.inventory.IInventory;
import common.tileentity.TileEntity;
import common.util.BlockPos;

View file

@ -0,0 +1,228 @@
package server.clipboard;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import common.block.Block;
import common.block.BlockBed;
import common.block.BlockDoor;
import common.color.DyeColor;
import common.init.BlockRegistry;
import common.init.Blocks;
import common.init.WoodType;
import common.util.Facing;
import common.util.Vec3i;
import common.world.State;
public abstract class ReorderRegistry {
private static final Set<Block> PLACE_LAST = new HashSet<Block>();
private static final Set<Block> PLACE_FINAL = new HashSet<Block>();
private static final Map<State, Vec3i> STATE_ATTACH = new HashMap<State, Vec3i>();
private static final Map<Block, Vec3i> BLOCK_ATTACH = new HashMap<Block, Vec3i>();
public static boolean shouldPlaceLast(Block id) {
return PLACE_LAST.contains(id);
}
public static boolean shouldPlaceFinal(Block id) {
return PLACE_FINAL.contains(id) || id instanceof BlockDoor;
}
public static Vec3i getAttachment(State state) {
Vec3i direction = BLOCK_ATTACH.get(state.getBlock());
if (direction != null) return direction;
return STATE_ATTACH.get(state);
}
public static void register() {
for(WoodType wood : WoodType.values()) {
PLACE_LAST.add(BlockRegistry.getRegisteredBlock(wood.getName() + "_sapling"));
}
// PLACE_LAST.add(Blocks.bed);
for(DyeColor color : BlockBed.COLORS) {
PLACE_LAST.add(BlockRegistry.getRegisteredBlock(color.getName() + "_bed"));
}
PLACE_LAST.add(Blocks.golden_rail);
PLACE_LAST.add(Blocks.detector_rail);
PLACE_LAST.add(Blocks.tallgrass);
PLACE_LAST.add(Blocks.deadbush);
PLACE_LAST.add(Blocks.piston_head);
PLACE_LAST.add(Blocks.flower);
PLACE_LAST.add(Blocks.brown_mushroom);
PLACE_LAST.add(Blocks.red_mushroom_block);
PLACE_LAST.add(Blocks.torch);
PLACE_LAST.add(Blocks.fire);
PLACE_LAST.add(Blocks.redstone);
PLACE_LAST.add(Blocks.wheat);
PLACE_LAST.add(Blocks.ladder);
PLACE_LAST.add(Blocks.rail);
PLACE_LAST.add(Blocks.lever);
PLACE_LAST.add(Blocks.stone_pressure_plate);
PLACE_LAST.add(Blocks.wooden_pressure_plate);
PLACE_LAST.add(Blocks.unlit_redstone_torch);
PLACE_LAST.add(Blocks.redstone_torch);
PLACE_LAST.add(Blocks.stone_button);
PLACE_LAST.add(Blocks.snow_layer);
PLACE_LAST.add(Blocks.portal);
PLACE_LAST.add(Blocks.repeater);
PLACE_LAST.add(Blocks.powered_repeater);
PLACE_LAST.add(Blocks.trapdoor);
PLACE_LAST.add(Blocks.vine);
PLACE_LAST.add(Blocks.waterlily);
PLACE_LAST.add(Blocks.soul_wart);
PLACE_LAST.add(Blocks.piston);
PLACE_LAST.add(Blocks.sticky_piston);
PLACE_LAST.add(Blocks.piston_head);
PLACE_LAST.add(Blocks.piston_extension);
PLACE_LAST.add(Blocks.cocoa);
PLACE_LAST.add(Blocks.tripwire_hook);
PLACE_LAST.add(Blocks.string);
PLACE_LAST.add(Blocks.flower_pot);
PLACE_LAST.add(Blocks.carrot);
PLACE_LAST.add(Blocks.potato);
PLACE_LAST.add(Blocks.wooden_button);
PLACE_LAST.add(Blocks.anvil); // becomes relevant with asynchronous placement
PLACE_LAST.add(Blocks.light_weighted_pressure_plate);
PLACE_LAST.add(Blocks.heavy_weighted_pressure_plate);
PLACE_LAST.add(Blocks.comparator);
PLACE_LAST.add(Blocks.powered_comparator);
PLACE_LAST.add(Blocks.activator_rail);
PLACE_LAST.add(Blocks.iron_trapdoor);
PLACE_LAST.add(Blocks.carpet);
PLACE_LAST.add(Blocks.double_plant);
PLACE_LAST.add(Blocks.daylight_detector_inverted);
// shouldPlaceLast.add(Blocks.daylight_detector);
PLACE_LAST.add(Blocks.blue_mushroom);
PLACE_LAST.add(Blocks.red_button);
}
static {
PLACE_FINAL.add(Blocks.sign);
PLACE_FINAL.add(Blocks.wall_sign);
PLACE_FINAL.add(Blocks.cactus);
PLACE_FINAL.add(Blocks.reeds);
PLACE_FINAL.add(Blocks.cake);
PLACE_FINAL.add(Blocks.piston_head);
PLACE_FINAL.add(Blocks.piston_extension);
PLACE_FINAL.add(Blocks.banner);
PLACE_FINAL.add(Blocks.wall_banner);
}
private static void addAttach(State state, Facing dir) {
STATE_ATTACH.put(state, dir.getDirectionVec());
}
private static void addAttach(Block block, Facing dir) {
BLOCK_ATTACH.put(block, dir.getDirectionVec());
}
private static void addCardinals(Block type, int west, int north, int east, int south) {
addAttach(type.getStateFromMeta(west), Facing.WEST);
addAttach(type.getStateFromMeta(north), Facing.NORTH);
addAttach(type.getStateFromMeta(east), Facing.EAST);
addAttach(type.getStateFromMeta(south), Facing.SOUTH);
}
static {
for(WoodType wood : WoodType.values()) {
addAttach(BlockRegistry.getRegisteredBlock(wood.getName() + "_sapling"), Facing.DOWN);
}
addAttach(Blocks.tallgrass, Facing.DOWN);
addAttach(Blocks.deadbush, Facing.DOWN);
for (int offset = 0; offset < 16; offset += 8) {
addAttach(Blocks.piston_head.getStateFromMeta(offset + 0), Facing.UP);
addAttach(Blocks.piston_head.getStateFromMeta(offset + 1), Facing.DOWN);
addCardinals(Blocks.piston_head, offset + 2, offset + 5, offset + 3, offset + 4);
}
addAttach(Blocks.flower, Facing.DOWN);
addAttach(Blocks.brown_mushroom, Facing.DOWN);
addAttach(Blocks.red_mushroom, Facing.DOWN);
for (Block blockId : new Block[] { Blocks.torch, Blocks.redstone_torch, Blocks.unlit_redstone_torch }) {
addAttach(blockId.getStateFromMeta(0), Facing.DOWN);
addAttach(blockId.getStateFromMeta(5), Facing.DOWN); // According to the wiki, this one is history. Keeping both, for now...
addCardinals(blockId, 4, 1, 3, 2);
}
addAttach(Blocks.redstone, Facing.DOWN);
addAttach(Blocks.wheat, Facing.DOWN);
addAttach(Blocks.sign, Facing.DOWN);
addCardinals(Blocks.ladder, 2, 5, 3, 4);
addCardinals(Blocks.wall_sign, 2, 5, 3, 4);
for (int offset = 0; offset < 16; offset += 8) {
addCardinals(Blocks.lever, offset + 4, offset + 1, offset + 3, offset + 2);
addAttach(Blocks.lever.getStateFromMeta(offset + 5), Facing.DOWN);
addAttach(Blocks.lever.getStateFromMeta(offset + 6), Facing.DOWN);
addAttach(Blocks.lever.getStateFromMeta(offset + 7), Facing.UP);
addAttach(Blocks.lever.getStateFromMeta(offset + 0), Facing.UP);
}
addAttach(Blocks.stone_pressure_plate, Facing.DOWN);
addAttach(Blocks.iron_door, Facing.DOWN);
addAttach(Blocks.wooden_pressure_plate, Facing.DOWN);
// redstone torches: see torches
for (int offset = 0; offset < 16; offset += 8) {
addCardinals(Blocks.stone_button, offset + 4, offset + 1, offset + 3, offset + 2);
addCardinals(Blocks.wooden_button, offset + 4, offset + 1, offset + 3, offset + 2);
addCardinals(Blocks.red_button, offset + 4, offset + 1, offset + 3, offset + 2);
}
addAttach(Blocks.stone_button.getStateFromMeta(0), Facing.UP);
addAttach(Blocks.stone_button.getStateFromMeta(5), Facing.DOWN);
addAttach(Blocks.wooden_button.getStateFromMeta(0), Facing.UP);
addAttach(Blocks.wooden_button.getStateFromMeta(5), Facing.DOWN);
addAttach(Blocks.red_button.getStateFromMeta(0), Facing.UP);
addAttach(Blocks.red_button.getStateFromMeta(5), Facing.DOWN);
addAttach(Blocks.cactus, Facing.DOWN);
addAttach(Blocks.reeds, Facing.DOWN);
addAttach(Blocks.cake, Facing.DOWN);
addAttach(Blocks.repeater, Facing.DOWN);
addAttach(Blocks.powered_repeater, Facing.DOWN);
for (int offset = 0; offset < 16; offset += 4) {
addCardinals(Blocks.trapdoor, offset + 0, offset + 3, offset + 1, offset + 2);
addCardinals(Blocks.iron_trapdoor, offset + 0, offset + 3, offset + 1, offset + 2);
}
addAttach(Blocks.pumpkin_stem, Facing.DOWN);
addAttach(Blocks.melon_stem, Facing.DOWN);
// vines are complicated, but I'll list the single-attachment variants anyway
addAttach(Blocks.vine.getStateFromMeta(0), Facing.UP);
addCardinals(Blocks.vine, 1, 2, 4, 8);
addAttach(Blocks.soul_wart, Facing.DOWN);
for (int offset = 0; offset < 16; offset += 4) {
addCardinals(Blocks.cocoa, offset + 0, offset + 1, offset + 2, offset + 3);
}
for (int offset = 0; offset < 16; offset += 4) {
addCardinals(Blocks.tripwire_hook, offset + 2, offset + 3, offset + 0, offset + 1);
}
addAttach(Blocks.string, Facing.DOWN);
addAttach(Blocks.flower_pot, Facing.DOWN);
addAttach(Blocks.carrot, Facing.DOWN);
addAttach(Blocks.potato, Facing.DOWN);
addAttach(Blocks.anvil, Facing.DOWN);
addAttach(Blocks.light_weighted_pressure_plate, Facing.DOWN);
addAttach(Blocks.heavy_weighted_pressure_plate, Facing.DOWN);
addAttach(Blocks.comparator, Facing.DOWN);
addAttach(Blocks.powered_comparator, Facing.DOWN);
addAttach(Blocks.carpet, Facing.DOWN);
addAttach(Blocks.double_plant, Facing.DOWN);
addAttach(Blocks.banner, Facing.DOWN);
addCardinals(Blocks.wall_banner, 4, 2, 5, 3);
addAttach(Blocks.oak_door, Facing.DOWN);
addAttach(Blocks.spruce_door, Facing.DOWN);
addAttach(Blocks.birch_door, Facing.DOWN);
addAttach(Blocks.jungle_door, Facing.DOWN);
addAttach(Blocks.acacia_door, Facing.DOWN);
addAttach(Blocks.dark_oak_door, Facing.DOWN);
addAttach(Blocks.cherry_door, Facing.DOWN);
addAttach(Blocks.maple_door, Facing.DOWN);
// Rails are hardcoded to be attached to the block below them.
// In addition to that, let's attach ascending rails to the block they're ascending towards.
for (int offset = 0; offset < 16; offset += 8) {
addCardinals(Blocks.golden_rail, offset + 3, offset + 4, offset + 2, offset + 5);
addCardinals(Blocks.detector_rail, offset + 3, offset + 4, offset + 2, offset + 5);
addCardinals(Blocks.rail, offset + 3, offset + 4, offset + 2, offset + 5);
addCardinals(Blocks.activator_rail, offset + 3, offset + 4, offset + 2, offset + 5);
}
addAttach(Blocks.blue_mushroom, Facing.DOWN);
}
}

View file

@ -0,0 +1,43 @@
package server.clipboard;
import java.util.function.Predicate;
public class Rotation {
private final RotationValue[] values;
private final boolean[] dirFlags = new boolean[16];
public Rotation(RotationValue[] values, Predicate<Integer> predicate) {
this.values = values;
for(int z = 0; z < 16; z++) {
if(predicate != null && !predicate.test(z)) {
this.dirFlags[z] = false;
continue;
}
boolean flag = false;
for(RotationValue value : values) {
if(value.getDirection() != null) {
flag = true;
break;
}
}
this.dirFlags[z] = flag;
}
}
public RotationValue[] getValues() {
return this.values;
}
public RotationValue getValue(int meta) {
for (RotationValue value : this.values) {
if (value.isSet(meta)) {
return value;
}
}
return null;
}
public boolean hasDirection(int meta) {
return this.dirFlags[meta & 15];
}
}

View file

@ -0,0 +1,129 @@
package server.clipboard;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import common.block.Block;
import common.block.BlockDoor;
import common.block.BlockLever;
import common.block.BlockLog;
import common.block.BlockPortal;
import common.block.BlockQuartz;
import common.block.BlockRail;
import common.block.BlockRailBase;
import common.block.BlockRailDetector;
import common.block.BlockRailPowered;
import common.block.BlockRotatedPillar;
import common.collect.Lists;
import common.collect.Maps;
import common.properties.IProperty;
import common.properties.PropertyDirection;
import common.util.Facing;
import common.util.Vec3i;
import common.world.State;
public abstract class RotationRegistry {
private static final Map<Block, Rotation> MAP = new HashMap<Block, Rotation>();
public static void register() {
for(Block block : common.init.BlockRegistry.REGISTRY) {
for(IProperty<?> prop : block.getPropertyMap()) {
Predicate<Integer> predicate = null;
if(prop == BlockDoor.FACING) {
predicate = new Predicate<Integer>() {
@Override
public boolean test(Integer meta) {
return (meta & 8) == 0;
}
};
}
List<RotationValue> values = Lists.newArrayList();
Map<Object, Byte> map = Maps.newHashMap();
for(int z = 15; z >= 0; z--) {
State st = block.getStateFromMeta(z);
if(st.getProperties().containsKey(prop)) {
map.put(st.getProperties().get(prop), (byte)z);
}
}
byte mask = 0;
for(Object v : prop.getAllowedValues()) {
if(map.get(v) == null) {
continue;
}
mask |= map.get(v);
}
if(mask == 0) {
continue;
}
for(Object v : prop.getAllowedValues()) {
if(map.get(v) == null) {
continue;
}
Vec3i dv = null;
Facing.Axis axis = null;
if(prop instanceof PropertyDirection) {
dv = ((Facing)v).getDirectionVec();
}
else if(prop == BlockRotatedPillar.AXIS) {
axis = ((Facing.Axis)v);
}
else if(prop == BlockPortal.AXIS) {
axis = ((Facing.Axis)v);
}
else if(prop == BlockLog.LOG_AXIS) {
axis = ((BlockLog.EnumAxis)v).getAxis();
}
else if(prop == BlockQuartz.VARIANT) {
axis = ((BlockQuartz.EnumType)v).getAxis();
}
else if(prop == BlockLever.FACING) {
dv = ((BlockLever.EnumOrientation)v).getFacing().getDirectionVec();
}
else if(prop == BlockRail.SHAPE || prop == BlockRailDetector.SHAPE || prop == BlockRailPowered.SHAPE) {
dv = ((BlockRailBase.EnumRailDirection)v).getFacing().getDirectionVec();
}
// else if(prop == BlockDoor.HINGE) {
// dv = ((BlockDoor.EnumHingePosition)v) == BlockDoor.EnumHingePosition.LEFT ? new Vec3i(-1, 0, 0) : new Vec3i(1, 0, 0);
// }
if(axis != null) {
switch(axis) {
case X:
dv = new Vec3i(1, 0, 0);
break;
case Y:
dv = new Vec3i(0, 1, 0);
break;
case Z:
dv = new Vec3i(0, 0, 1);
break;
}
}
if(dv == null) {
continue;
}
values.add(new RotationValue(mask, (byte)(map.get(v) & mask), new Vector(dv.getX(), dv.getY(), dv.getZ())));
if(axis != null) {
values.add(new RotationValue(mask, (byte)(map.get(v) & mask), new Vector(-dv.getX(), -dv.getY(), -dv.getZ())));
}
}
if(!values.isEmpty()) {
int legacyId = common.init.BlockRegistry.getIdFromBlock(block);
Rotation state = new Rotation(values.toArray(new RotationValue[values.size()]), predicate);
// Log.CONFIG.debug("Block " + game.init.BlockRegistry.REGISTRY.getNameForObject(block) + "/" + legacyId + " mask = " + String.format("0x%x", mask));
// for(RotationValue value : values) {
// Log.CONFIG.debug(" meta " + value.data + " -> " + value.direction.toString());
// }
MAP.put(block, state);
}
}
}
}
public static Rotation getRotation(Block block) {
return MAP.get(block);
}
}

View file

@ -0,0 +1,25 @@
package server.clipboard;
public class RotationValue {
public final byte mask;
public final byte data;
public final Vector direction;
public RotationValue(byte mask, byte data, Vector direction) {
this.mask = mask;
this.data = data;
this.direction = direction;
}
public boolean isSet(int meta) {
return (meta & mask) == data;
}
public int set(int meta) {
return ((meta & ~mask) | data);
}
public Vector getDirection() {
return direction;
}
}

View file

@ -0,0 +1,802 @@
package server.clipboard;
public class Vector implements Comparable<Vector> {
public static final Vector ZERO = new Vector(0, 0, 0);
protected final double x, y, z;
public Vector(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
// /**
// * Construct an instance.
// *
// * @param x the X coordinate
// * @param y the Y coordinate
// * @param z the Z coordinate
// */
// public Vector(int x, int y, int z) {
// this.x = (double) x;
// this.y = (double) y;
// this.z = (double) z;
// }
// /**
// * Construct an instance.
// *
// * @param x the X coordinate
// * @param y the Y coordinate
// * @param z the Z coordinate
// */
// public Vector(float x, float y, float z) {
// this.x = (double) x;
// this.y = (double) y;
// this.z = (double) z;
// }
// /**
// * Copy another vector.
// *
// * @param other another vector to make a copy of
// */
// public Vector(Vector other) {
// this.x = other.x;
// this.y = other.y;
// this.z = other.z;
// }
/**
* Construct a new instance with X, Y, and Z coordinates set to 0.
*
* <p>One can also refer to a static {@link #ZERO}.</p>
*/
public Vector() {
this.x = 0;
this.y = 0;
this.z = 0;
}
/**
* Get the X coordinate.
*
* @return the x coordinate
*/
public double getX() {
return x;
}
/**
* Get the X coordinate rounded.
*
* @return the x coordinate
*/
public int getBlockX() {
return (int) Math.round(x);
}
// /**
// * Set the X coordinate.
// *
// * @param x the new X
// * @return a new vector
// */
// public Vector setX(double x) {
// return new Vector(x, y, z);
// }
// /**
// * Set the X coordinate.
// *
// * @param x the X coordinate
// * @return new vector
// */
// public Vector setX(int x) {
// return new Vector(x, y, z);
// }
/**
* Get the Y coordinate.
*
* @return the y coordinate
*/
public double getY() {
return y;
}
/**
* Get the Y coordinate rounded.
*
* @return the y coordinate
*/
public int getBlockY() {
return (int) Math.round(y);
}
// /**
// * Set the Y coordinate.
// *
// * @param y the new Y
// * @return a new vector
// */
// public Vector setY(double y) {
// return new Vector(x, y, z);
// }
// /**
// * Set the Y coordinate.
// *
// * @param y the new Y
// * @return a new vector
// */
// public Vector setY(int y) {
// return new Vector(x, y, z);
// }
/**
* Get the Z coordinate.
*
* @return the z coordinate
*/
public double getZ() {
return z;
}
/**
* Get the Z coordinate rounded.
*
* @return the z coordinate
*/
public int getBlockZ() {
return (int) Math.round(z);
}
// /**
// * Set the Z coordinate.
// *
// * @param z the new Z
// * @return a new vector
// */
// public Vector setZ(double z) {
// return new Vector(x, y, z);
// }
// /**
// * Set the Z coordinate.
// *
// * @param z the new Z
// * @return a new vector
// */
// public Vector setZ(int z) {
// return new Vector(x, y, z);
// }
// /**
// * Add another vector to this vector and return the result as a new vector.
// *
// * @param other the other vector
// * @return a new vector
// */
// public Vector add(Vector other) {
// return new Vector(x + other.x, y + other.y, z + other.z);
// }
// /**
// * Add another vector to this vector and return the result as a new vector.
// *
// * @param x the value to add
// * @param y the value to add
// * @param z the value to add
// * @return a new vector
// */
// public Vector add(double x, double y, double z) {
// return new Vector(this.x + x, this.y + y, this.z + z);
// }
// /**
// * Add another vector to this vector and return the result as a new vector.
// *
// * @param x the value to add
// * @param y the value to add
// * @param z the value to add
// * @return a new vector
// */
// public Vector add(int x, int y, int z) {
// return new Vector(this.x + x, this.y + y, this.z + z);
// }
// /**
// * Add a list of vectors to this vector and return the
// * result as a new vector.
// *
// * @param others an array of vectors
// * @return a new vector
// */
// public Vector add(Vector... others) {
// double newX = x, newY = y, newZ = z;
//
// for (Vector other : others) {
// newX += other.x;
// newY += other.y;
// newZ += other.z;
// }
//
// return new Vector(newX, newY, newZ);
// }
/**
* Subtract another vector from this vector and return the result
* as a new vector.
*
* @param other the other vector
* @return a new vector
*/
public Vector subtract(Vector other) {
return new Vector(x - other.x, y - other.y, z - other.z);
}
// /**
// * Subtract another vector from this vector and return the result
// * as a new vector.
// *
// * @param x the value to subtract
// * @param y the value to subtract
// * @param z the value to subtract
// * @return a new vector
// */
// public Vector subtract(double x, double y, double z) {
// return new Vector(this.x - x, this.y - y, this.z - z);
// }
// /**
// * Subtract another vector from this vector and return the result
// * as a new vector.
// *
// * @param x the value to subtract
// * @param y the value to subtract
// * @param z the value to subtract
// * @return a new vector
// */
// public Vector subtract(int x, int y, int z) {
// return new Vector(this.x - x, this.y - y, this.z - z);
// }
//
// /**
// * Subtract a list of vectors from this vector and return the result
// * as a new vector.
// *
// * @param others an array of vectors
// * @return a new vector
// */
// public Vector subtract(Vector... others) {
// double newX = x, newY = y, newZ = z;
//
// for (Vector other : others) {
// newX -= other.x;
// newY -= other.y;
// newZ -= other.z;
// }
//
// return new Vector(newX, newY, newZ);
// }
// /**
// * Multiply this vector by another vector on each component.
// *
// * @param other the other vector
// * @return a new vector
// */
// public Vector multiply(Vector other) {
// return new Vector(x * other.x, y * other.y, z * other.z);
// }
// /**
// * Multiply this vector by another vector on each component.
// *
// * @param x the value to multiply
// * @param y the value to multiply
// * @param z the value to multiply
// * @return a new vector
// */
// public Vector multiply(double x, double y, double z) {
// return new Vector(this.x * x, this.y * y, this.z * z);
// }
//
// /**
// * Multiply this vector by another vector on each component.
// *
// * @param x the value to multiply
// * @param y the value to multiply
// * @param z the value to multiply
// * @return a new vector
// */
// public Vector multiply(int x, int y, int z) {
// return new Vector(this.x * x, this.y * y, this.z * z);
// }
//
// /**
// * Multiply this vector by zero or more vectors on each component.
// *
// * @param others an array of vectors
// * @return a new vector
// */
// public Vector multiply(Vector... others) {
// double newX = x, newY = y, newZ = z;
//
// for (Vector other : others) {
// newX *= other.x;
// newY *= other.y;
// newZ *= other.z;
// }
//
// return new Vector(newX, newY, newZ);
// }
// /**
// * Perform scalar multiplication and return a new vector.
// *
// * @param n the value to multiply
// * @return a new vector
// */
// public Vector multiply(double n) {
// return new Vector(this.x * n, this.y * n, this.z * n);
// }
// /**
// * Perform scalar multiplication and return a new vector.
// *
// * @param n the value to multiply
// * @return a new vector
// */
// public Vector multiply(float n) {
// return new Vector(this.x * n, this.y * n, this.z * n);
// }
// /**
// * Perform scalar multiplication and return a new vector.
// *
// * @param n the value to multiply
// * @return a new vector
// */
// public Vector multiply(int n) {
// return new Vector(this.x * n, this.y * n, this.z * n);
// }
//
// /**
// * Divide this vector by another vector on each component.
// *
// * @param other the other vector
// * @return a new vector
// */
// public Vector divide(Vector other) {
// return new Vector(x / other.x, y / other.y, z / other.z);
// }
// /**
// * Divide this vector by another vector on each component.
// *
// * @param x the value to divide by
// * @param y the value to divide by
// * @param z the value to divide by
// * @return a new vector
// */
// public Vector divide(double x, double y, double z) {
// return new Vector(this.x / x, this.y / y, this.z / z);
// }
//
// /**
// * Divide this vector by another vector on each component.
// *
// * @param x the value to divide by
// * @param y the value to divide by
// * @param z the value to divide by
// * @return a new vector
// */
// public Vector divide(int x, int y, int z) {
// return new Vector(this.x / x, this.y / y, this.z / z);
// }
// /**
// * Perform scalar division and return a new vector.
// *
// * @param n the value to divide by
// * @return a new vector
// */
// public Vector divide(int n) {
// return new Vector(x / n, y / n, z / n);
// }
/**
* Perform scalar division and return a new vector.
*
* @param n the value to divide by
* @return a new vector
*/
public Vector divide(double n) {
return new Vector(x / n, y / n, z / n);
}
// /**
// * Perform scalar division and return a new vector.
// *
// * @param n the value to divide by
// * @return a new vector
// */
// public Vector divide(float n) {
// return new Vector(x / n, y / n, z / n);
// }
/**
* Get the length of the vector.
*
* @return length
*/
public double length() {
return Math.sqrt(x * x + y * y + z * z);
}
// /**
// * Get the length, squared, of the vector.
// *
// * @return length, squared
// */
// public double lengthSq() {
// return x * x + y * y + z * z;
// }
// /**
// * Get the distance between this vector and another vector.
// *
// * @param other the other vector
// * @return distance
// */
// public double distance(Vector other) {
// return Math.sqrt(Math.pow(other.x - x, 2) +
// Math.pow(other.y - y, 2) +
// Math.pow(other.z - z, 2));
// }
// /**
// * Get the distance between this vector and another vector, squared.
// *
// * @param other the other vector
// * @return distance
// */
// public double distanceSq(Vector other) {
// return Math.pow(other.x - x, 2) +
// Math.pow(other.y - y, 2) +
// Math.pow(other.z - z, 2);
// }
/**
* Get the normalized vector, which is the vector divided by its
* length, as a new vector.
*
* @return a new vector
*/
public Vector normalize() {
return divide(length());
}
/**
* Gets the dot product of this and another vector.
*
* @param other the other vector
* @return the dot product of this and the other vector
*/
public double dot(Vector other) {
return x * other.x + y * other.y + z * other.z;
}
// /**
// * Gets the cross product of this and another vector.
// *
// * @param other the other vector
// * @return the cross product of this and the other vector
// */
// public Vector cross(Vector other) {
// return new Vector(
// y * other.z - z * other.y,
// z * other.x - x * other.z,
// x * other.y - y * other.x
// );
// }
//
// /**
// * Checks to see if a vector is contained with another.
// *
// * @param min the minimum point (X, Y, and Z are the lowest)
// * @param max the maximum point (X, Y, and Z are the lowest)
// * @return true if the vector is contained
// */
// public boolean containedWithin(Vector min, Vector max) {
// return x >= min.x && x <= max.x && y >= min.y && y <= max.y && z >= min.z && z <= max.z;
// }
//
// /**
// * Checks to see if a vector is contained with another, comparing
// * using discrete comparisons, inclusively.
// *
// * @param min the minimum point (X, Y, and Z are the lowest)
// * @param max the maximum point (X, Y, and Z are the lowest)
// * @return true if the vector is contained
// */
// public boolean containedWithinBlock(Vector min, Vector max) {
// return getBlockX() >= min.getBlockX() && getBlockX() <= max.getBlockX()
// && getBlockY() >= min.getBlockY() && getBlockY() <= max.getBlockY()
// && getBlockZ() >= min.getBlockZ() && getBlockZ() <= max.getBlockZ();
// }
/**
* Clamp the Y component.
*
* @param min the minimum value
* @param max the maximum value
* @return a new vector
*/
public Vector clampY(int min, int max) {
return new Vector(x, Math.max(min, Math.min(max, y)), z);
}
// /**
// * Floors the values of all components.
// *
// * @return a new vector
// */
// public Vector floor() {
// return new Vector(Math.floor(x), Math.floor(y), Math.floor(z));
// }
//
// /**
// * Rounds all components up.
// *
// * @return a new vector
// */
// public Vector ceil() {
// return new Vector(Math.ceil(x), Math.ceil(y), Math.ceil(z));
// }
//
// /**
// * Rounds all components to the closest integer.
// *
// * <p>Components &lt; 0.5 are rounded down, otherwise up.</p>
// *
// * @return a new vector
// */
// public Vector round() {
// return new Vector(Math.floor(x + 0.5), Math.floor(y + 0.5), Math.floor(z + 0.5));
// }
// /**
// * Returns a vector with the absolute values of the components of
// * this vector.
// *
// * @return a new vector
// */
// public Vector positive() {
// return new Vector(Math.abs(x), Math.abs(y), Math.abs(z));
// }
// /**
// * Perform a 2D transformation on this vector and return a new one.
// *
// * @param angle in degrees
// * @param aboutX about which x coordinate to rotate
// * @param aboutZ about which z coordinate to rotate
// * @param translateX what to add after rotation
// * @param translateZ what to add after rotation
// * @return a new vector
// * @see AffineTransform another method to transform vectors
// */
// public Vector transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
// angle = Math.toRadians(angle);
// double x = this.x - aboutX;
// double z = this.z - aboutZ;
// double x2 = x * Math.cos(angle) - z * Math.sin(angle);
// double z2 = x * Math.sin(angle) + z * Math.cos(angle);
//
// return new Vector(
// x2 + aboutX + translateX,
// y,
// z2 + aboutZ + translateZ
// );
// }
//
// /**
// * Returns whether this vector is collinear with another vector.
// *
// * @param other the other vector
// * @return true if collinear
// */
// public boolean isCollinearWith(Vector other) {
// if (x == 0 && y == 0 && z == 0) {
// // this is a zero vector
// return true;
// }
//
// final double otherX = other.x;
// final double otherY = other.y;
// final double otherZ = other.z;
//
// if (otherX == 0 && otherY == 0 && otherZ == 0) {
// // other is a zero vector
// return true;
// }
//
// if ((x == 0) != (otherX == 0)) return false;
// if ((y == 0) != (otherY == 0)) return false;
// if ((z == 0) != (otherZ == 0)) return false;
//
// final double quotientX = otherX / x;
// if (!Double.isNaN(quotientX)) {
// return other.equals(multiply(quotientX));
// }
//
// final double quotientY = otherY / y;
// if (!Double.isNaN(quotientY)) {
// return other.equals(multiply(quotientY));
// }
//
// final double quotientZ = otherZ / z;
// if (!Double.isNaN(quotientZ)) {
// return other.equals(multiply(quotientZ));
// }
//
// throw new RuntimeException("This should not happen");
// }
// /**
// * Get this vector's pitch as used within the game.
// *
// * @return pitch in radians
// */
// public float toPitch() {
// double x = getX();
// double z = getZ();
//
// if (x == 0 && z == 0) {
// return getY() > 0 ? -90 : 90;
// } else {
// double x2 = x * x;
// double z2 = z * z;
// double xz = Math.sqrt(x2 + z2);
// return (float) Math.toDegrees(Math.atan(-getY() / xz));
// }
// }
// /**
// * Get this vector's yaw as used within the game.
// *
// * @return yaw in radians
// */
// public float toYaw() {
// double x = getX();
// double z = getZ();
//
// double t = Math.atan2(-x, z);
// double _2pi = 2 * Math.PI;
//
// return (float) Math.toDegrees(((t + _2pi) % _2pi));
// }
// /**
// * Create a new {@code BlockVector} using the given components.
// *
// * @param x the X coordinate
// * @param y the Y coordinate
// * @param z the Z coordinate
// * @return a new {@code BlockVector}
// */
// public static BlockVector toBlockPoint(double x, double y, double z) {
// return new BlockVector(
// Math.floor(x),
// Math.floor(y),
// Math.floor(z)
// );
// }
// /**
// * Create a new {@code BlockVector} from this vector.
// *
// * @return a new {@code BlockVector}
// */
// public BlockVector toBlockVector() {
// return new BlockVector(this);
// }
// /**
// * Creates a 2D vector by dropping the Y component from this vector.
// *
// * @return a new {@code Vector2D}
// */
// public Vector2D toVector2D() {
// return new Vector2D(x, z);
// }
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Vector)) {
return false;
}
Vector other = (Vector) obj;
return other.x == this.x && other.y == this.y && other.z == this.z;
}
@Override
public int compareTo(Vector other) {
if (other == null) {
throw new IllegalArgumentException("null not supported");
}
if (y != other.y) return Double.compare(y, other.y);
if (z != other.z) return Double.compare(z, other.z);
if (x != other.x) return Double.compare(x, other.x);
return 0;
}
@Override
public int hashCode() {
int hash = 7;
hash = 79 * hash + (int) (Double.doubleToLongBits(this.x) ^ (Double.doubleToLongBits(this.x) >>> 32));
hash = 79 * hash + (int) (Double.doubleToLongBits(this.y) ^ (Double.doubleToLongBits(this.y) >>> 32));
hash = 79 * hash + (int) (Double.doubleToLongBits(this.z) ^ (Double.doubleToLongBits(this.z) >>> 32));
return hash;
}
@Override
public String toString() {
return x + ", " + y + ", " + z;
}
// /**
// * Gets the minimum components of two vectors.
// *
// * @param v1 the first vector
// * @param v2 the second vector
// * @return minimum
// */
// public static Vector getMinimum(Vector v1, Vector v2) {
// return new Vector(
// Math.min(v1.x, v2.x),
// Math.min(v1.y, v2.y),
// Math.min(v1.z, v2.z)
// );
// }
//
// /**
// * Gets the maximum components of two vectors.
// *
// * @param v1 the first vector
// * @param v2 the second vector
// * @return maximum
// */
// public static Vector getMaximum(Vector v1, Vector v2) {
// return new Vector(
// Math.max(v1.x, v2.x),
// Math.max(v1.y, v2.y),
// Math.max(v1.z, v2.z)
// );
// }
// /**
// * Gets the midpoint of two vectors.
// *
// * @param v1 the first vector
// * @param v2 the second vector
// * @return maximum
// */
// public static Vector getMidpoint(Vector v1, Vector v2) {
// return new Vector(
// (v1.x + v2.x) / 2,
// (v1.y + v2.y) / 2,
// (v1.z + v2.z) / 2
// );
// }
// public BlockPos toBlockPos() {
// return new BlockPos(x, y, z);
// }
}

View file

@ -12,11 +12,6 @@ import common.block.Block;
import common.block.BlockFence;
import common.block.BlockFenceGate;
import common.block.BlockWall;
import common.clipboard.BlockTransform;
import common.clipboard.ClipboardBlock;
import common.clipboard.Rotation;
import common.clipboard.RotationValue;
import common.clipboard.Vector;
import common.collect.Lists;
import common.color.TextColor;
import common.dimension.Dimension;
@ -35,7 +30,6 @@ import common.init.BlockRegistry;
import common.init.Config;
import common.init.EntityRegistry;
import common.init.Items;
import common.init.RotationRegistry;
import common.init.SoundEvent;
import common.init.UniverseRegistry;
import common.init.Config.ValueType;
@ -130,7 +124,13 @@ import common.world.World;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import server.Server;
import server.clipboard.BlockTransform;
import server.clipboard.ClipboardBlock;
import server.clipboard.ClipboardPlacer;
import server.clipboard.Rotation;
import server.clipboard.RotationRegistry;
import server.clipboard.RotationValue;
import server.clipboard.Vector;
import server.command.Executor;
import server.world.Region;
import server.world.WorldServer;

View file

@ -21,7 +21,6 @@ import common.block.BlockEventData;
import common.block.BlockFalling;
import common.block.BlockLiquid;
import common.block.BlockSnow;
import common.clipboard.ClipboardBlock;
import common.collect.Lists;
import common.collect.Maps;
import common.collect.Sets;
@ -98,6 +97,7 @@ import common.worldgen.caves.MapGenBigCaves;
import common.worldgen.caves.MapGenCaves;
import common.worldgen.caves.MapGenRavine;
import server.Server;
import server.clipboard.ClipboardBlock;
import server.network.Player;
import server.village.VillageCollection;
import server.worldgen.structure.MapGenBridge;