From 8722104565d4e18bf2e353a03dce4f2f7ce5e025 Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 4 Apr 2014 12:43:12 -0700 Subject: [PATCH] Added back old BlockBags as deprecated classes. --- .../com/sk89q/worldedit/bags/BlockBag.java | 198 ++++++++++++++++++ .../worldedit/bags/BlockBagException.java | 29 +++ .../worldedit/bags/OutOfBlocksException.java | 29 +++ .../worldedit/bags/OutOfSpaceException.java | 49 +++++ .../bags/UnplaceableBlockException.java | 30 +++ 5 files changed, 335 insertions(+) create mode 100644 src/legacy/java/com/sk89q/worldedit/bags/BlockBag.java create mode 100644 src/legacy/java/com/sk89q/worldedit/bags/BlockBagException.java create mode 100644 src/legacy/java/com/sk89q/worldedit/bags/OutOfBlocksException.java create mode 100644 src/legacy/java/com/sk89q/worldedit/bags/OutOfSpaceException.java create mode 100644 src/legacy/java/com/sk89q/worldedit/bags/UnplaceableBlockException.java diff --git a/src/legacy/java/com/sk89q/worldedit/bags/BlockBag.java b/src/legacy/java/com/sk89q/worldedit/bags/BlockBag.java new file mode 100644 index 000000000..52b7a9745 --- /dev/null +++ b/src/legacy/java/com/sk89q/worldedit/bags/BlockBag.java @@ -0,0 +1,198 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.bags; + +import com.sk89q.worldedit.WorldVector; +import com.sk89q.worldedit.blocks.*; + +/** + * @deprecated Block bags are currently not a supported feature of WorldEdit + */ +@Deprecated +public abstract class BlockBag { + /** + * Stores a block as if it was mined. + * + * @param id + * @throws BlockBagException + * @deprecated Use {@link BlockBag#storeDroppedBlock(int, int)} instead + */ + @Deprecated + public void storeDroppedBlock(int id) throws BlockBagException { + storeDroppedBlock(id, 0); + } + + /** + * Stores a block as if it was mined. + * + * @param id + * @param data + * @throws BlockBagException + */ + public void storeDroppedBlock(int id, int data) throws BlockBagException { + BaseItem dropped = BlockType.getBlockBagItem(id, data); + if (dropped == null) return; + if (dropped.getType() == BlockID.AIR) return; + + storeItem(dropped); + } + + /** + * Sets a block as if it was placed by hand. + * + * @param id + * @throws BlockBagException + * @deprecated Use {@link #fetchPlacedBlock(int,int)} instead + */ + @Deprecated + public void fetchPlacedBlock(int id) throws BlockBagException { + fetchPlacedBlock(id, 0); + } + + /** + * Sets a block as if it was placed by hand. + * + * @param id + * @param data TODO + * @throws BlockBagException + */ + public void fetchPlacedBlock(int id, int data) throws BlockBagException { + try { + // Blocks that can't be fetched... + switch (id) { + case BlockID.BEDROCK: + case BlockID.GOLD_ORE: + case BlockID.IRON_ORE: + case BlockID.COAL_ORE: + case BlockID.DIAMOND_ORE: + case BlockID.TNT: + case BlockID.MOB_SPAWNER: + case BlockID.CROPS: + case BlockID.REDSTONE_ORE: + case BlockID.GLOWING_REDSTONE_ORE: + case BlockID.SNOW: + case BlockID.LIGHTSTONE: + case BlockID.PORTAL: + throw new UnplaceableBlockException(); + + case BlockID.WATER: + case BlockID.STATIONARY_WATER: + case BlockID.LAVA: + case BlockID.STATIONARY_LAVA: + // Override liquids + return; + + default: + fetchBlock(id); + break; + } + + } catch (OutOfBlocksException e) { + BaseItem placed = BlockType.getBlockBagItem(id, data); + if (placed == null) throw e; // TODO: check + if (placed.getType() == BlockID.AIR) throw e; // TODO: check + + fetchItem(placed); + } + } + + /** + * Get a block. + * + * Either this method or fetchItem needs to be overridden + * + * @param id + * @throws BlockBagException + */ + public void fetchBlock(int id) throws BlockBagException { + fetchItem(new BaseItem(id)); + } + + /** + * Get a block. + * + * Either this method or fetchBlock needs to be overridden + * + * @param item + * @throws BlockBagException + */ + public void fetchItem(BaseItem item) throws BlockBagException { + fetchBlock(item.getType()); + } + + /** + * Store a block. + * + * Either this method or storeItem needs to be overridden + * + * @param id + * @throws BlockBagException + */ + public void storeBlock(int id) throws BlockBagException { + storeItem(new BaseItem(id)); + } + + /** + * Store a block. + * + * Either this method or storeBlock needs to be overridden + * + * @param item + * @throws BlockBagException + */ + public void storeItem(BaseItem item) throws BlockBagException { + storeBlock(item.getType()); + } + + /** + * Checks to see if a block exists without removing it. + * + * @param id + * @return whether the block exists + */ + public boolean peekBlock(int id) { + try { + fetchBlock(id); + storeBlock(id); + return true; + } catch (BlockBagException e) { + return false; + } + } + + /** + * Flush any changes. This is called at the end. + */ + public abstract void flushChanges(); + + /** + * Adds a position to be used a source. + * + * @param pos + */ + public abstract void addSourcePosition(WorldVector pos); + + /** + * Adds a position to be used a source. + * + * @param pos + */ + public abstract void addSingleSourcePosition(WorldVector pos); +} diff --git a/src/legacy/java/com/sk89q/worldedit/bags/BlockBagException.java b/src/legacy/java/com/sk89q/worldedit/bags/BlockBagException.java new file mode 100644 index 000000000..1d7350af7 --- /dev/null +++ b/src/legacy/java/com/sk89q/worldedit/bags/BlockBagException.java @@ -0,0 +1,29 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.bags; + + +/** + * @deprecated Block bags are currently not a supported feature of WorldEdit + */ +@Deprecated +public class BlockBagException extends Exception { + private static final long serialVersionUID = 4672190086028430655L; +} diff --git a/src/legacy/java/com/sk89q/worldedit/bags/OutOfBlocksException.java b/src/legacy/java/com/sk89q/worldedit/bags/OutOfBlocksException.java new file mode 100644 index 000000000..d5b37127f --- /dev/null +++ b/src/legacy/java/com/sk89q/worldedit/bags/OutOfBlocksException.java @@ -0,0 +1,29 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.bags; + + +/** + * @deprecated Block bags are currently not a supported feature of WorldEdit + */ +@Deprecated +public class OutOfBlocksException extends BlockBagException { + private static final long serialVersionUID = 7495899825677689509L; +} diff --git a/src/legacy/java/com/sk89q/worldedit/bags/OutOfSpaceException.java b/src/legacy/java/com/sk89q/worldedit/bags/OutOfSpaceException.java new file mode 100644 index 000000000..8d5376a2a --- /dev/null +++ b/src/legacy/java/com/sk89q/worldedit/bags/OutOfSpaceException.java @@ -0,0 +1,49 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.bags; + + +/** + * @deprecated Block bags are currently not a supported feature of WorldEdit + */ +@Deprecated +public class OutOfSpaceException extends BlockBagException { + private static final long serialVersionUID = -2962840237632916821L; + + /** + * Stores the block ID. + */ + private int id; + + /** + * Construct the object. + * @param id + */ + public OutOfSpaceException(int id) { + this.id = id; + } + + /** + * @return the id + */ + public int getID() { + return id; + } +} diff --git a/src/legacy/java/com/sk89q/worldedit/bags/UnplaceableBlockException.java b/src/legacy/java/com/sk89q/worldedit/bags/UnplaceableBlockException.java new file mode 100644 index 000000000..4859840e1 --- /dev/null +++ b/src/legacy/java/com/sk89q/worldedit/bags/UnplaceableBlockException.java @@ -0,0 +1,30 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.bags; + + +/** + * @deprecated Block bags are currently not a supported feature of WorldEdit + */ +@Deprecated +public class UnplaceableBlockException extends BlockBagException { + private static final long serialVersionUID = 7227883966999843526L; + +}