Update for recent SpoutAPI changes

This commit is contained in:
zml2008 2012-03-23 21:37:59 -07:00
parent 97c370549f
commit 54eed713ab
14 changed files with 134 additions and 53 deletions

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;

View File

@ -1,3 +1,21 @@
/*
* WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com> 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;
import org.spout.api.generator.biome.BiomeType; import org.spout.api.generator.biome.BiomeType;

View File

@ -1,3 +1,21 @@
/*
* WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com> 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;
@ -31,7 +33,8 @@
import org.spout.api.entity.Entity; import org.spout.api.entity.Entity;
import org.spout.api.geo.discrete.Point; import org.spout.api.geo.discrete.Point;
import org.spout.api.inventory.ItemStack; import org.spout.api.inventory.ItemStack;
import org.spout.api.material.MaterialData; import org.spout.api.material.MaterialRegistry;
import org.spout.api.material.source.MaterialData;
import org.spout.api.player.Player; import org.spout.api.player.Player;
public class SpoutPlayer extends LocalPlayer { public class SpoutPlayer extends LocalPlayer {
@ -75,7 +78,7 @@ public double getYaw() {
@Override @Override
public void giveItem(int type, int amt) { public void giveItem(int type, int amt) {
player.getEntity().getInventory().addItem(new ItemStack(MaterialData.getMaterial((short)type), amt)); player.getEntity().getInventory().addItem(new ItemStack(MaterialRegistry.get((short) type), amt));
} }
@Override @Override

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;
@ -30,7 +32,7 @@
import org.spout.api.inventory.Inventory; import org.spout.api.inventory.Inventory;
import org.spout.api.inventory.ItemStack; import org.spout.api.inventory.ItemStack;
import org.spout.api.material.Material; import org.spout.api.material.Material;
import org.spout.api.material.MaterialData; import org.spout.api.material.MaterialRegistry;
import org.spout.api.player.Player; import org.spout.api.player.Player;
public class SpoutPlayerBlockBag extends BlockBag { public class SpoutPlayerBlockBag extends BlockBag {
@ -81,7 +83,10 @@ public void fetchItem(BaseItem item) throws BlockBagException {
final short damage = item.getDamage(); final short damage = item.getDamage();
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1; int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
assert(amount == 1); assert(amount == 1);
final Material mat = MaterialData.getMaterial(id, damage); Material mat = MaterialRegistry.get(id);
if (mat.hasSubMaterials()) {
mat = mat.getSubMaterial(damage);
}
if (id == BlockID.AIR) { if (id == BlockID.AIR) {
throw new IllegalArgumentException("Can't fetch air block"); throw new IllegalArgumentException("Can't fetch air block");
@ -132,9 +137,12 @@ public void fetchItem(BaseItem item) throws BlockBagException {
*/ */
@Override @Override
public void storeItem(BaseItem item) throws BlockBagException { public void storeItem(BaseItem item) throws BlockBagException {
final int id = item.getType(); final short id = (short) item.getType();
final short damage = item.getDamage(); final short damage = item.getDamage();
final Material mat = MaterialData.getMaterial((short) id, damage); Material mat = MaterialRegistry.get(id);
if (mat.hasSubMaterials()) {
mat = mat.getSubMaterial(damage);
}
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1; int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
assert(amount <= mat.getMaxStackSize()); assert(amount <= mat.getMaxStackSize());

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;
@ -29,7 +31,7 @@
import org.spout.api.Spout; import org.spout.api.Spout;
import org.spout.api.geo.World; import org.spout.api.geo.World;
import org.spout.api.material.Material; import org.spout.api.material.Material;
import org.spout.api.material.MaterialData; import org.spout.api.material.MaterialRegistry;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
@ -51,7 +53,7 @@ public SpoutServerInterface(WorldEditPlugin plugin, Game game) {
@Override @Override
public int resolveItem(String name) { public int resolveItem(String name) {
Material mat = MaterialData.getMaterial(name); Material mat = MaterialRegistry.get(name);
return mat == null ? 0 : mat.getId(); return mat == null ? 0 : mat.getId();
} }

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;
@ -37,7 +39,9 @@
import org.spout.api.geo.World; import org.spout.api.geo.World;
import org.spout.api.geo.cuboid.Chunk; import org.spout.api.geo.cuboid.Chunk;
import org.spout.api.inventory.ItemStack; import org.spout.api.inventory.ItemStack;
import org.spout.api.material.MaterialData; import org.spout.api.material.BlockMaterial;
import org.spout.api.material.Material;
import org.spout.api.material.MaterialRegistry;
import org.spout.api.math.Vector3; import org.spout.api.math.Vector3;
import org.spout.vanilla.controller.object.Item; import org.spout.vanilla.controller.object.Item;
import org.spout.vanilla.controller.object.falling.PrimedTnt; import org.spout.vanilla.controller.object.falling.PrimedTnt;
@ -84,7 +88,11 @@ public String getName() {
*/ */
@Override @Override
public boolean setBlockType(Vector pt, int type) { public boolean setBlockType(Vector pt, int type) {
return world.setBlockId(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), (short) type, WorldEditPlugin.getInstance()); Material mat = MaterialRegistry.get((short) type);
if (mat != null && mat instanceof BlockMaterial) {
return world.setBlockMaterial(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), (BlockMaterial) mat, (short)0, true, WorldEditPlugin.getInstance());
}
return false;
} }
/** /**
@ -108,7 +116,11 @@ public boolean setBlockTypeFast(Vector pt, int type) {
*/ */
@Override @Override
public boolean setTypeIdAndData(Vector pt, int type, int data) { public boolean setTypeIdAndData(Vector pt, int type, int data) {
return world.setBlockIdAndData(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), (short) type, (short) data, WorldEditPlugin.getInstance()); Material mat = MaterialRegistry.get((short) type);
if (mat != null && mat instanceof BlockMaterial) {
return world.setBlockMaterial(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), (BlockMaterial) mat, (short)data, true, WorldEditPlugin.getInstance());
}
return false;
} }
/** /**
@ -132,7 +144,7 @@ public boolean setTypeIdAndDataFast(Vector pt, int type, int data) {
*/ */
@Override @Override
public int getBlockType(Vector pt) { public int getBlockType(Vector pt) {
return world.getBlockId(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); return world.getBlockMaterial(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getId();
} }
/** /**
@ -143,7 +155,7 @@ public int getBlockType(Vector pt) {
*/ */
@Override @Override
public void setBlockData(Vector pt, int data) { public void setBlockData(Vector pt, int data) {
setTypeIdAndData(pt, world.getBlockId(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()), data); world.setBlockData(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), (short) data, true, WorldEditPlugin.getInstance());
} }
/** /**
@ -414,7 +426,11 @@ public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession
*/ */
@Override @Override
public void dropItem(Vector pt, BaseItemStack item) { public void dropItem(Vector pt, BaseItemStack item) {
ItemStack bukkitItem = new ItemStack(MaterialData.getMaterial((short)item.getType(), item.getDamage()), item.getAmount(), item.getDamage()); Material mat = MaterialRegistry.get((short) item.getType());
if (mat.hasSubMaterials()) {
mat = mat.getSubMaterial(item.getDamage());
}
ItemStack bukkitItem = new ItemStack(mat, item.getDamage(), item.getAmount());
world.createAndSpawnEntity(SpoutUtil.toPoint(world, pt), new Item(bukkitItem, new Vector3(pt.getX(), pt.getY(), pt.getZ()))); world.createAndSpawnEntity(SpoutUtil.toPoint(world, pt), new Item(bukkitItem, new Vector3(pt.getX(), pt.getY(), pt.getZ())));
} }
@ -662,7 +678,7 @@ public int removeEntities(EntityType type, Vector origin, int radius) {
*/ */
@Override @Override
public boolean isValidBlockType(int type) { public boolean isValidBlockType(int type) {
return MaterialData.getBlock((short)type) != null; return MaterialRegistry.get((short)type) instanceof BlockMaterial;
} }
@Override @Override

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;

View File

@ -1,4 +1,3 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
@ -17,6 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout.selections; package com.sk89q.worldedit.spout.selections;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;

View File

@ -1,4 +1,3 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
@ -17,6 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout.selections; package com.sk89q.worldedit.spout.selections;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;

View File

@ -1,4 +1,3 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
@ -17,6 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout.selections; package com.sk89q.worldedit.spout.selections;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;