2011-01-01 18:33:18 +00:00
|
|
|
/*
|
2014-04-04 22:03:18 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2011-01-01 18:33:18 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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
|
2011-01-01 18:33:18 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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.
|
2011-01-01 18:33:18 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2011-01-01 18:33:18 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-02-18 23:49:50 +00:00
|
|
|
*/
|
2011-01-01 18:33:18 +00:00
|
|
|
|
|
|
|
package com.sk89q.worldedit;
|
|
|
|
|
2014-03-30 04:05:09 +00:00
|
|
|
import com.sk89q.worldedit.blocks.*;
|
2012-03-17 22:24:30 +00:00
|
|
|
import com.sk89q.worldedit.util.TreeGenerator;
|
2014-04-05 05:40:29 +00:00
|
|
|
import com.sk89q.worldedit.world.AbstractWorld;
|
|
|
|
import com.sk89q.worldedit.world.World;
|
2011-01-08 19:26:27 +00:00
|
|
|
|
2014-03-30 04:05:09 +00:00
|
|
|
import java.util.Random;
|
|
|
|
|
2011-01-01 18:33:18 +00:00
|
|
|
/**
|
2014-04-05 05:40:29 +00:00
|
|
|
* A legacy abstract implementation of {@link World}. New implementations
|
|
|
|
* should use {@link AbstractWorld} when possible.
|
2012-03-02 04:47:19 +00:00
|
|
|
*
|
2014-04-05 05:40:29 +00:00
|
|
|
* @deprecated Replace with {@link World} wherever appropriate
|
2011-01-01 18:33:18 +00:00
|
|
|
*/
|
2014-04-05 05:40:29 +00:00
|
|
|
@Deprecated
|
|
|
|
public abstract class LocalWorld extends AbstractWorld {
|
2014-03-30 21:16:06 +00:00
|
|
|
|
2011-12-06 05:26:12 +00:00
|
|
|
/**
|
2012-03-17 22:24:30 +00:00
|
|
|
* Named flags to use as parameters to {@link LocalWorld#killMobs(Vector, double, int)}
|
2011-12-06 05:26:12 +00:00
|
|
|
*/
|
2014-04-05 05:40:29 +00:00
|
|
|
@SuppressWarnings("PointlessBitwiseExpression")
|
2014-04-04 21:35:12 +00:00
|
|
|
public final class KillFlags {
|
2011-12-06 05:26:12 +00:00
|
|
|
public static final int PETS = 1 << 0;
|
|
|
|
public static final int NPCS = 1 << 1;
|
2011-12-06 06:08:32 +00:00
|
|
|
public static final int ANIMALS = 1 << 2;
|
2012-03-16 19:02:56 +00:00
|
|
|
public static final int GOLEMS = 1 << 3;
|
2012-12-25 23:34:17 +00:00
|
|
|
public static final int AMBIENT = 1 << 4;
|
|
|
|
public static final int FRIENDLY = PETS | NPCS | ANIMALS | GOLEMS | AMBIENT;
|
2011-12-21 17:10:34 +00:00
|
|
|
public static final int WITH_LIGHTNING = 1 << 20;
|
2014-04-04 21:35:12 +00:00
|
|
|
|
|
|
|
private KillFlags() {
|
|
|
|
}
|
2011-12-06 05:26:12 +00:00
|
|
|
}
|
|
|
|
|
2011-01-11 18:21:26 +00:00
|
|
|
/**
|
2014-04-05 05:40:29 +00:00
|
|
|
* @deprecated Don't use this anymore. It will be removed
|
2011-01-08 19:26:27 +00:00
|
|
|
*/
|
2014-04-05 05:40:29 +00:00
|
|
|
@SuppressWarnings("ProtectedField")
|
2014-04-01 01:22:44 +00:00
|
|
|
@Deprecated
|
2014-04-05 05:40:29 +00:00
|
|
|
protected Random random = new Random();
|
2011-06-04 17:30:45 +00:00
|
|
|
|
2014-04-05 05:40:29 +00:00
|
|
|
@Override
|
|
|
|
public BaseBlock getBlock(Vector pt) {
|
|
|
|
checkLoadedChunk(pt);
|
2012-03-17 15:35:29 +00:00
|
|
|
|
2014-04-05 05:40:29 +00:00
|
|
|
@SuppressWarnings("deprecation") int type = getBlockType(pt);
|
|
|
|
@SuppressWarnings("deprecation") int data = getBlockData(pt);
|
2012-03-21 05:45:48 +00:00
|
|
|
|
2014-04-05 05:40:29 +00:00
|
|
|
switch (type) {
|
|
|
|
case BlockID.WALL_SIGN:
|
|
|
|
case BlockID.SIGN_POST: {
|
|
|
|
SignBlock block = new SignBlock(type, data);
|
|
|
|
copyFromWorld(pt, block);
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BlockID.CHEST: {
|
|
|
|
ChestBlock block = new ChestBlock(data);
|
|
|
|
copyFromWorld(pt, block);
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BlockID.FURNACE:
|
|
|
|
case BlockID.BURNING_FURNACE: {
|
|
|
|
FurnaceBlock block = new FurnaceBlock(type, data);
|
|
|
|
copyFromWorld(pt, block);
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BlockID.DISPENSER: {
|
|
|
|
DispenserBlock block = new DispenserBlock(data);
|
|
|
|
copyFromWorld(pt, block);
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BlockID.MOB_SPAWNER: {
|
|
|
|
MobSpawnerBlock block = new MobSpawnerBlock(data);
|
|
|
|
copyFromWorld(pt, block);
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BlockID.NOTE_BLOCK: {
|
|
|
|
NoteBlock block = new NoteBlock(data);
|
|
|
|
copyFromWorld(pt, block);
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BlockID.HEAD: {
|
|
|
|
SkullBlock block = new SkullBlock(data);
|
|
|
|
copyFromWorld(pt, block);
|
|
|
|
return block;
|
|
|
|
}
|
2011-10-26 20:50:46 +00:00
|
|
|
|
2014-04-05 05:40:29 +00:00
|
|
|
default:
|
|
|
|
return new BaseBlock(type, data);
|
|
|
|
}
|
2011-08-14 07:48:18 +00:00
|
|
|
}
|
2011-10-26 20:50:46 +00:00
|
|
|
|
2011-01-08 19:26:27 +00:00
|
|
|
/**
|
2014-04-05 05:40:29 +00:00
|
|
|
* Given a block and a position, copy data from the world to the block
|
|
|
|
* based on the type of block.
|
|
|
|
* </p>
|
|
|
|
* The provided {@link BaseBlock} should match that of the one in the
|
|
|
|
* world.
|
2012-03-02 04:47:19 +00:00
|
|
|
*
|
2014-04-05 05:40:29 +00:00
|
|
|
* @param position the position
|
|
|
|
* @param block the block
|
|
|
|
* @return true if the copy operation succeeded, false otherwise
|
2011-01-08 19:26:27 +00:00
|
|
|
*/
|
2014-04-05 05:40:29 +00:00
|
|
|
public abstract boolean copyFromWorld(Vector position, BaseBlock block);
|
2011-01-08 19:26:27 +00:00
|
|
|
|
2014-04-05 05:40:29 +00:00
|
|
|
@Override
|
|
|
|
public BaseBlock getLazyBlock(Vector position) {
|
|
|
|
return getBlock(position);
|
|
|
|
}
|
2011-01-08 19:26:27 +00:00
|
|
|
|
2014-04-05 05:40:29 +00:00
|
|
|
@Override
|
|
|
|
public boolean setBlock(Vector pt, BaseBlock block, boolean notifyAdjacent) {
|
|
|
|
boolean successful;
|
2011-01-08 19:26:27 +00:00
|
|
|
|
2014-04-05 05:40:29 +00:00
|
|
|
// Default implementation will call the old deprecated methods
|
|
|
|
if (notifyAdjacent) {
|
|
|
|
successful = setTypeIdAndData(pt, block.getId(), block.getData());
|
|
|
|
} else {
|
|
|
|
successful = setTypeIdAndDataFast(pt, block.getId(), block.getData());
|
|
|
|
}
|
2011-01-08 19:26:27 +00:00
|
|
|
|
2014-04-05 05:40:29 +00:00
|
|
|
copyToWorld(pt, block);
|
2011-01-30 22:54:42 +00:00
|
|
|
|
2014-04-05 05:40:29 +00:00
|
|
|
return successful;
|
2012-03-17 22:24:30 +00:00
|
|
|
}
|
2011-01-30 22:54:42 +00:00
|
|
|
|
|
|
|
/**
|
2014-04-05 05:40:29 +00:00
|
|
|
* Given a block and a position, copy data to the world from the block
|
|
|
|
* based on the type of block.
|
|
|
|
* </p>
|
|
|
|
* The provided {@link BaseBlock} should match that of the one in the
|
|
|
|
* world.
|
2012-03-02 04:47:19 +00:00
|
|
|
*
|
2014-04-05 05:40:29 +00:00
|
|
|
* @param position the position
|
|
|
|
* @param block the block
|
|
|
|
* @return true if the copy operation succeeded, false otherwise
|
2011-01-30 22:54:42 +00:00
|
|
|
*/
|
2014-04-05 05:40:29 +00:00
|
|
|
public abstract boolean copyToWorld(Vector position, BaseBlock block);
|
2011-01-30 22:54:42 +00:00
|
|
|
|
2014-04-05 05:40:29 +00:00
|
|
|
@Override
|
|
|
|
public boolean setBlock(Vector pt, BaseBlock block) {
|
|
|
|
return setBlock(pt, block, true);
|
2012-03-17 22:24:30 +00:00
|
|
|
}
|
|
|
|
|
2014-04-05 05:40:29 +00:00
|
|
|
@Override
|
|
|
|
public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
2012-03-17 22:24:30 +00:00
|
|
|
switch (type) {
|
|
|
|
case BIG_TREE:
|
|
|
|
return generateBigTree(editSession, pt);
|
|
|
|
case BIRCH:
|
|
|
|
return generateBirchTree(editSession, pt);
|
|
|
|
case REDWOOD:
|
|
|
|
return generateRedwoodTree(editSession, pt);
|
|
|
|
case TALL_REDWOOD:
|
|
|
|
return generateTallRedwoodTree(editSession, pt);
|
|
|
|
default:
|
|
|
|
case TREE:
|
|
|
|
return generateTree(editSession, pt);
|
|
|
|
}
|
|
|
|
}
|
2011-01-09 18:22:01 +00:00
|
|
|
|
2011-02-18 23:49:50 +00:00
|
|
|
@Override
|
2014-04-05 05:40:29 +00:00
|
|
|
public boolean generateTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
2011-11-28 06:13:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-11-29 08:09:32 +00:00
|
|
|
|
2014-03-30 04:05:09 +00:00
|
|
|
@Override
|
2014-04-05 05:40:29 +00:00
|
|
|
public boolean generateBigTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
|
|
|
return false;
|
2014-04-01 01:22:44 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 23:52:37 +00:00
|
|
|
@Override
|
2014-04-05 05:40:29 +00:00
|
|
|
public boolean generateBirchTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
|
|
|
return false;
|
2014-03-30 21:16:06 +00:00
|
|
|
}
|
|
|
|
|
2014-04-04 00:52:53 +00:00
|
|
|
@Override
|
2014-04-05 05:40:29 +00:00
|
|
|
public boolean generateRedwoodTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
|
|
|
return false;
|
2014-04-04 00:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-04-05 05:40:29 +00:00
|
|
|
public boolean generateTallRedwoodTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
|
|
|
return false;
|
2014-04-04 00:52:53 +00:00
|
|
|
}
|
|
|
|
|
2011-01-01 18:33:18 +00:00
|
|
|
}
|