diff --git a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java
index 6ba9d5eaf..3fba70a8e 100644
--- a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java
+++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java
@@ -96,7 +96,7 @@ final class BukkitAdapter {
final double length = Math.sqrt(eyeX * eyeX + eyeZ * eyeZ);
final float pitch = (float) Math.toDegrees(Math.atan2(-direction.getY(), length));
return new org.bukkit.Location(
- adapt(location.getWorld()),
+ adapt((World) location.getExtent()),
position.getX(), position.getY(), position.getZ(),
yaw, pitch);
}
diff --git a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java
index a8dc5adc2..1e57ffa54 100644
--- a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java
+++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java
@@ -19,8 +19,6 @@
package com.sk89q.worldedit.bukkit;
-import com.sk89q.worldedit.LocalWorld;
-import com.sk89q.worldedit.PlayerNeededException;
import com.sk89q.worldedit.WorldEditPermissionException;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.cui.CUIEvent;
diff --git a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitEntity.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitEntity.java
index 810709603..1625c572a 100644
--- a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitEntity.java
+++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitEntity.java
@@ -22,8 +22,8 @@ package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.metadata.Tameable;
+import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
-import com.sk89q.worldedit.world.World;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -63,7 +63,7 @@ class BukkitEntity implements Entity {
}
@Override
- public World getWorld() {
+ public Extent getExtent() {
return BukkitAdapter.adapt(getEntity().getWorld());
}
@@ -74,7 +74,12 @@ class BukkitEntity implements Entity {
@Override
public BaseEntity getState() {
- return new BukkitBaseEntity(getEntity().getType());
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ @Override
+ public boolean remove() {
+ return false;
}
}
diff --git a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
index dfafb852f..67d2152b1 100644
--- a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
+++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
@@ -184,13 +184,7 @@ public class BukkitWorld extends LocalWorld {
@Nullable
@Override
public com.sk89q.worldedit.entity.Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) {
- if (entity instanceof BukkitBaseEntity) {
- BukkitBaseEntity bukkitBaseEntity = (BukkitBaseEntity) entity;
- Entity nativeEntity = getWorld().spawnEntity(BukkitAdapter.adapt(location), bukkitBaseEntity.getBukkitType());
- return BukkitAdapter.adapt(nativeEntity);
- } else {
- return null;
- }
+ throw new UnsupportedOperationException("Not implemented yet");
}
private class NmsBlockClassLoader extends ClassLoader {
diff --git a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitBaseEntity.java b/src/forge/java/com/sk89q/worldedit/forge/ForgeAdapter.java
similarity index 60%
rename from src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitBaseEntity.java
rename to src/forge/java/com/sk89q/worldedit/forge/ForgeAdapter.java
index 25fe7c4f4..5a1d6120f 100644
--- a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitBaseEntity.java
+++ b/src/forge/java/com/sk89q/worldedit/forge/ForgeAdapter.java
@@ -17,28 +17,23 @@
* along with this program. If not, see .
*/
-package com.sk89q.worldedit.bukkit;
+package com.sk89q.worldedit.forge;
-import com.sk89q.worldedit.entity.AbstractBaseEntity;
-import com.sk89q.worldedit.entity.BaseEntity;
-import org.bukkit.entity.EntityType;
+import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.world.World;
+import net.minecraft.util.Vec3;
-import static com.google.common.base.Preconditions.checkNotNull;
+final class ForgeAdapter {
-/**
- * An implementation of a {@link BaseEntity} for Bukkit.
- */
-public class BukkitBaseEntity extends AbstractBaseEntity {
-
- private final EntityType type;
-
- public BukkitBaseEntity(EntityType type) {
- checkNotNull(type);
- this.type = type;
+ private ForgeAdapter() {
}
- public EntityType getBukkitType() {
- return type;
+ public static World adapt(net.minecraft.world.World world) {
+ return new ForgeWorld(world);
+ }
+
+ public static Vector adapt(Vec3 vector) {
+ return new Vector(vector.xCoord, vector.yCoord, vector.zCoord);
}
}
diff --git a/src/forge/java/com/sk89q/worldedit/forge/ForgeEntity.java b/src/forge/java/com/sk89q/worldedit/forge/ForgeEntity.java
new file mode 100644
index 000000000..75f1d9b09
--- /dev/null
+++ b/src/forge/java/com/sk89q/worldedit/forge/ForgeEntity.java
@@ -0,0 +1,67 @@
+/*
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q
+ * Copyright (C) WorldEdit team and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.worldedit.forge;
+
+import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.entity.BaseEntity;
+import com.sk89q.worldedit.entity.Entity;
+import com.sk89q.worldedit.extent.Extent;
+import com.sk89q.worldedit.util.Location;
+import net.minecraft.entity.EntityList;
+import net.minecraft.nbt.NBTTagCompound;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+class ForgeEntity implements Entity {
+
+ private final net.minecraft.entity.Entity entity;
+
+ ForgeEntity(net.minecraft.entity.Entity entity) {
+ checkNotNull(entity);
+ this.entity = entity;
+ }
+
+ @Override
+ public BaseEntity getState() {
+ NBTTagCompound tag = new NBTTagCompound();
+ entity.writeToNBT(tag);
+ return new BaseEntity(EntityList.getEntityString(entity), NBTConverter.fromNative(tag));
+ }
+
+ @Override
+ public Location getLocation() {
+ return new Location(
+ ForgeAdapter.adapt(entity.worldObj),
+ new Vector(entity.posX, entity.posY, entity.posZ),
+ ForgeAdapter.adapt(entity.getLookVec()));
+ }
+
+ @Override
+ public Extent getExtent() {
+ return ForgeAdapter.adapt(entity.worldObj);
+ }
+
+ @Override
+ public boolean remove() {
+ entity.setDead();
+ return true;
+ }
+
+}
diff --git a/src/forge/java/com/sk89q/worldedit/forge/ForgeWorld.java b/src/forge/java/com/sk89q/worldedit/forge/ForgeWorld.java
index e9f712d09..60f229bf0 100644
--- a/src/forge/java/com/sk89q/worldedit/forge/ForgeWorld.java
+++ b/src/forge/java/com/sk89q/worldedit/forge/ForgeWorld.java
@@ -25,6 +25,7 @@ import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.LazyBlock;
import com.sk89q.worldedit.entity.BaseEntity;
+import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
@@ -32,8 +33,8 @@ import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.mapping.NullResolver;
import com.sk89q.worldedit.world.mapping.Resolver;
import net.minecraft.block.Block;
-import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityHanging;
+import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.item.*;
@@ -55,7 +56,7 @@ import net.minecraft.world.gen.ChunkProviderServer;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
-import java.util.Collections;
+import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
@@ -227,7 +228,7 @@ public class ForgeWorld extends AbstractWorld {
int num = 0;
double radiusSq = radius * radius;
- for (Entity obj : (Iterable) getWorld().loadedEntityList) {
+ for (net.minecraft.entity.Entity obj : (Iterable) getWorld().loadedEntityList) {
if ((obj instanceof EntityLiving)) {
EntityLiving ent = (EntityLiving) obj;
@@ -270,7 +271,7 @@ public class ForgeWorld extends AbstractWorld {
int num = 0;
double radiusSq = Math.pow(radius, 2.0D);
- for (Entity ent : (Iterable) getWorld().loadedEntityList) {
+ for (net.minecraft.entity.Entity ent : (Iterable) getWorld().loadedEntityList) {
if ((radius != -1) && (origin.distanceSq(new Vector(ent.posX, ent.posY, ent.posZ)) > radiusSq)) {
continue;
}
@@ -497,7 +498,7 @@ public class ForgeWorld extends AbstractWorld {
@Nullable
@Override
- public T getMetaData(com.sk89q.worldedit.entity.Entity entity, Class metaDataClass) {
+ public T getMetaData(Entity entity, Class metaDataClass) {
return null;
}
@@ -508,14 +509,29 @@ public class ForgeWorld extends AbstractWorld {
}
@Override
- public List getEntities() {
- return Collections.emptyList();
+ public List getEntities() {
+ List entities = new ArrayList();
+ for (Object entity : getWorld().getLoadedEntityList()) {
+ entities.add(new ForgeEntity((net.minecraft.entity.Entity) entity));
+ }
+ return entities;
}
@Nullable
@Override
- public com.sk89q.worldedit.entity.Entity createEntity(Location location, BaseEntity entity) {
- return null;
+ public Entity createEntity(Location location, BaseEntity entity) {
+ World world = getWorld();
+ net.minecraft.entity.Entity createdEntity = EntityList.createEntityByName(entity.getTypeId(), world);
+ if (createdEntity != null) {
+ CompoundTag tag = entity.getNbtData();
+ if (tag != null) {
+ createdEntity.readFromNBT(NBTConverter.toNative(entity.getNbtData()));
+ }
+ world.spawnEntityInWorld(createdEntity);
+ return new ForgeEntity(createdEntity);
+ } else {
+ return null;
+ }
}
/**
diff --git a/src/main/java/com/sk89q/worldedit/WorldVector.java b/src/main/java/com/sk89q/worldedit/WorldVector.java
index 5e3d12b2e..d03137a69 100644
--- a/src/main/java/com/sk89q/worldedit/WorldVector.java
+++ b/src/main/java/com/sk89q/worldedit/WorldVector.java
@@ -20,6 +20,7 @@
package com.sk89q.worldedit;
import com.sk89q.worldedit.internal.LocalWorldAdapter;
+import com.sk89q.worldedit.world.World;
/**
* @deprecated Use {@link com.sk89q.worldedit.util.Location} wherever possible
@@ -97,7 +98,7 @@ public class WorldVector extends Vector {
* @param location the location
*/
public WorldVector(com.sk89q.worldedit.util.Location location) {
- this(LocalWorldAdapter.adapt(location.getWorld()), location.getX(), location.getY(), location.getZ());
+ this(LocalWorldAdapter.adapt((World) location.getExtent()), location.getX(), location.getY(), location.getZ());
}
/**
diff --git a/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java b/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java
index fffa9a0be..04a25443a 100644
--- a/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java
+++ b/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java
@@ -25,6 +25,7 @@ import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
+import com.sk89q.worldedit.world.World;
/**
* A super pickaxe mode that will remove blocks in an area.
@@ -48,7 +49,7 @@ public class AreaPickaxe implements BlockTool {
int ox = clicked.getBlockX();
int oy = clicked.getBlockY();
int oz = clicked.getBlockZ();
- int initialType = clicked.getWorld().getBlockType(clicked.toVector());
+ int initialType = ((World) clicked.getExtent()).getBlockType(clicked.toVector());
if (initialType == 0) {
return true;
@@ -70,7 +71,7 @@ public class AreaPickaxe implements BlockTool {
continue;
}
- clicked.getWorld().queueBlockBreakEffect(server, pos, initialType, clicked.toVector().distanceSq(pos));
+ ((World) clicked.getExtent()).queueBlockBreakEffect(server, pos, initialType, clicked.toVector().distanceSq(pos));
editSession.setBlock(pos, air);
}
diff --git a/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java b/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java
index 252823561..41bff5f2a 100644
--- a/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java
+++ b/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java
@@ -41,7 +41,7 @@ public class BlockDataCyler implements DoubleActionBlockTool {
private boolean handleCycle(Platform server, LocalConfiguration config,
Player player, LocalSession session, Location clicked, boolean forward) {
- World world = clicked.getWorld();
+ World world = (World) clicked.getExtent();
int type = world.getBlockType(clicked.toVector());
int data = world.getBlockData(clicked.toVector());
diff --git a/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java b/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java
index 19abb8ea3..d1af045bb 100644
--- a/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java
+++ b/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java
@@ -48,7 +48,7 @@ public class BlockReplacer implements DoubleActionBlockTool {
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
BlockBag bag = session.getBlockBag(player);
- World world = clicked.getWorld();
+ World world = (World) clicked.getExtent();
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1, bag, player);
try {
@@ -67,7 +67,7 @@ BlockBag bag = session.getBlockBag(player);
@Override
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
- World world = clicked.getWorld();
+ World world = (World) clicked.getExtent();
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1, player);
targetBlock = (editSession).getBlock(clicked.toVector());
BlockType type = BlockType.fromID(targetBlock.getType());
diff --git a/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java b/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java
index df92fb5f0..14785c392 100644
--- a/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java
+++ b/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java
@@ -53,7 +53,7 @@ public class FloatingTreeRemover implements BlockTool {
public boolean actPrimary(Platform server, LocalConfiguration config,
Player player, LocalSession session, Location clicked) {
- final World world = clicked.getWorld();
+ final World world = (World) clicked.getExtent();
switch (world.getBlockType(clicked.toVector())) {
case BlockID.LOG:
diff --git a/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java b/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java
index 4ccead8cf..3d484b18e 100644
--- a/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java
+++ b/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java
@@ -51,7 +51,7 @@ public class FloodFillTool implements BlockTool {
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
- World world = clicked.getWorld();
+ World world = (World) clicked.getExtent();
int initialType = world.getBlockType(clicked.toVector());
diff --git a/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java b/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java
index a68031f74..6aa5262a0 100644
--- a/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java
+++ b/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java
@@ -42,7 +42,7 @@ public class QueryTool implements BlockTool {
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
- World world = clicked.getWorld();
+ World world = (World) clicked.getExtent();
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, 0, player);
BaseBlock block = (editSession).rawGetBlock(clicked.toVector());
BlockType type = BlockType.fromID(block.getType());
diff --git a/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java b/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java
index e551b9f2e..7a8589b4c 100644
--- a/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java
+++ b/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java
@@ -50,7 +50,7 @@ public class RecursivePickaxe implements BlockTool {
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
- World world = clicked.getWorld();
+ World world = (World) clicked.getExtent();
int initialType = world.getBlockType(clicked.toVector());
diff --git a/src/main/java/com/sk89q/worldedit/command/tool/SinglePickaxe.java b/src/main/java/com/sk89q/worldedit/command/tool/SinglePickaxe.java
index 202c04c95..246a6f633 100644
--- a/src/main/java/com/sk89q/worldedit/command/tool/SinglePickaxe.java
+++ b/src/main/java/com/sk89q/worldedit/command/tool/SinglePickaxe.java
@@ -42,7 +42,7 @@ public class SinglePickaxe implements BlockTool {
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
- World world = clicked.getWorld();
+ World world = (World) clicked.getExtent();
final int blockType = world.getBlockType(clicked.toVector());
if (blockType == BlockID.BEDROCK
&& !player.canDestroyBedrock()) {
diff --git a/src/main/java/com/sk89q/worldedit/entity/AbstractBaseEntity.java b/src/main/java/com/sk89q/worldedit/entity/AbstractBaseEntity.java
deleted file mode 100644
index c1c4bca1b..000000000
--- a/src/main/java/com/sk89q/worldedit/entity/AbstractBaseEntity.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * Copyright (C) WorldEdit team and contributors
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.sk89q.worldedit.entity;
-
-import com.sk89q.jnbt.CompoundTag;
-import com.sk89q.worldedit.world.DataException;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * An abstract implementation of {@link BaseEntity} that implementations can
- * subclass to simplify implementation.
- */
-public abstract class AbstractBaseEntity implements BaseEntity {
-
- private CompoundTag nbtData;
-
- @Override
- public boolean hasNbtData() {
- return getNbtData() != null;
- }
-
- @Override
- public CompoundTag getNbtData() {
- return nbtData;
- }
-
- @Override
- public void setNbtData(CompoundTag nbtData) throws DataException {
- checkNotNull(nbtData);
- this.nbtData = nbtData;
- }
-
-}
diff --git a/src/main/java/com/sk89q/worldedit/entity/BaseEntity.java b/src/main/java/com/sk89q/worldedit/entity/BaseEntity.java
index 2b1fb2193..b1f8b0a91 100644
--- a/src/main/java/com/sk89q/worldedit/entity/BaseEntity.java
+++ b/src/main/java/com/sk89q/worldedit/entity/BaseEntity.java
@@ -19,11 +19,74 @@
package com.sk89q.worldedit.entity;
+import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.NbtValued;
+import static com.google.common.base.Preconditions.checkNotNull;
+
/**
* A snapshot of an entity that can be reused and passed around.
*/
-public interface BaseEntity extends NbtValued {
+public class BaseEntity implements NbtValued {
+
+ private String id;
+ private CompoundTag nbtData;
+
+ /**
+ * Create a new base entity.
+ *
+ * @param id the entity type ID
+ * @param nbtData NBT data
+ */
+ public BaseEntity(String id, CompoundTag nbtData) {
+ setTypeId(id);
+ setNbtData(nbtData);
+ }
+
+ /**
+ * Make a clone of a {@link BaseEntity}.
+ *
+ * @param other the object to clone
+ */
+ public BaseEntity(BaseEntity other) {
+ checkNotNull(other);
+ setTypeId(other.getTypeId());
+ setNbtData(other.getNbtData());
+ }
+
+ @Override
+ public boolean hasNbtData() {
+ return true;
+ }
+
+ @Override
+ public CompoundTag getNbtData() {
+ return nbtData;
+ }
+
+ @Override
+ public void setNbtData(CompoundTag nbtData) {
+ checkNotNull(nbtData);
+ this.nbtData = nbtData;
+ }
+
+ /**
+ * Get the entity that determines the type of entity.
+ *
+ * @return the entity ID
+ */
+ public String getTypeId() {
+ return id;
+ }
+
+ /**
+ * Set the entity ID that determines the type of entity.
+ *
+ * @param id the id
+ */
+ public void setTypeId(String id) {
+ checkNotNull(id);
+ this.id = id;
+ }
}
diff --git a/src/main/java/com/sk89q/worldedit/entity/Entity.java b/src/main/java/com/sk89q/worldedit/entity/Entity.java
index 88473d6f8..800f61c72 100644
--- a/src/main/java/com/sk89q/worldedit/entity/Entity.java
+++ b/src/main/java/com/sk89q/worldedit/entity/Entity.java
@@ -21,7 +21,6 @@ package com.sk89q.worldedit.entity;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
-import com.sk89q.worldedit.world.World;
/**
* A reference to an instance of an entity that exists in an {@link Extent}
@@ -50,10 +49,17 @@ public interface Entity {
Location getLocation();
/**
- * Get the world that this entity is on.
+ * Get the extent that this entity is on.
*
- * @return the world
+ * @return the extent
*/
- World getWorld();
+ Extent getExtent();
+
+ /**
+ * Remove this entity from it container.
+ *
+ * @return true if removal was successful
+ */
+ boolean remove();
}
diff --git a/src/main/java/com/sk89q/worldedit/entity/Player.java b/src/main/java/com/sk89q/worldedit/entity/Player.java
index 9f09a4b5b..c5e2e333e 100644
--- a/src/main/java/com/sk89q/worldedit/entity/Player.java
+++ b/src/main/java/com/sk89q/worldedit/entity/Player.java
@@ -19,16 +19,28 @@
package com.sk89q.worldedit.entity;
-import com.sk89q.worldedit.*;
+import com.sk89q.worldedit.PlayerDirection;
+import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.WorldEditException;
+import com.sk89q.worldedit.WorldVector;
+import com.sk89q.worldedit.WorldVectorFace;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.inventory.BlockBag;
+import com.sk89q.worldedit.world.World;
/**
* A player.
*/
public interface Player extends Entity, Actor {
+ /**
+ * Return the world that the player is on.
+ *
+ * @return the world
+ */
+ World getWorld();
+
/**
* Returns true if the entity is holding a pick axe.
*
diff --git a/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java b/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java
index e329baf22..6cc034891 100644
--- a/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java
+++ b/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java
@@ -19,12 +19,21 @@
package com.sk89q.worldedit.extension.platform;
-import com.sk89q.worldedit.*;
+import com.sk89q.worldedit.BlockWorldVector;
+import com.sk89q.worldedit.LocalPlayer;
+import com.sk89q.worldedit.NotABlockException;
+import com.sk89q.worldedit.PlayerDirection;
+import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.WorldEditException;
+import com.sk89q.worldedit.WorldEditPermissionException;
+import com.sk89q.worldedit.WorldVector;
+import com.sk89q.worldedit.WorldVectorFace;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.blocks.ItemID;
import com.sk89q.worldedit.entity.Player;
+import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.util.TargetBlock;
import com.sk89q.worldedit.world.World;
@@ -36,7 +45,12 @@ import java.io.File;
* that is intended for implementations of WorldEdit to use to wrap
* players that make use of WorldEdit.
*/
-public abstract class AbstractPlayerActor implements Actor, Player {
+public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
+
+ @Override
+ public final Extent getExtent() {
+ return getWorld();
+ }
/**
* Returns direction according to rotation. May return null.
@@ -466,4 +480,15 @@ public abstract class AbstractPlayerActor implements Actor, Player {
return false;
}
+ @SuppressWarnings("CloneDoesntCallSuperClone")
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ throw new CloneNotSupportedException("Not supported");
+ }
+
+ @Override
+ public boolean remove() {
+ return false;
+ }
+
}
diff --git a/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java b/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java
index ed29e8fb5..019c1cc72 100644
--- a/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java
+++ b/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java
@@ -19,13 +19,21 @@
package com.sk89q.worldedit.internal.command;
-import com.sk89q.worldedit.*;
+import com.sk89q.worldedit.BiomeType;
+import com.sk89q.worldedit.EditSession;
+import com.sk89q.worldedit.IncompleteRegionException;
+import com.sk89q.worldedit.LocalSession;
+import com.sk89q.worldedit.UnknownDirectionException;
+import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.WorldEdit;
+import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
+import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.annotation.Direction;
@@ -33,7 +41,12 @@ import com.sk89q.worldedit.internal.annotation.Selection;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
-import com.sk89q.worldedit.util.command.parametric.*;
+import com.sk89q.worldedit.util.command.parametric.ArgumentStack;
+import com.sk89q.worldedit.util.command.parametric.BindingBehavior;
+import com.sk89q.worldedit.util.command.parametric.BindingHelper;
+import com.sk89q.worldedit.util.command.parametric.BindingMatch;
+import com.sk89q.worldedit.util.command.parametric.ParameterException;
+import com.sk89q.worldedit.world.World;
import java.util.Arrays;
@@ -158,7 +171,10 @@ public class WorldEditBinding extends BindingHelper {
ParserContext parserContext = new ParserContext();
parserContext.setActor(context.getContext().getLocals().get(Actor.class));
if (actor instanceof Entity) {
- parserContext.setWorld(((Entity) actor).getWorld());
+ Extent extent = ((Entity) actor).getExtent();
+ if (extent instanceof World) {
+ parserContext.setWorld((World) extent);
+ }
}
parserContext.setSession(worldEdit.getSessionManager().get(actor));
try {
@@ -184,7 +200,10 @@ public class WorldEditBinding extends BindingHelper {
ParserContext parserContext = new ParserContext();
parserContext.setActor(context.getContext().getLocals().get(Actor.class));
if (actor instanceof Entity) {
- parserContext.setWorld(((Entity) actor).getWorld());
+ Extent extent = ((Entity) actor).getExtent();
+ if (extent instanceof World) {
+ parserContext.setWorld((World) extent);
+ }
}
parserContext.setSession(worldEdit.getSessionManager().get(actor));
try {
@@ -210,7 +229,10 @@ public class WorldEditBinding extends BindingHelper {
ParserContext parserContext = new ParserContext();
parserContext.setActor(context.getContext().getLocals().get(Actor.class));
if (actor instanceof Entity) {
- parserContext.setWorld(((Entity) actor).getWorld());
+ Extent extent = ((Entity) actor).getExtent();
+ if (extent instanceof World) {
+ parserContext.setWorld((World) extent);
+ }
}
parserContext.setSession(worldEdit.getSessionManager().get(actor));
try {
diff --git a/src/main/java/com/sk89q/worldedit/util/Location.java b/src/main/java/com/sk89q/worldedit/util/Location.java
index e5ae26909..d6ee8c468 100644
--- a/src/main/java/com/sk89q/worldedit/util/Location.java
+++ b/src/main/java/com/sk89q/worldedit/util/Location.java
@@ -20,7 +20,7 @@
package com.sk89q.worldedit.util;
import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.world.World;
+import com.sk89q.worldedit.extent.Extent;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -36,92 +36,92 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/
public class Location {
- private final World world;
+ private final Extent extent;
private final Vector position;
private final Vector direction;
/**
- * Create a new instance in the given world at 0, 0, 0 with a
+ * Create a new instance in the given extent at 0, 0, 0 with a
* direction vector of 0, 0, 0.
*
- * @param world the world
+ * @param extent the extent
*/
- public Location(World world) {
- this(world, new Vector(), new Vector());
+ public Location(Extent extent) {
+ this(extent, new Vector(), new Vector());
}
/**
- * Create a new instance in the given world with the given coordinates
+ * Create a new instance in the given extent with the given coordinates
* with a direction vector of 0, 0, 0.
*
- * @param world the world
+ * @param extent the extent
* @param x the X coordinate
* @param y the Y coordinate
* @param z the Z coordinate
*/
- public Location(World world, double x, double y, double z) {
- this(world, new Vector(x, y, z), new Vector());
+ public Location(Extent extent, double x, double y, double z) {
+ this(extent, new Vector(x, y, z), new Vector());
}
/**
- * Create a new instance in the given world with the given position
+ * Create a new instance in the given extent with the given position
* vector and a direction vector of 0, 0, 0.
*
- * @param world the world
+ * @param extent the extent
* @param position the position vector
*/
- public Location(World world, Vector position) {
- this(world, position, new Vector());
+ public Location(Extent extent, Vector position) {
+ this(extent, position, new Vector());
}
/**
- * Create a new instance in the given world with the given coordinates
+ * Create a new instance in the given extent with the given coordinates
* and the given direction vector.
*
- * @param world the world
+ * @param extent the extent
* @param x the X coordinate
* @param y the Y coordinate
* @param z the Z coordinate
* @param direction the direction vector
*/
- public Location(World world, double x, double y, double z, Vector direction) {
- this(world, new Vector(x, y, z), direction);
+ public Location(Extent extent, double x, double y, double z, Vector direction) {
+ this(extent, new Vector(x, y, z), direction);
}
/**
- * Create a new instance in the given world with the given position vector
+ * Create a new instance in the given extent with the given position vector
* and the given direction vector.
*
- * @param world the world
+ * @param extent the extent
* @param position the position vector
* @param direction the direction vector
*/
- public Location(World world, Vector position, Vector direction) {
- checkNotNull(world);
+ public Location(Extent extent, Vector position, Vector direction) {
+ checkNotNull(extent);
checkNotNull(position);
checkNotNull(direction);
- this.world = world;
+ this.extent = extent;
this.position = position;
this.direction = direction;
}
/**
- * Get the world.
+ * Get the extent.
*
- * @return the world
+ * @return the extent
*/
- public World getWorld() {
- return world;
+ public Extent getExtent() {
+ return extent;
}
/**
- * Create a clone of this object with the given world.
+ * Create a clone of this object with the given extent.
*
- * @param world the new world
+ * @param extent the new extent
* @return the new instance
*/
- public Location setWorld(World world) {
- return new Location(world, position, getDirection());
+ public Location setExtent(Extent extent) {
+ return new Location(extent, position, getDirection());
}
/**
@@ -143,7 +143,7 @@ public class Location {
* @return the new instance
*/
public Location setDirection(Vector direction) {
- return new Location(world, position, direction);
+ return new Location(extent, position, direction);
}
/**
@@ -181,7 +181,7 @@ public class Location {
* @return a new immutable instance
*/
public Location setX(double x) {
- return new Location(world, position.setX(x), direction);
+ return new Location(extent, position.setX(x), direction);
}
/**
@@ -192,7 +192,7 @@ public class Location {
* @return a new immutable instance
*/
public Location setX(int x) {
- return new Location(world, position.setX(x), direction);
+ return new Location(extent, position.setX(x), direction);
}
/**
@@ -221,7 +221,7 @@ public class Location {
* @return a new immutable instance
*/
public Location setY(double y) {
- return new Location(world, position.setY(y), direction);
+ return new Location(extent, position.setY(y), direction);
}
/**
@@ -232,7 +232,7 @@ public class Location {
* @return a new immutable instance
*/
public Location setY(int y) {
- return new Location(world, position.setY(y), direction);
+ return new Location(extent, position.setY(y), direction);
}
/**
@@ -261,7 +261,7 @@ public class Location {
* @return a new immutable instance
*/
public Location setZ(double z) {
- return new Location(world, position.setZ(z), direction);
+ return new Location(extent, position.setZ(z), direction);
}
/**
@@ -272,7 +272,7 @@ public class Location {
* @return a new immutable instance
*/
public Location setZ(int z) {
- return new Location(world, position.setZ(z), direction);
+ return new Location(extent, position.setZ(z), direction);
}
@Override
@@ -284,14 +284,14 @@ public class Location {
if (!direction.equals(location.direction)) return false;
if (!position.equals(location.position)) return false;
- if (!world.equals(location.world)) return false;
+ if (!extent.equals(location.extent)) return false;
return true;
}
@Override
public int hashCode() {
- int result = world.hashCode();
+ int result = extent.hashCode();
result = 31 * result + position.hashCode();
result = 31 * result + direction.hashCode();
return result;
diff --git a/src/test/java/com/sk89q/worldedit/util/LocationTest.java b/src/test/java/com/sk89q/worldedit/util/LocationTest.java
index ecf3bc327..06d546e32 100644
--- a/src/test/java/com/sk89q/worldedit/util/LocationTest.java
+++ b/src/test/java/com/sk89q/worldedit/util/LocationTest.java
@@ -38,7 +38,7 @@ public class LocationTest {
public void testGetWorld() throws Exception {
World world = mock(World.class);
Location location = new Location(world);
- assertEquals(world, location.getWorld());
+ assertEquals(world, location.getExtent());
}
@Test
@@ -46,9 +46,9 @@ public class LocationTest {
World world1 = mock(World.class);
World world2 = mock(World.class);
Location location1 = new Location(world1);
- Location location2 = location1.setWorld(world2);
- assertEquals(world1, location1.getWorld());
- assertEquals(world2, location2.getWorld());
+ Location location2 = location1.setExtent(world2);
+ assertEquals(world1, location1.getExtent());
+ assertEquals(world2, location2.getExtent());
}
@Test