mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 10:56:42 +00:00
Added incomplete entity support to all Extents.
The Bukkit implementation supports the new entity API, but it has not yet been tested. The Forge implementation does not support the entity API yet. At the moment, an UnsupportedOperationException is thrown for Entity.getState() in some implementations, but use of an exception should probably not be allowed. BaseEntity is now an interface. It should not be possible to create instances of BaseEntity because it may be implementation-specific.
This commit is contained in:
@ -22,6 +22,8 @@ package com.sk89q.worldedit;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
||||
import com.sk89q.worldedit.extent.ChangeSetExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
@ -70,8 +72,7 @@ import com.sk89q.worldedit.regions.shape.ArbitraryBiomeShape;
|
||||
import com.sk89q.worldedit.regions.shape.ArbitraryShape;
|
||||
import com.sk89q.worldedit.regions.shape.RegionShape;
|
||||
import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment;
|
||||
import com.sk89q.worldedit.util.Countable;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.util.*;
|
||||
import com.sk89q.worldedit.util.collection.DoubleArrayList;
|
||||
import com.sk89q.worldedit.util.eventbus.EventBus;
|
||||
import com.sk89q.worldedit.world.NullWorld;
|
||||
@ -572,6 +573,17 @@ public class EditSession implements Extent {
|
||||
return getBlock(position).isAir() && setBlock(position, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entity> getEntities() {
|
||||
return world.getEntities();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) {
|
||||
return world.createEntity(location, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a contrived block change into the history.
|
||||
*
|
||||
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
@ -19,79 +19,11 @@
|
||||
|
||||
package com.sk89q.worldedit.entity;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.NbtValued;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A snapshot of an entity that can be reused and passed around.
|
||||
*/
|
||||
public class BaseEntity implements NbtValued {
|
||||
|
||||
private CompoundTag nbtData;
|
||||
|
||||
/**
|
||||
* Create a new entity with the given entity ID.
|
||||
*
|
||||
* @param id the ID of the entity, which determines its type
|
||||
*/
|
||||
public BaseEntity(String id) {
|
||||
checkNotNull(id);
|
||||
Map<String, Tag> map = new HashMap<String, Tag>();
|
||||
map.put("id", new StringTag("id", id));
|
||||
this.nbtData = new CompoundTag("", map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new entity with the given NBT data.
|
||||
*
|
||||
* @param nbtData the NBT data
|
||||
*/
|
||||
public BaseEntity(CompoundTag nbtData) {
|
||||
checkNotNull(nbtData);
|
||||
this.nbtData = nbtData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID of the entity, which determines the type of entity.
|
||||
* An example of an entity ID would be "CaveSpider".
|
||||
*
|
||||
* @return the entity ID, which may be an empty string
|
||||
*/
|
||||
public String getEntityId() {
|
||||
CompoundTag nbtData = getNbtData();
|
||||
if (nbtData == null) {
|
||||
return "";
|
||||
}
|
||||
Tag idTag = nbtData.getValue().get("id");
|
||||
if (idTag != null && idTag instanceof StringTag) {
|
||||
return ((StringTag) idTag).getValue();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
public interface BaseEntity extends NbtValued {
|
||||
|
||||
}
|
||||
|
@ -35,6 +35,13 @@ import com.sk89q.worldedit.world.World;
|
||||
*/
|
||||
public interface Entity {
|
||||
|
||||
/**
|
||||
* Get a copy of the entity's state.
|
||||
*
|
||||
* @return the entity's state
|
||||
*/
|
||||
BaseEntity getState();
|
||||
|
||||
/**
|
||||
* Get the location of this entity.
|
||||
*
|
||||
|
@ -22,11 +22,16 @@ package com.sk89q.worldedit.extent;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.operation.OperationQueue;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
@ -70,6 +75,17 @@ public abstract class AbstractDelegateExtent implements Extent {
|
||||
return extent.setBlock(location, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Entity createEntity(Location location, BaseEntity entity) {
|
||||
return extent.createEntity(location, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entity> getEntities() {
|
||||
return extent.getEntities();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getMinimumPoint() {
|
||||
return extent.getMinimumPoint();
|
||||
|
@ -20,6 +20,12 @@
|
||||
package com.sk89q.worldedit.extent;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A world, portion of a world, clipboard, or other object that can have blocks
|
||||
@ -50,4 +56,24 @@ public interface Extent extends InputExtent, OutputExtent {
|
||||
*/
|
||||
Vector getMaximumPoint();
|
||||
|
||||
/**
|
||||
* Get a list of all entities.
|
||||
* </p>
|
||||
* If the extent is not wholly loaded (i.e. a world being simulated in the
|
||||
* game will not have every chunk loaded), then this list may not be
|
||||
* incomplete.
|
||||
*
|
||||
* @return a list of entities
|
||||
*/
|
||||
List<Entity> getEntities();
|
||||
|
||||
/**
|
||||
* Create an entity at the given location.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param location the location
|
||||
* @return a reference to the created entity, or null if the entity could not be created
|
||||
*/
|
||||
@Nullable Entity createEntity(Location location, BaseEntity entity);
|
||||
|
||||
}
|
||||
|
@ -22,9 +22,14 @@ package com.sk89q.worldedit.extent;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An extent that returns air blocks for all blocks and does not
|
||||
@ -44,6 +49,17 @@ public class NullExtent implements Extent {
|
||||
return nullPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entity> getEntities() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Entity createEntity(Location location, BaseEntity entity) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getBlock(Vector position) {
|
||||
return new BaseBlock(0);
|
||||
|
@ -32,6 +32,7 @@ import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.mapping.Resolver;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -339,6 +340,17 @@ public class LocalWorldAdapter extends LocalWorld {
|
||||
return world.getMetaData(entity, metaDataClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) {
|
||||
return world.createEntity(location, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entity> getEntities() {
|
||||
return world.getEntities();
|
||||
}
|
||||
|
||||
public static LocalWorldAdapter wrap(World world) {
|
||||
return new LocalWorldAdapter(world);
|
||||
}
|
||||
|
@ -26,11 +26,14 @@ import com.sk89q.worldedit.blocks.BlockID;
|
||||
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;
|
||||
import com.sk89q.worldedit.world.mapping.NullResolver;
|
||||
import com.sk89q.worldedit.world.mapping.Resolver;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A null implementation of {@link World} that drops all changes and
|
||||
@ -128,4 +131,15 @@ public class NullWorld extends AbstractWorld {
|
||||
public <T> T getMetaData(BaseEntity entity, Class<T> metaDataClass) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entity> getEntities() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Entity createEntity(Location location, BaseEntity entity) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user