Added a new preliminary mapping + metadata framework.

The eventual goal is to add:

1. Support for mapping block, etc. names (minecraft:stone, etc.)
2. Proper support for entities in WorldEdit
3. Support for querying for metadata about a block, entity, etc.
4. Extent support to biomes, structures, and so on
This commit is contained in:
sk89q
2014-04-26 21:57:45 -07:00
parent 19c43a2834
commit 354d819872
16 changed files with 777 additions and 188 deletions

View File

@ -0,0 +1,61 @@
/*
* 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.bukkit;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.Vectors;
import com.sk89q.worldedit.world.World;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Adapts between Bukkit and WorldEdit equivalent objects.
*/
final class BukkitAdapter {
private BukkitAdapter() {
}
/**
* Create a WorldEdit world from a Bukkit world.
*
* @param world the Bukkit world
* @return a WorldEdit world
*/
public static World adapt(org.bukkit.World world) {
checkNotNull(world);
return new BukkitWorld(world);
}
/**
* Create a WorldEdit location from a Bukkit location.
*
* @param location the Bukkit location
* @return a WorldEdit location
*/
public static Location adapt(org.bukkit.Location location) {
checkNotNull(location);
Vector position = BukkitUtil.toVector(location);
Vector direction = Vectors.fromEulerDeg(location.getYaw(), location.getPitch());
return new com.sk89q.worldedit.util.Location(adapt(location.getWorld()), position, direction);
}
}

View File

@ -0,0 +1,60 @@
/*
* 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.bukkit;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.metadata.Tameable;
import com.sk89q.worldedit.internal.util.AbstractAdapter;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
/**
* An adapter to adapt a Bukkit entity into a WorldEdit one.
*/
class BukkitEntity extends AbstractAdapter<org.bukkit.entity.Entity> implements Entity {
/**
* Create a new instance.
*
* @param entity the entity
*/
BukkitEntity(org.bukkit.entity.Entity entity) {
super(entity);
}
@SuppressWarnings("unchecked")
<T> T getMetaData(Class<T> metaDataClass) {
if (metaDataClass == Tameable.class && getHandle() instanceof org.bukkit.entity.Tameable) {
return (T) new TameableAdapter((org.bukkit.entity.Tameable) getHandle());
} else {
return null;
}
}
@Override
public World getWorld() {
return BukkitAdapter.adapt(getHandle().getWorld());
}
@Override
public Location getLocation() {
return BukkitAdapter.adapt(getHandle().getLocation());
}
}

View File

@ -26,8 +26,11 @@ import com.sk89q.worldedit.blocks.*;
import com.sk89q.worldedit.blocks.ContainerBlock;
import com.sk89q.worldedit.blocks.NoteBlock;
import com.sk89q.worldedit.bukkit.entity.BukkitEntity;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.world.mapping.NullResolver;
import com.sk89q.worldedit.world.mapping.Resolver;
import org.bukkit.*;
import org.bukkit.Location;
import org.bukkit.block.*;
@ -38,6 +41,7 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import javax.annotation.Nullable;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
@ -1248,4 +1252,37 @@ public class BukkitWorld extends LocalWorld {
return super.setBlock(pt, block, notifyAdjacent);
}
@Override
public Resolver<BaseBlock> getBlockMapping() {
return new NullResolver<BaseBlock>();
}
@Override
public Resolver<BaseEntity> getEntityMapping() {
return new NullResolver<BaseEntity>();
}
@Nullable
@Override
public <T> T getMetaData(BaseBlock block, Class<T> metaDataClass) {
return null;
}
@Nullable
@Override
public <T> T getMetaData(com.sk89q.worldedit.entity.Entity entity, Class<T> metaDataClass) {
if (entity instanceof com.sk89q.worldedit.bukkit.BukkitEntity) {
return ((com.sk89q.worldedit.bukkit.BukkitEntity) entity).getMetaData(metaDataClass);
}
return null;
}
@Nullable
@Override
public <T> T getMetaData(BaseEntity entity, Class<T> metaDataClass) {
return null;
}
}

View File

@ -0,0 +1,40 @@
/*
* 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.bukkit;
import com.sk89q.worldedit.entity.metadata.Tameable;
import com.sk89q.worldedit.internal.util.AbstractAdapter;
/**
* Adapts a Bukkit {@link org.bukkit.entity.Tameable} into a WorldEdit
* equivalent.
*/
public class TameableAdapter extends AbstractAdapter<org.bukkit.entity.Tameable> implements Tameable {
TameableAdapter(org.bukkit.entity.Tameable entity) {
super(entity);
}
@Override
public boolean isTamed() {
return getHandle().isTamed();
}
}