mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 03:56:41 +00:00
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:
@ -23,8 +23,14 @@ import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
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.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.world.mapping.NullResolver;
|
||||
import com.sk89q.worldedit.world.mapping.Resolver;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A null implementation of {@link World} that drops all changes and
|
||||
@ -95,4 +101,31 @@ public class NullWorld extends AbstractWorld {
|
||||
return new BaseBlock(BlockID.AIR);
|
||||
}
|
||||
|
||||
@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(Entity entity, Class<T> metaDataClass) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getMetaData(BaseEntity entity, Class<T> metaDataClass) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +27,12 @@ import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.world.mapping.Mapping;
|
||||
|
||||
/**
|
||||
* Represents a world (dimension).
|
||||
*/
|
||||
public interface World extends Extent {
|
||||
public interface World extends Extent, Mapping {
|
||||
|
||||
/**
|
||||
* Get the name of the world.
|
||||
|
114
src/main/java/com/sk89q/worldedit/world/mapping/Mapping.java
Normal file
114
src/main/java/com/sk89q/worldedit/world/mapping/Mapping.java
Normal file
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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.world.mapping;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.entity.metadata.Tameable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A mapping can create state objects (such as {@link BaseBlock})
|
||||
* from implementation-independent identifiers (such as "minecraft.stone"),
|
||||
* as well as perform the opposite task of retrieving
|
||||
* the identifier for a given state object (whenever possible at least, because
|
||||
* a mapping may not be compatible with a set of state objects that may have
|
||||
* come from another implementation). In addition, a mapping may be able to
|
||||
* retrieve a variety of metadata objects (such as {@link Tameable}) to
|
||||
* describe a given state object.
|
||||
* </p>
|
||||
* However, it may be possible that a mapping be "dumb" and not be able to,
|
||||
* for example, return a {@link Tameable} for a "Horse" entity, simply because
|
||||
* it has not be implemented. Any code that queries a mapping must be
|
||||
* aware of this and act accordingly.
|
||||
*/
|
||||
public interface Mapping {
|
||||
|
||||
/**
|
||||
* Get the mapping for block identifiers.
|
||||
*
|
||||
* @return a block mapping
|
||||
*/
|
||||
Resolver<BaseBlock> getBlockMapping();
|
||||
|
||||
/**
|
||||
* Get the mapping for entity identifiers.
|
||||
*
|
||||
* @return an entity mapping
|
||||
*/
|
||||
Resolver<BaseEntity> getEntityMapping();
|
||||
|
||||
/**
|
||||
* Attempt to return an instance of the given class for the given block.
|
||||
* For example, {@code getMetaData(block, Inventory.class)} might return
|
||||
* an instance if the block happens to contain an inventory.
|
||||
* </p>
|
||||
* If the given block is not of the given class (i.e. a dirt block does
|
||||
* not have an inventory) or if the information is simply not available,
|
||||
* {@code null} will be returned.
|
||||
* </p>
|
||||
* Mutator methods on the returned instance should change the block.
|
||||
*
|
||||
* @param block the block
|
||||
* @param metaDataClass the metadata class for the returned instance
|
||||
* @param <T> the metadata class
|
||||
* @return an instance of the given class, otherwise null
|
||||
*/
|
||||
@Nullable <T> T getMetaData(BaseBlock block, Class<T> metaDataClass);
|
||||
|
||||
/**
|
||||
* Attempt to return an instance of the given class for the given entity.
|
||||
* For example, {@code getMetaData(entity, Creature.class)} might return
|
||||
* an instance if the entity happens to be a creature.
|
||||
* </p>
|
||||
* If the given entity is not of the given class (i.e. a painting is
|
||||
* not a creature) or if the information is simply not available,
|
||||
* {@code null} will be returned.
|
||||
* </p>
|
||||
* Mutator methods on the returned instance should change the entity.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param metaDataClass the metadata class for the returned instance
|
||||
* @param <T> the metadata class
|
||||
* @return an instance of the given class, otherwise null
|
||||
*/
|
||||
@Nullable <T> T getMetaData(Entity entity, Class<T> metaDataClass);
|
||||
|
||||
/**
|
||||
* Attempt to return an instance of the given class for the given entity.
|
||||
* For example, {@code getMetaData(entity, Creature.class)} might return
|
||||
* an instance if the entity happens to be a creature.
|
||||
* </p>
|
||||
* If the given entity is not of the given class (i.e. a painting is
|
||||
* not a creature) or if the information is simply not available,
|
||||
* {@code null} will be returned.
|
||||
* </p>
|
||||
* Mutator methods on the returned instance should change the entity.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param metaDataClass the metadata class for the returned instance
|
||||
* @param <T> the metadata class
|
||||
* @return an instance of the given class, otherwise null
|
||||
*/
|
||||
@Nullable <T> T getMetaData(BaseEntity entity, Class<T> metaDataClass);
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.world.mapping;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* An implementation of a {@link Resolver} that knows nothing and returns
|
||||
* {@code null} in all cases.
|
||||
*
|
||||
* @param <E> the object to resolve
|
||||
*/
|
||||
public class NullResolver<E> implements Resolver<E> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public E create(String id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getId(E object) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.world.mapping;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A resolver can create state objects (such as {@link BaseBlock}) from
|
||||
* universal identifiers, but also get the universal identifier for
|
||||
* a given state object (at least when it is known).
|
||||
* </p>
|
||||
* Identifiers may be case-sensitive. Routines that work with IDs should
|
||||
* not make changes to the casing of the IDs or perform case-insensitive
|
||||
* comparisons. Implementations may normalize the casing of IDs if it
|
||||
* is appropriate.
|
||||
*
|
||||
* @param <E> the type of state object
|
||||
*/
|
||||
public interface Resolver<E> {
|
||||
|
||||
/**
|
||||
* Create an instance of the state object from the given ID.
|
||||
*
|
||||
* @param id the ID
|
||||
* @return an instance, otherwise null if an instance cannot be created
|
||||
*/
|
||||
@Nullable E create(String id);
|
||||
|
||||
/**
|
||||
* Get the ID for the given object.
|
||||
*
|
||||
* @param object the object
|
||||
* @return the ID, otherwise null if it is not known
|
||||
*/
|
||||
@Nullable String getId(E object);
|
||||
|
||||
}
|
Reference in New Issue
Block a user