From 54eed713ab7c427f42b5fb56248b1d4fcf122b48 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Fri, 23 Mar 2012 21:37:59 -0700 Subject: [PATCH] Update for recent SpoutAPI changes --- .../sk89q/worldedit/spout/SessionTimer.java | 8 +++-- .../sk89q/worldedit/spout/SpoutBiomeType.java | 18 ++++++++++ .../worldedit/spout/SpoutBiomeTypes.java | 18 ++++++++++ .../worldedit/spout/SpoutCommandSender.java | 8 +++-- .../sk89q/worldedit/spout/SpoutPlayer.java | 13 ++++--- .../worldedit/spout/SpoutPlayerBlockBag.java | 22 ++++++++---- .../worldedit/spout/SpoutServerInterface.java | 12 ++++--- .../com/sk89q/worldedit/spout/SpoutUtil.java | 8 +++-- .../com/sk89q/worldedit/spout/SpoutWorld.java | 36 +++++++++++++------ .../spout/WorldEditPlayerListener.java | 8 +++-- .../worldedit/spout/WorldEditPlugin.java | 8 +++-- .../spout/selections/CuboidSelection.java | 4 ++- .../spout/selections/RegionSelection.java | 4 ++- .../worldedit/spout/selections/Selection.java | 20 ++++++----- 14 files changed, 134 insertions(+), 53 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/spout/SessionTimer.java b/src/main/java/com/sk89q/worldedit/spout/SessionTimer.java index ca5d8ae9a..abc47f67a 100644 --- a/src/main/java/com/sk89q/worldedit/spout/SessionTimer.java +++ b/src/main/java/com/sk89q/worldedit/spout/SessionTimer.java @@ -1,7 +1,6 @@ -// $Id$ /* * WorldEdit - * Copyright (C) 2010, 2011 sk89q and contributors + * Copyright (C) 2012 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 @@ -15,7 +14,10 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ + +// $Id$ + package com.sk89q.worldedit.spout; diff --git a/src/main/java/com/sk89q/worldedit/spout/SpoutBiomeType.java b/src/main/java/com/sk89q/worldedit/spout/SpoutBiomeType.java index fcd8eb20e..2ad39464d 100644 --- a/src/main/java/com/sk89q/worldedit/spout/SpoutBiomeType.java +++ b/src/main/java/com/sk89q/worldedit/spout/SpoutBiomeType.java @@ -1,3 +1,21 @@ +/* + * WorldEdit + * Copyright (C) 2012 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.spout; import org.spout.api.generator.biome.BiomeType; diff --git a/src/main/java/com/sk89q/worldedit/spout/SpoutBiomeTypes.java b/src/main/java/com/sk89q/worldedit/spout/SpoutBiomeTypes.java index 35577ba5a..01383a8a2 100644 --- a/src/main/java/com/sk89q/worldedit/spout/SpoutBiomeTypes.java +++ b/src/main/java/com/sk89q/worldedit/spout/SpoutBiomeTypes.java @@ -1,3 +1,21 @@ +/* + * WorldEdit + * Copyright (C) 2012 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.spout; import java.util.ArrayList; diff --git a/src/main/java/com/sk89q/worldedit/spout/SpoutCommandSender.java b/src/main/java/com/sk89q/worldedit/spout/SpoutCommandSender.java index 3da348cf4..e830363c9 100644 --- a/src/main/java/com/sk89q/worldedit/spout/SpoutCommandSender.java +++ b/src/main/java/com/sk89q/worldedit/spout/SpoutCommandSender.java @@ -1,7 +1,6 @@ -// $Id$ /* * WorldEdit - * Copyright (C) 2010 sk89q and contributors + * Copyright (C) 2012 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 @@ -15,7 +14,10 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ + +// $Id$ + package com.sk89q.worldedit.spout; diff --git a/src/main/java/com/sk89q/worldedit/spout/SpoutPlayer.java b/src/main/java/com/sk89q/worldedit/spout/SpoutPlayer.java index 088598b2b..2506222ef 100644 --- a/src/main/java/com/sk89q/worldedit/spout/SpoutPlayer.java +++ b/src/main/java/com/sk89q/worldedit/spout/SpoutPlayer.java @@ -1,7 +1,6 @@ -// $Id$ /* * WorldEdit - * Copyright (C) 2010 sk89q and contributors + * Copyright (C) 2012 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 @@ -15,7 +14,10 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ + +// $Id$ + package com.sk89q.worldedit.spout; @@ -31,7 +33,8 @@ import com.sk89q.worldedit.cui.CUIEvent; import org.spout.api.entity.Entity; import org.spout.api.geo.discrete.Point; 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; public class SpoutPlayer extends LocalPlayer { @@ -75,7 +78,7 @@ public class SpoutPlayer extends LocalPlayer { @Override 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 diff --git a/src/main/java/com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java b/src/main/java/com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java index ccdf89d5a..63d8863cd 100644 --- a/src/main/java/com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java +++ b/src/main/java/com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java @@ -1,7 +1,6 @@ -// $Id$ /* * WorldEdit - * Copyright (C) 2010 sk89q and contributors + * Copyright (C) 2012 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 @@ -15,7 +14,10 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ + +// $Id$ + package com.sk89q.worldedit.spout; @@ -30,7 +32,7 @@ import com.sk89q.worldedit.blocks.BlockID; import org.spout.api.inventory.Inventory; import org.spout.api.inventory.ItemStack; import org.spout.api.material.Material; -import org.spout.api.material.MaterialData; +import org.spout.api.material.MaterialRegistry; import org.spout.api.player.Player; public class SpoutPlayerBlockBag extends BlockBag { @@ -81,7 +83,10 @@ public class SpoutPlayerBlockBag extends BlockBag { final short damage = item.getDamage(); int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 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) { throw new IllegalArgumentException("Can't fetch air block"); @@ -132,9 +137,12 @@ public class SpoutPlayerBlockBag extends BlockBag { */ @Override public void storeItem(BaseItem item) throws BlockBagException { - final int id = item.getType(); + final short id = (short) item.getType(); 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; assert(amount <= mat.getMaxStackSize()); diff --git a/src/main/java/com/sk89q/worldedit/spout/SpoutServerInterface.java b/src/main/java/com/sk89q/worldedit/spout/SpoutServerInterface.java index b4cd46d7c..55ed0c7e2 100644 --- a/src/main/java/com/sk89q/worldedit/spout/SpoutServerInterface.java +++ b/src/main/java/com/sk89q/worldedit/spout/SpoutServerInterface.java @@ -1,7 +1,6 @@ -// $Id$ /* * WorldEdit - * Copyright (C) 2010 sk89q and contributors + * Copyright (C) 2012 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 @@ -15,7 +14,10 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ + +// $Id$ + package com.sk89q.worldedit.spout; @@ -29,7 +31,7 @@ import org.spout.api.Game; import org.spout.api.Spout; import org.spout.api.geo.World; 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.util.ArrayList; @@ -51,7 +53,7 @@ public class SpoutServerInterface extends ServerInterface { @Override public int resolveItem(String name) { - Material mat = MaterialData.getMaterial(name); + Material mat = MaterialRegistry.get(name); return mat == null ? 0 : mat.getId(); } diff --git a/src/main/java/com/sk89q/worldedit/spout/SpoutUtil.java b/src/main/java/com/sk89q/worldedit/spout/SpoutUtil.java index 13d7c2c64..9141d0bbf 100644 --- a/src/main/java/com/sk89q/worldedit/spout/SpoutUtil.java +++ b/src/main/java/com/sk89q/worldedit/spout/SpoutUtil.java @@ -1,7 +1,6 @@ -// $Id$ /* * WorldEdit - * Copyright (C) 2010 sk89q and contributors + * Copyright (C) 2012 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 @@ -15,7 +14,10 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ + +// $Id$ + package com.sk89q.worldedit.spout; diff --git a/src/main/java/com/sk89q/worldedit/spout/SpoutWorld.java b/src/main/java/com/sk89q/worldedit/spout/SpoutWorld.java index 26f68fd74..e81dcab0d 100644 --- a/src/main/java/com/sk89q/worldedit/spout/SpoutWorld.java +++ b/src/main/java/com/sk89q/worldedit/spout/SpoutWorld.java @@ -1,7 +1,6 @@ -// $Id$ /* * WorldEdit - * Copyright (C) 2010 sk89q and contributors + * Copyright (C) 2012 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 @@ -15,7 +14,10 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ + +// $Id$ + package com.sk89q.worldedit.spout; @@ -37,7 +39,9 @@ import org.spout.api.generator.biome.BiomeGenerator; import org.spout.api.geo.World; import org.spout.api.geo.cuboid.Chunk; 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.vanilla.controller.object.Item; import org.spout.vanilla.controller.object.falling.PrimedTnt; @@ -84,7 +88,11 @@ public class SpoutWorld extends LocalWorld { */ @Override 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 class SpoutWorld extends LocalWorld { */ @Override 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 class SpoutWorld extends LocalWorld { */ @Override 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 class SpoutWorld extends LocalWorld { */ @Override 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 class SpoutWorld extends LocalWorld { */ @Override 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()))); } @@ -662,7 +678,7 @@ public class SpoutWorld extends LocalWorld { */ @Override public boolean isValidBlockType(int type) { - return MaterialData.getBlock((short)type) != null; + return MaterialRegistry.get((short)type) instanceof BlockMaterial; } @Override diff --git a/src/main/java/com/sk89q/worldedit/spout/WorldEditPlayerListener.java b/src/main/java/com/sk89q/worldedit/spout/WorldEditPlayerListener.java index 056b3d531..1be9cc359 100644 --- a/src/main/java/com/sk89q/worldedit/spout/WorldEditPlayerListener.java +++ b/src/main/java/com/sk89q/worldedit/spout/WorldEditPlayerListener.java @@ -1,7 +1,6 @@ -// $Id$ /* * WorldEdit - * Copyright (C) 2010 sk89q and contributors + * Copyright (C) 2012 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 @@ -15,7 +14,10 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ + +// $Id$ + package com.sk89q.worldedit.spout; diff --git a/src/main/java/com/sk89q/worldedit/spout/WorldEditPlugin.java b/src/main/java/com/sk89q/worldedit/spout/WorldEditPlugin.java index bc18eb0e7..93f5ed47e 100644 --- a/src/main/java/com/sk89q/worldedit/spout/WorldEditPlugin.java +++ b/src/main/java/com/sk89q/worldedit/spout/WorldEditPlugin.java @@ -1,7 +1,6 @@ -// $Id$ /* * WorldEdit - * Copyright (C) 2010 sk89q and contributors + * Copyright (C) 2012 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 @@ -15,7 +14,10 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ + +// $Id$ + package com.sk89q.worldedit.spout; diff --git a/src/main/java/com/sk89q/worldedit/spout/selections/CuboidSelection.java b/src/main/java/com/sk89q/worldedit/spout/selections/CuboidSelection.java index 3b66d9af1..88010978c 100644 --- a/src/main/java/com/sk89q/worldedit/spout/selections/CuboidSelection.java +++ b/src/main/java/com/sk89q/worldedit/spout/selections/CuboidSelection.java @@ -1,4 +1,3 @@ -// $Id$ /* * WorldEdit * Copyright (C) 2012 sk89q and contributors @@ -17,6 +16,9 @@ * along with this program. If not, see . */ +// $Id$ + + package com.sk89q.worldedit.spout.selections; import com.sk89q.worldedit.Vector; diff --git a/src/main/java/com/sk89q/worldedit/spout/selections/RegionSelection.java b/src/main/java/com/sk89q/worldedit/spout/selections/RegionSelection.java index 93e8a33e3..015be8e6a 100644 --- a/src/main/java/com/sk89q/worldedit/spout/selections/RegionSelection.java +++ b/src/main/java/com/sk89q/worldedit/spout/selections/RegionSelection.java @@ -1,4 +1,3 @@ -// $Id$ /* * WorldEdit * Copyright (C) 2012 sk89q and contributors @@ -17,6 +16,9 @@ * along with this program. If not, see . */ +// $Id$ + + package com.sk89q.worldedit.spout.selections; import com.sk89q.worldedit.Vector; diff --git a/src/main/java/com/sk89q/worldedit/spout/selections/Selection.java b/src/main/java/com/sk89q/worldedit/spout/selections/Selection.java index f09bf6e61..561f5b8f7 100644 --- a/src/main/java/com/sk89q/worldedit/spout/selections/Selection.java +++ b/src/main/java/com/sk89q/worldedit/spout/selections/Selection.java @@ -1,4 +1,3 @@ -// $Id$ /* * WorldEdit * Copyright (C) 2012 sk89q and contributors @@ -17,6 +16,9 @@ * along with this program. If not, see . */ +// $Id$ + + package com.sk89q.worldedit.spout.selections; import com.sk89q.worldedit.Vector; @@ -27,49 +29,49 @@ import org.spout.api.geo.discrete.Point; public interface Selection { /** * Get the lower point of a region. - * + * * @return min. point */ public Point getMinimumPoint(); /** * Get the lower point of a region. - * + * * @return min. point */ public Vector getNativeMinimumPoint(); /** * Get the upper point of a region. - * + * * @return max. point */ public Point getMaximumPoint(); /** * Get the upper point of a region. - * + * * @return max. point */ public Vector getNativeMaximumPoint(); /** * Get the region selector. This is for internal use. - * + * * @return */ public RegionSelector getRegionSelector(); /** * Get the world. - * + * * @return */ public World getWorld(); /** * Get the number of blocks in the region. - * + * * @return number of blocks */ public int getArea(); @@ -99,7 +101,7 @@ public interface Selection { * Returns true based on whether the region contains the point, * * @param pt - * @return + * @return */ public boolean contains(Point pt); }