mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Added secondary mode to tool framework. Updated /cycler to make use of this.
This commit is contained in:
parent
a6cab43d38
commit
47268bef20
@ -866,7 +866,7 @@ public class WorldEdit {
|
|||||||
Tool tool = session.getTool(player.getItemInHand());
|
Tool tool = session.getTool(player.getItemInHand());
|
||||||
|
|
||||||
if (tool != null && tool instanceof BlockTool) {
|
if (tool != null && tool instanceof BlockTool) {
|
||||||
((BlockTool)tool).act(server, config, player, session, clicked);
|
((BlockTool)tool).actPrimary(server, config, player, session, clicked);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -901,11 +901,18 @@ public class WorldEdit {
|
|||||||
}
|
}
|
||||||
} else if (player.isHoldingPickAxe() && session.hasSuperPickAxe()) {
|
} else if (player.isHoldingPickAxe() && session.hasSuperPickAxe()) {
|
||||||
if (session.getSuperPickaxe() != null) {
|
if (session.getSuperPickaxe() != null) {
|
||||||
return session.getSuperPickaxe().act(server, config,
|
return session.getSuperPickaxe().actPrimary(server, config,
|
||||||
player, session, clicked);
|
player, session, clicked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Tool tool = session.getTool(player.getItemInHand());
|
||||||
|
|
||||||
|
if (tool != null && tool instanceof DoubleActionBlockTool) {
|
||||||
|
((DoubleActionBlockTool)tool).actSecondary(server, config, player, session, clicked);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public class AreaPickaxe implements BlockTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean act(ServerInterface server, LocalConfiguration config,
|
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
|
||||||
LocalPlayer player, LocalSession session, WorldVector clicked) {
|
LocalPlayer player, LocalSession session, WorldVector clicked) {
|
||||||
LocalWorld world = clicked.getWorld();
|
LocalWorld world = clicked.getWorld();
|
||||||
int ox = clicked.getBlockX();
|
int ox = clicked.getBlockX();
|
||||||
|
@ -27,10 +27,10 @@ import com.sk89q.worldedit.blocks.BlockID;
|
|||||||
*
|
*
|
||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class BlockDataCyler implements BlockTool {
|
public class BlockDataCyler implements DoubleActionBlockTool {
|
||||||
@Override
|
|
||||||
public boolean act(ServerInterface server, LocalConfiguration config,
|
private boolean handleCycle(ServerInterface server, LocalConfiguration config,
|
||||||
LocalPlayer player, LocalSession session, WorldVector clicked) {
|
LocalPlayer player, LocalSession session, WorldVector clicked, boolean forward) {
|
||||||
|
|
||||||
LocalWorld world = clicked.getWorld();
|
LocalWorld world = clicked.getWorld();
|
||||||
|
|
||||||
@ -44,40 +44,50 @@ public class BlockDataCyler implements BlockTool {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int increment = forward ? 1 : -1;
|
||||||
|
|
||||||
if (type == BlockID.LOG) {
|
if (type == BlockID.LOG) {
|
||||||
data = (data + 1) % 3;
|
data = (data + increment) % 3;
|
||||||
} else if (type == BlockID.LEAVES) {
|
} else if (type == BlockID.LEAVES) {
|
||||||
data = (data + 1) % 3;
|
data = (data + increment) % 3;
|
||||||
|
} else if (type == BlockID.SAPLING) {
|
||||||
|
int saplingType = data & 0x03;
|
||||||
|
int age = data & 0x0c;
|
||||||
|
data = (saplingType + increment) % 4 | age;
|
||||||
} else if (type == BlockID.CACTUS) {
|
} else if (type == BlockID.CACTUS) {
|
||||||
data = (data + 1) % 16;
|
data = (data + increment) % 16;
|
||||||
} else if (type == BlockID.SOIL) {
|
} else if (type == BlockID.SOIL) {
|
||||||
data = (data + 1) % 9;
|
data = (data + increment) % 9;
|
||||||
} else if (type == BlockID.CROPS) {
|
} else if (type == BlockID.CROPS) {
|
||||||
data = (data + 1) % 6;
|
data = (data + increment) % 6;
|
||||||
} else if (type == BlockID.MINECART_TRACKS) {
|
} else if (type == BlockID.MINECART_TRACKS) {
|
||||||
if (data >= 6 && data <= 9) {
|
if (data >= 6 && data <= 9) {
|
||||||
data = (data + 1) % 4 + 6;
|
data = (data + increment) % 4 + 6;
|
||||||
} else {
|
} else {
|
||||||
player.printError("This minecart track orientation is not supported.");
|
player.printError("This minecart track orientation is not supported.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (type == BlockID.WOODEN_STAIRS || type == BlockID.COBBLESTONE_STAIRS) {
|
} else if (type == BlockID.WOODEN_STAIRS || type == BlockID.COBBLESTONE_STAIRS) {
|
||||||
data = (data + 1) % 4;
|
data = (data + increment) % 4;
|
||||||
} else if (type == BlockID.SIGN_POST) {
|
} else if (type == BlockID.SIGN_POST) {
|
||||||
data = (data + 1) % 16;
|
data = (data + increment) % 16;
|
||||||
} else if (type == BlockID.WALL_SIGN) {
|
} else if (type == BlockID.WALL_SIGN) {
|
||||||
if(data == 2) data = 5; else data--;
|
data = ((data + increment) - 2) % 4 + 2;
|
||||||
} else if (type == BlockID.STEP) {
|
} else if (type == BlockID.STEP) {
|
||||||
data = (data + 1) % 3;
|
data = (data + increment) % 3;
|
||||||
} else if (type == BlockID.DOUBLE_STEP) {
|
} else if (type == BlockID.DOUBLE_STEP) {
|
||||||
data = (data + 1) % 3;
|
data = (data + increment) % 3;
|
||||||
} else if (type == BlockID.FURNACE || type == BlockID.BURNING_FURNACE
|
} else if (type == BlockID.FURNACE || type == BlockID.BURNING_FURNACE
|
||||||
|| type == BlockID.DISPENSER) {
|
|| type == BlockID.DISPENSER) {
|
||||||
data = (data + 1) % 4 + 2;
|
data = (data + increment) % 4 + 2;
|
||||||
} else if (type == BlockID.PUMPKIN || type == BlockID.JACKOLANTERN) {
|
} else if (type == BlockID.PUMPKIN || type == BlockID.JACKOLANTERN) {
|
||||||
data = (data + 1) % 4;
|
data = (data + increment) % 4;
|
||||||
} else if (type == BlockID.CLOTH) {
|
} else if (type == BlockID.CLOTH) {
|
||||||
data = nextClothColor(data);
|
if (forward) {
|
||||||
|
data = nextClothColor(data);
|
||||||
|
} else {
|
||||||
|
data = prevClothColor(data);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
player.printError("That block's data cannot be cycled.");
|
player.printError("That block's data cannot be cycled.");
|
||||||
return true;
|
return true;
|
||||||
@ -88,6 +98,19 @@ public class BlockDataCyler implements BlockTool {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
|
||||||
|
LocalPlayer player, LocalSession session, WorldVector clicked) {
|
||||||
|
return handleCycle(server, config, player, session, clicked, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean actSecondary(ServerInterface server,
|
||||||
|
LocalConfiguration config, LocalPlayer player,
|
||||||
|
LocalSession session, WorldVector clicked) {
|
||||||
|
return handleCycle(server, config, player, session, clicked, false);
|
||||||
|
}
|
||||||
|
|
||||||
private static int nextClothColor(int data) {
|
private static int nextClothColor(int data) {
|
||||||
switch (data) {
|
switch (data) {
|
||||||
case 0: return 8;
|
case 0: return 8;
|
||||||
@ -110,4 +133,27 @@ public class BlockDataCyler implements BlockTool {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int prevClothColor(int data) {
|
||||||
|
switch (data) {
|
||||||
|
case 8: return 0;
|
||||||
|
case 7: return 8;
|
||||||
|
case 15: return 7;
|
||||||
|
case 12: return 15;
|
||||||
|
case 14: return 12;
|
||||||
|
case 1: return 14;
|
||||||
|
case 4: return 1;
|
||||||
|
case 5: return 4;
|
||||||
|
case 13: return 5;
|
||||||
|
case 9: return 13;
|
||||||
|
case 3: return 9;
|
||||||
|
case 11: return 3;
|
||||||
|
case 10: return 11;
|
||||||
|
case 2: return 10;
|
||||||
|
case 6: return 2;
|
||||||
|
case 0: return 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class BlockReplacer implements BlockTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean act(ServerInterface server, LocalConfiguration config,
|
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
|
||||||
LocalPlayer player, LocalSession session, WorldVector clicked) {
|
LocalPlayer player, LocalSession session, WorldVector clicked) {
|
||||||
|
|
||||||
BlockBag bag = session.getBlockBag(player);
|
BlockBag bag = session.getBlockBag(player);
|
||||||
|
@ -38,6 +38,6 @@ public interface BlockTool extends Tool {
|
|||||||
* @param clicked
|
* @param clicked
|
||||||
* @return true to deny
|
* @return true to deny
|
||||||
*/
|
*/
|
||||||
public boolean act(ServerInterface server, LocalConfiguration config,
|
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
|
||||||
LocalPlayer player, LocalSession session, WorldVector clicked);
|
LocalPlayer player, LocalSession session, WorldVector clicked);
|
||||||
}
|
}
|
||||||
|
47
src/com/sk89q/worldedit/tools/DoubleActionBlockTool.java
Normal file
47
src/com/sk89q/worldedit/tools/DoubleActionBlockTool.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldEdit
|
||||||
|
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit.tools;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.LocalConfiguration;
|
||||||
|
import com.sk89q.worldedit.LocalPlayer;
|
||||||
|
import com.sk89q.worldedit.LocalSession;
|
||||||
|
import com.sk89q.worldedit.ServerInterface;
|
||||||
|
import com.sk89q.worldedit.WorldVector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a block tool that also has a secondary/primary function.
|
||||||
|
*
|
||||||
|
* @author sk89q
|
||||||
|
*/
|
||||||
|
public interface DoubleActionBlockTool extends BlockTool {
|
||||||
|
/**
|
||||||
|
* Perform the secondary action. Should return true to deny the default
|
||||||
|
* action.
|
||||||
|
*
|
||||||
|
* @param server
|
||||||
|
* @param config
|
||||||
|
* @param player
|
||||||
|
* @param session
|
||||||
|
* @param clicked
|
||||||
|
* @return true to deny
|
||||||
|
*/
|
||||||
|
public boolean actSecondary(ServerInterface server, LocalConfiguration config,
|
||||||
|
LocalPlayer player, LocalSession session, WorldVector clicked);
|
||||||
|
}
|
@ -30,7 +30,7 @@ import com.sk89q.worldedit.blocks.*;
|
|||||||
public class QueryTool implements BlockTool {
|
public class QueryTool implements BlockTool {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean act(ServerInterface server, LocalConfiguration config,
|
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
|
||||||
LocalPlayer player, LocalSession session, WorldVector clicked) {
|
LocalPlayer player, LocalSession session, WorldVector clicked) {
|
||||||
|
|
||||||
LocalWorld world = clicked.getWorld();
|
LocalWorld world = clicked.getWorld();
|
||||||
|
@ -40,7 +40,7 @@ public class RecursivePickaxe implements BlockTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean act(ServerInterface server, LocalConfiguration config,
|
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
|
||||||
LocalPlayer player, LocalSession session, WorldVector clicked) {
|
LocalPlayer player, LocalSession session, WorldVector clicked) {
|
||||||
LocalWorld world = clicked.getWorld();
|
LocalWorld world = clicked.getWorld();
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ import com.sk89q.worldedit.blocks.BlockID;
|
|||||||
*/
|
*/
|
||||||
public class SinglePickaxe implements BlockTool {
|
public class SinglePickaxe implements BlockTool {
|
||||||
@Override
|
@Override
|
||||||
public boolean act(ServerInterface server, LocalConfiguration config,
|
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
|
||||||
LocalPlayer player, LocalSession session, WorldVector clicked) {
|
LocalPlayer player, LocalSession session, WorldVector clicked) {
|
||||||
LocalWorld world = clicked.getWorld();
|
LocalWorld world = clicked.getWorld();
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ public class TreePlanter implements BlockTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean act(ServerInterface server, LocalConfiguration config,
|
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
|
||||||
LocalPlayer player, LocalSession session, WorldVector clicked) {
|
LocalPlayer player, LocalSession session, WorldVector clicked) {
|
||||||
|
|
||||||
LocalWorld world = clicked.getWorld();
|
LocalWorld world = clicked.getWorld();
|
||||||
|
Loading…
Reference in New Issue
Block a user