Current progress with update

This commit is contained in:
IronApollo
2018-12-23 11:19:33 -05:00
parent 9896a1339e
commit d4157b7e0e
417 changed files with 8994 additions and 4644 deletions

View File

@ -19,7 +19,18 @@
package com.sk89q.worldedit.forge;
<<<<<<< HEAD
import com.sk89q.worldedit.Vector;
=======
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.registry.state.BooleanProperty;
import com.sk89q.worldedit.registry.state.DirectionalProperty;
import com.sk89q.worldedit.registry.state.EnumProperty;
import com.sk89q.worldedit.registry.state.IntegerProperty;
import com.sk89q.worldedit.registry.state.Property;
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.World;
import net.minecraft.util.EnumFacing;
@ -35,15 +46,15 @@ final class ForgeAdapter {
return new ForgeWorld(world);
}
public static Vector adapt(Vec3d vector) {
return new Vector(vector.x, vector.y, vector.z);
public static Vector3 adapt(Vec3d vector) {
return new Vector3(vector.x, vector.y, vector.z);
}
public static Vector adapt(BlockPos pos) {
return new Vector(pos.getX(), pos.getY(), pos.getZ());
public static Vector3 adapt(BlockPos pos) {
return new Vector3(pos.getX(), pos.getY(), pos.getZ());
}
public static Vec3d toVec3(Vector vector) {
public static Vec3d toVec3(BlockVector3 vector) {
return new Vec3d(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
}
@ -60,7 +71,24 @@ final class ForgeAdapter {
}
}
<<<<<<< HEAD
public static BlockPos toBlockPos(Vector vector) {
=======
public static Direction adaptEnumFacing(EnumFacing face) {
switch (face) {
case NORTH: return Direction.NORTH;
case SOUTH: return Direction.SOUTH;
case WEST: return Direction.WEST;
case EAST: return Direction.EAST;
case DOWN: return Direction.DOWN;
case UP:
default:
return Direction.UP;
}
}
public static BlockPos toBlockPos(BlockVector3 vector) {
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
return new BlockPos(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
}

View File

@ -21,11 +21,11 @@ package com.sk89q.worldedit.forge;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.metadata.EntityProperties;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.NullWorld;
import com.sk89q.worldedit.world.entity.EntityTypes;
@ -66,7 +66,7 @@ class ForgeEntity implements Entity {
public Location getLocation() {
net.minecraft.entity.Entity entity = entityRef.get();
if (entity != null) {
Vector position = new Vector(entity.posX, entity.posY, entity.posZ);
Vector3 position = new Vector3(entity.posX, entity.posY, entity.posZ);
float yaw = entity.rotationYaw;
float pitch = entity.rotationPitch;

View File

@ -20,17 +20,18 @@
package com.sk89q.worldedit.forge;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extension.platform.AbstractPlayerActor;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.item.ItemTypes;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -45,6 +46,8 @@ import java.util.UUID;
import javax.annotation.Nullable;
import io.netty.buffer.Unpooled;
public class ForgePlayer extends AbstractPlayerActor {
private final EntityPlayerMP player;
@ -77,7 +80,7 @@ public class ForgePlayer extends AbstractPlayerActor {
@Override
public Location getLocation() {
Vector position = new Vector(this.player.posX, this.player.posY, this.player.posZ);
Vector3 position = new Vector3(this.player.posX, this.player.posY, this.player.posZ);
return new Location(
ForgeWorldEdit.inst.getWorld(this.player.world),
position,
@ -139,7 +142,7 @@ public class ForgePlayer extends AbstractPlayerActor {
}
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
public void setPosition(Vector3 pos, float pitch, float yaw) {
this.player.connection.setPlayerLocation(pos.getX(), pos.getY(), pos.getZ(), yaw, pitch);
}
@ -165,6 +168,27 @@ public class ForgePlayer extends AbstractPlayerActor {
}
@Override
<<<<<<< HEAD
=======
public void sendFakeBlock(BlockVector3 pos, BlockStateHolder block) {
BlockPos loc = ForgeAdapter.toBlockPos(pos);
if (block == null) {
// TODO
// player.sendBlockChange(loc, player.getWorld().getBlockAt(loc).getBlockData());
} else {
// TODO
// player.sendBlockChange(loc, BukkitAdapter.adapt(block));
if (block instanceof BaseBlock && ((BaseBlock) block).hasNbtData()) {
player.connection.sendPacket(new SPacketUpdateTileEntity(
new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), 7,
NBTConverter.toNative(((BaseBlock) block).getNbtData()))
);
}
}
}
@Override
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
public SessionKey getSessionKey() {
return new SessionKeyImpl(player.getUniqueID(), player.getName());
}

View File

@ -23,11 +23,12 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.io.Files;
import com.sk89q.jnbt.CompoundTag;
<<<<<<< HEAD
import com.sk89q.worldedit.BlockVector;
=======
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItem;
@ -35,6 +36,9 @@ import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Direction;
@ -157,7 +161,7 @@ public class ForgeWorld extends AbstractWorld {
}
@Override
public boolean setBlock(Vector position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException {
public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException {
checkNotNull(position);
checkNotNull(block);
@ -197,15 +201,15 @@ public class ForgeWorld extends AbstractWorld {
}
@Override
public int getBlockLightLevel(Vector position) {
public int getBlockLightLevel(BlockVector3 position) {
checkNotNull(position);
return getWorld().getLight(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()));
return getWorld().getLight(ForgeAdapter.toBlockPos(position));
}
@Override
public boolean clearContainerBlockContents(Vector position) {
public boolean clearContainerBlockContents(BlockVector3 position) {
checkNotNull(position);
TileEntity tile = getWorld().getTileEntity(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()));
TileEntity tile = getWorld().getTileEntity(ForgeAdapter.toBlockPos(position));
if ((tile instanceof IInventory)) {
IInventory inv = (IInventory) tile;
int size = inv.getSizeInventory();
@ -218,13 +222,13 @@ public class ForgeWorld extends AbstractWorld {
}
@Override
public BaseBiome getBiome(Vector2D position) {
public BaseBiome getBiome(BlockVector2 position) {
checkNotNull(position);
return new BaseBiome(Biome.getIdForBiome(getWorld().getBiomeForCoordsBody(new BlockPos(position.getBlockX(), 0, position.getBlockZ()))));
}
@Override
public boolean setBiome(Vector2D position, BaseBiome biome) {
public boolean setBiome(BlockVector2 position, BaseBiome biome) {
checkNotNull(position);
checkNotNull(biome);
@ -238,7 +242,7 @@ public class ForgeWorld extends AbstractWorld {
}
@Override
public boolean useItem(Vector position, BaseItem item, Direction face) {
public boolean useItem(BlockVector3 position, BaseItem item, Direction face) {
Item nativeItem = Item.getByNameOrId(item.getType().getId());
ItemStack stack = null;
if (item.getNbtData() == null) {
@ -253,7 +257,7 @@ public class ForgeWorld extends AbstractWorld {
}
@Override
public void dropItem(Vector position, BaseItemStack item) {
public void dropItem(Vector3 position, BaseItemStack item) {
checkNotNull(position);
checkNotNull(item);
@ -267,7 +271,7 @@ public class ForgeWorld extends AbstractWorld {
}
@Override
public void simulateBlockMine(Vector position) {
public void simulateBlockMine(BlockVector3 position) {
BlockPos pos = ForgeAdapter.toBlockPos(position);
IBlockState state = getWorld().getBlockState(pos);
state.getBlock().dropBlockAsItem(getWorld(), pos, state, 0);
@ -298,13 +302,13 @@ public class ForgeWorld extends AbstractWorld {
// Pre-gen all the chunks
// We need to also pull one more chunk in every direction
CuboidRegion expandedPreGen = new CuboidRegion(region.getMinimumPoint().subtract(16, 0, 16), region.getMaximumPoint().add(16, 0, 16));
for (Vector2D chunk : expandedPreGen.getChunks()) {
for (BlockVector2 chunk : expandedPreGen.getChunks()) {
freshWorld.getChunkFromChunkCoords(chunk.getBlockX(), chunk.getBlockZ());
}
ForgeWorld from = new ForgeWorld(freshWorld);
try {
for (BlockVector vec : region) {
for (BlockVector3 vec : region) {
editSession.setBlock(vec, from.getFullBlock(vec));
}
} catch (MaxChangedBlocksException e) {
@ -346,12 +350,39 @@ public class ForgeWorld extends AbstractWorld {
}
@Override
public boolean generateTree(TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException {
public boolean generateTree(TreeType type, EditSession editSession, BlockVector3 position) throws MaxChangedBlocksException {
WorldGenerator generator = createWorldGenerator(type);
return generator != null && generator.generate(getWorld(), random, ForgeAdapter.toBlockPos(position));
}
@Override
<<<<<<< HEAD
=======
public void checkLoadedChunk(BlockVector3 pt) {
getWorld().getChunkFromBlockCoords(ForgeAdapter.toBlockPos(pt));
}
@Override
public void fixAfterFastMode(Iterable<BlockVector2> chunks) {
fixLighting(chunks);
}
@Override
public void fixLighting(Iterable<BlockVector2> chunks) {
World world = getWorld();
for (BlockVector2 chunk : chunks) {
world.getChunkFromChunkCoords(chunk.getBlockX(), chunk.getBlockZ()).resetRelightChecks();
}
}
@Override
public boolean playEffect(Vector3 position, int type, int data) {
getWorld().playEvent(type, ForgeAdapter.toBlockPos(position.toBlockPoint()), data);
return true;
}
@Override
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
public WeatherType getWeather() {
// TODO Weather implementation
return null;
@ -373,7 +404,7 @@ public class ForgeWorld extends AbstractWorld {
}
@Override
public BlockState getBlock(Vector position) {
public BlockState getBlock(BlockVector3 position) {
World world = getWorld();
BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ());
IBlockState state = world.getBlockState(pos);
@ -382,7 +413,7 @@ public class ForgeWorld extends AbstractWorld {
}
@Override
public BaseBlock getFullBlock(Vector position) {
public BaseBlock getFullBlock(BlockVector3 position) {
BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ());
TileEntity tile = getWorld().getTileEntity(pos);
@ -418,7 +449,7 @@ public class ForgeWorld extends AbstractWorld {
public List<? extends Entity> getEntities(Region region) {
List<Entity> entities = new ArrayList<>();
for (net.minecraft.entity.Entity entity : getWorld().loadedEntityList) {
if (region.contains(new Vector(entity.posX, entity.posY, entity.posZ))) {
if (region.contains(new BlockVector3(entity.posX, entity.posY, entity.posZ))) {
entities.add(new ForgeEntity(entity));
}
}

View File

@ -21,7 +21,8 @@ package com.sk89q.worldedit.forge;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.BlockVector3;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.tileentity.TileEntity;
@ -47,7 +48,7 @@ final class TileEntityUtils {
* @param position the position
* @return a tag compound
*/
private static NBTTagCompound updateForSet(NBTTagCompound tag, Vector position) {
private static NBTTagCompound updateForSet(NBTTagCompound tag, BlockVector3 position) {
checkNotNull(tag);
checkNotNull(position);
@ -66,7 +67,7 @@ final class TileEntityUtils {
* @param clazz the tile entity class
* @param tag the tag for the tile entity (may be null to not set NBT data)
*/
static void setTileEntity(World world, Vector position, Class<? extends TileEntity> clazz, @Nullable NBTTagCompound tag) {
static void setTileEntity(World world, BlockVector3 position, Class<? extends TileEntity> clazz, @Nullable NBTTagCompound tag) {
checkNotNull(world);
checkNotNull(position);
checkNotNull(clazz);
@ -94,7 +95,7 @@ final class TileEntityUtils {
* @param position the position
* @param tag the tag for the tile entity (may be null to do nothing)
*/
static void setTileEntity(World world, Vector position, @Nullable NBTTagCompound tag) {
static void setTileEntity(World world, BlockVector3 position, @Nullable NBTTagCompound tag) {
if (tag != null) {
updateForSet(tag, position);
TileEntity tileEntity = TileEntity.create(world, tag);
@ -113,7 +114,7 @@ final class TileEntityUtils {
* @return a tile entity (may be null if it failed)
*/
@Nullable
static TileEntity constructTileEntity(World world, Vector position, Class<? extends TileEntity> clazz) {
static TileEntity constructTileEntity(World world, BlockVector3 position, Class<? extends TileEntity> clazz) {
Constructor<? extends TileEntity> baseConstructor;
try {
baseConstructor = clazz.getConstructor(); // creates "blank" TE