Changed Location to use Extents rather than worlds and overhauled the new Entity code a bit.

This commit is contained in:
sk89q
2014-06-29 15:36:41 -07:00
parent c9612c05a7
commit eee2c5d9f4
24 changed files with 312 additions and 158 deletions

View File

@ -1,51 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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.
*