mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-03 03:46:42 +00:00
Moved LocalWorld's members upwards to AbstractWorld and World.
This commit is contained in:
243
src/main/java/com/sk89q/worldedit/world/AbstractWorld.java
Normal file
243
src/main/java/com/sk89q/worldedit/world/AbstractWorld.java
Normal file
@ -0,0 +1,243 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.LocalWorld.KillFlags;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldedit.function.mask.BlockMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.PriorityQueue;
|
||||
|
||||
/**
|
||||
* An abstract implementation of {@link World}.
|
||||
*/
|
||||
public abstract class AbstractWorld implements World {
|
||||
|
||||
private final PriorityQueue<QueuedEffect> effectQueue = new PriorityQueue<QueuedEffect>();
|
||||
private int taskId = -1;
|
||||
|
||||
@Override
|
||||
public int getMaxY() {
|
||||
return 255;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidBlockType(int type) {
|
||||
return BlockType.fromID(type) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean usesBlockData(int type) {
|
||||
// We future proof here by assuming all unknown blocks use data
|
||||
return BlockType.usesData(type) || BlockType.fromID(type) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask createLiquidMask() {
|
||||
return new BlockMask(this,
|
||||
new BaseBlock(BlockID.STATIONARY_LAVA, -1),
|
||||
new BaseBlock(BlockID.LAVA, -1),
|
||||
new BaseBlock(BlockID.STATIONARY_WATER, -1),
|
||||
new BaseBlock(BlockID.WATER, -1));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean setBlockTypeFast(Vector pt, int type) {
|
||||
return setBlockType(pt, type);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean setTypeIdAndData(Vector pt, int type, int data) {
|
||||
boolean ret = setBlockType(pt, type);
|
||||
setBlockData(pt, data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean setTypeIdAndDataFast(Vector pt, int type, int data) {
|
||||
boolean ret = setBlockTypeFast(pt, type);
|
||||
setBlockDataFast(pt, data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropItem(Vector pt, BaseItemStack item, int times) {
|
||||
for (int i = 0; i < times; ++i) {
|
||||
dropItem(pt, item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void simulateBlockMine(Vector pt) {
|
||||
BaseBlock block = getLazyBlock(pt);
|
||||
BaseItemStack stack = BlockType.getBlockDrop(block.getId(), (short) block.getData());
|
||||
if (stack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int amount = stack.getAmount();
|
||||
if (amount > 1) {
|
||||
dropItem(pt, new BaseItemStack(stack.getType(), 1, stack.getData()), amount);
|
||||
} else {
|
||||
dropItem(pt, stack, amount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalEntity[] getEntities(Region region) {
|
||||
return new LocalEntity[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int killEntities(LocalEntity... entities) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int killMobs(Vector origin, int radius) {
|
||||
return killMobs(origin, radius, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int killMobs(Vector origin, int radius, boolean killPets) {
|
||||
return killMobs(origin, radius, killPets ? KillFlags.PETS : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int killMobs(Vector origin, double radius, int flags) {
|
||||
return killMobs(origin, (int) radius, (flags & KillFlags.PETS) != 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
||||
return generateTree(TreeType.TREE, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateBigTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
||||
return generateTree(TreeType.BIG_TREE, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateBirchTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
||||
return generateTree(TreeType.BIRCH, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateRedwoodTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
||||
return generateTree(TreeType.REDWOOD, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateTallRedwoodTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
||||
return generateTree(TreeType.TALL_REDWOOD, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkLoadedChunk(Vector pt) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fixAfterFastMode(Iterable<BlockVector2D> chunks) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fixLighting(Iterable<BlockVector2D> chunks) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playEffect(Vector position, int type, int data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean queueBlockBreakEffect(ServerInterface server, Vector position, int blockId, double priority) {
|
||||
if (taskId == -1) {
|
||||
taskId = server.schedule(0, 1, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int max = Math.max(1, Math.min(30, effectQueue.size() / 3));
|
||||
for (int i = 0; i < max; ++i) {
|
||||
if (effectQueue.isEmpty()) return;
|
||||
|
||||
effectQueue.poll().play();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (taskId == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
effectQueue.offer(new QueuedEffect(position, blockId, priority));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getMinimumPoint() {
|
||||
return new Vector(-30000000, 0, -30000000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getMaximumPoint() {
|
||||
return new Vector(30000000, getMaxY(), 30000000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Operation commit() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private class QueuedEffect implements Comparable<QueuedEffect> {
|
||||
private final Vector position;
|
||||
private final int blockId;
|
||||
private final double priority;
|
||||
public QueuedEffect(Vector position, int blockId, double priority) {
|
||||
this.position = position;
|
||||
this.blockId = blockId;
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
public void play() {
|
||||
playEffect(position, 2001, blockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@Nullable QueuedEffect other) {
|
||||
return Double.compare(priority, other != null ? other.priority : 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -19,54 +19,335 @@
|
||||
|
||||
package com.sk89q.worldedit.world;
|
||||
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.foundation.Block;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Represents a world instance that can be modified. The world instance could be
|
||||
* loaded in-game or loaded in a stand-alone editor.
|
||||
* </p>
|
||||
* This class is meant to replace {@link LocalWorld} eventually, once this class has been
|
||||
* fleshed out with the required methods and it has been decided that it is time to
|
||||
* start breaking some API compatibility.
|
||||
* Represents a world (dimension).
|
||||
*/
|
||||
public interface World {
|
||||
public interface World extends Extent {
|
||||
|
||||
/**
|
||||
* Change the block at the given location to the given block. The operation may
|
||||
* not tie the given {@link BaseBlock} to the world, so future changes to the
|
||||
* {@link BaseBlock} do not affect the world until this method is called again.
|
||||
* </p>
|
||||
* Implementations may or may not consider the value of the notifyAdjacent
|
||||
* parameter, and implementations may to choose to either apply physics anyway or
|
||||
* to not apply any physics (particularly in a stand-alone implementation).
|
||||
* </p>
|
||||
* The return value of this method indicates whether the change "went through," as
|
||||
* in the block was changed in the world in any way. If the new block is no different
|
||||
* than the block already at the position in the world, 'false' would be returned.
|
||||
* If the position is invalid (out of bounds, for example), then nothing should
|
||||
* occur and 'false' should be returned. If possible, the return value should be
|
||||
* accurate as possible, but implementations may choose to not provide an accurate
|
||||
* value if it is not possible to know.
|
||||
* Get the name of the world.
|
||||
*
|
||||
* @param location location of the block
|
||||
* @return a name for the world
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Get the maximum Y.
|
||||
*
|
||||
* @return the maximum Y
|
||||
*/
|
||||
int getMaxY();
|
||||
|
||||
/**
|
||||
* Checks whether the given block ID is a valid block ID.
|
||||
*
|
||||
* @param id the block ID
|
||||
* @return true if the block ID is a valid one
|
||||
*/
|
||||
boolean isValidBlockType(int id);
|
||||
|
||||
/**
|
||||
* Checks whether the given block ID uses data values for differentiating
|
||||
* types of blocks.
|
||||
*
|
||||
* @param id the block ID
|
||||
* @return true if the block uses data values
|
||||
*/
|
||||
boolean usesBlockData(int id);
|
||||
|
||||
/**
|
||||
* Create a mask that matches all liquids.
|
||||
* </p>
|
||||
* Implementations should override this so that custom liquids are supported.
|
||||
*
|
||||
* @return a mask
|
||||
*/
|
||||
Mask createLiquidMask();
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getLazyBlock(Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
int getBlockType(Vector pt);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getLazyBlock(Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
int getBlockData(Vector pt);
|
||||
|
||||
/**
|
||||
* Similar to {@link Extent#setBlock(Vector, BaseBlock)} but a
|
||||
* {@code notifyAndLight} parameter indicates whether adjacent blocks
|
||||
* should be notified that changes have been made and lighting operations
|
||||
* should be executed.
|
||||
* </p>
|
||||
* If it's not possible to skip lighting, or if it's not possible to
|
||||
* avoid notifying adjacent blocks, then attempt to meet the
|
||||
* specification as best as possible.
|
||||
* </p>
|
||||
* On implementations where the world is not simulated, the
|
||||
* {@code notifyAndLight} parameter has no effect either way.
|
||||
*
|
||||
* @param position position of the block
|
||||
* @param block block to set
|
||||
* @param notifyAdjacent true to to notify adjacent (perform physics)
|
||||
* @param notifyAndLight true to to notify and light
|
||||
* @return true if the block was successfully set (return value may not be accurate)
|
||||
*/
|
||||
boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent);
|
||||
boolean setBlock(Vector position, BaseBlock block, boolean notifyAndLight);
|
||||
|
||||
/**
|
||||
* Get a copy of the block at the given location. May return null if the location
|
||||
* given is out of bounds. The returned block must not be tied to any real block
|
||||
* in the world, so changes to the returned {@link Block} have no effect until
|
||||
* {@link #setBlock(Vector, BaseBlock, boolean)} is called.
|
||||
*
|
||||
* @param location location of the block
|
||||
* @return the block, or null if the block does not exist
|
||||
* @deprecated Use {@link #setBlock(Vector, BaseBlock)}
|
||||
*/
|
||||
BaseBlock getBlock(Vector location);
|
||||
@Deprecated
|
||||
boolean setBlockType(Vector position, int type);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setBlock(Vector, BaseBlock)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean setBlockTypeFast(Vector position, int type);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setBlock(Vector, BaseBlock)}
|
||||
*/
|
||||
@Deprecated
|
||||
void setBlockData(Vector position, int data);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setBlock(Vector, BaseBlock)}
|
||||
*/
|
||||
@Deprecated
|
||||
void setBlockDataFast(Vector position, int data);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setBlock(Vector, BaseBlock)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean setTypeIdAndData(Vector position, int type, int data);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setBlock(Vector, BaseBlock)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean setTypeIdAndDataFast(Vector position, int type, int data);
|
||||
|
||||
/**
|
||||
* Get the light level at the given block.
|
||||
*
|
||||
* @param position the position
|
||||
* @return the light level (0-15)
|
||||
*/
|
||||
int getBlockLightLevel(Vector position);
|
||||
|
||||
/**
|
||||
* Clear a chest's contents.
|
||||
*
|
||||
* @param position the position
|
||||
* @return true if the container was cleared
|
||||
*/
|
||||
boolean clearContainerBlockContents(Vector position);
|
||||
|
||||
/**
|
||||
* Get the biome type.
|
||||
*
|
||||
* @param position the (x, z) location to check the biome at
|
||||
* @return the biome type at the location
|
||||
*/
|
||||
BiomeType getBiome(Vector2D position);
|
||||
|
||||
/**
|
||||
* Set the biome type.
|
||||
*
|
||||
* @param position the (x, z) location to set the biome at
|
||||
* @param biome the biome type to set to
|
||||
*/
|
||||
void setBiome(Vector2D position, BiomeType biome);
|
||||
|
||||
/**
|
||||
* Drop an item at the given position.
|
||||
*
|
||||
* @param position the position
|
||||
* @param item the item to drop
|
||||
* @param count the number of individual stacks to drop (number of item entities)
|
||||
*/
|
||||
void dropItem(Vector position, BaseItemStack item, int count);
|
||||
|
||||
/**
|
||||
* Drop one stack of the item at the given position.
|
||||
*
|
||||
* @param position the position
|
||||
* @param item the item to drop
|
||||
* @see #dropItem(Vector, BaseItemStack, int) shortcut method to specify the number of stacks
|
||||
*/
|
||||
void dropItem(Vector position, BaseItemStack item);
|
||||
|
||||
/**
|
||||
* Simulate a block being mined at the given position.
|
||||
*
|
||||
* @param position the position
|
||||
*/
|
||||
void simulateBlockMine(Vector position);
|
||||
|
||||
/**
|
||||
* Get a list of entities in the given region.
|
||||
*
|
||||
* @param region the region
|
||||
* @return a list of entities
|
||||
*/
|
||||
LocalEntity[] getEntities(Region region);
|
||||
|
||||
/**
|
||||
* Kill the entities listed in the provided array.
|
||||
*
|
||||
* @param entity an array of entities
|
||||
* @return the number of entities that were removed
|
||||
*/
|
||||
int killEntities(LocalEntity... entity);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #killMobs(Vector, double, int)}
|
||||
*/
|
||||
@Deprecated
|
||||
int killMobs(Vector origin, int radius);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #killMobs(Vector, double, int)}
|
||||
*/
|
||||
@Deprecated
|
||||
int killMobs(Vector origin, int radius, boolean killPets);
|
||||
|
||||
/**
|
||||
* Kill mobs at the given location with the given radius.
|
||||
*
|
||||
* @param origin the origin
|
||||
* @param radius the radius
|
||||
* @param flags kill flags (see {@link LocalWorld.KillFlags})
|
||||
* @return the number of mobs that were killed
|
||||
*/
|
||||
int killMobs(Vector origin, double radius, int flags);
|
||||
|
||||
/**
|
||||
* Remove entities in an area.
|
||||
*
|
||||
* @param type the type of entity
|
||||
* @param origin the origin
|
||||
* @param radius the radius
|
||||
* @return the number of mobs that were killed
|
||||
*/
|
||||
int removeEntities(EntityType type, Vector origin, int radius);
|
||||
|
||||
/**
|
||||
* Regenerate an area.
|
||||
*
|
||||
* @param region the region
|
||||
* @param editSession the {@link EditSession}
|
||||
* @return true if re-generation was successful
|
||||
*/
|
||||
boolean regenerate(Region region, EditSession editSession);
|
||||
|
||||
/**
|
||||
* Generate a tree at the given position.
|
||||
*
|
||||
* @param type the tree type
|
||||
* @param editSession the {@link EditSession}
|
||||
* @param position the position
|
||||
* @return true if generation was successful
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks were changed
|
||||
*/
|
||||
boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #generateTree(TreeType, EditSession, Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean generateTree(EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #generateTree(TreeType, EditSession, Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean generateBigTree(EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #generateTree(TreeType, EditSession, Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean generateBirchTree(EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #generateTree(TreeType, EditSession, Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean generateRedwoodTree(EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #generateTree(TreeType, EditSession, Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean generateTallRedwoodTree(EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* Load the chunk at the given position if it isn't loaded.
|
||||
*
|
||||
* @param position the position
|
||||
*/
|
||||
void checkLoadedChunk(Vector position);
|
||||
|
||||
/**
|
||||
* Fix the given chunks after fast mode was used.
|
||||
* </p>
|
||||
* Fast mode makes calls to {@link #setBlock(Vector, BaseBlock, boolean)}
|
||||
* with {@code false} for the {@code notifyAndLight} parameter, which
|
||||
* may causes lighting errors to accumulate. Use of this method, if
|
||||
* it is implemented by the underlying world, corrects those lighting
|
||||
* errors and may trigger block change notifications.
|
||||
*
|
||||
* @param chunks a list of chunk coordinates to fix
|
||||
*/
|
||||
void fixAfterFastMode(Iterable<BlockVector2D> chunks);
|
||||
|
||||
/**
|
||||
* Relight the given chunks if possible.
|
||||
*
|
||||
* @param chunks a list of chunk coordinates to fix
|
||||
*/
|
||||
void fixLighting(Iterable<BlockVector2D> chunks);
|
||||
|
||||
/**
|
||||
* Play the given effect.
|
||||
*
|
||||
* @param position the position
|
||||
* @param type the effect type
|
||||
* @param data the effect data
|
||||
* @return true if the effect was played
|
||||
*/
|
||||
boolean playEffect(Vector position, int type, int data);
|
||||
|
||||
/**
|
||||
* Queue a block break effect.
|
||||
*
|
||||
* @param server the server
|
||||
* @param position the position
|
||||
* @param blockId the block ID
|
||||
* @param priority the priority
|
||||
* @return true if the effect was played
|
||||
*/
|
||||
boolean queueBlockBreakEffect(ServerInterface server, Vector position, int blockId, double priority);
|
||||
|
||||
@Override
|
||||
boolean equals(Object other);
|
||||
|
||||
@Override
|
||||
int hashCode();
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user