3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-25 10:30:04 +01:00

Worked around changes in hMod regarding chests.

Dieser Commit ist enthalten in:
sk89q 2010-12-29 23:56:21 -08:00
Ursprung 912468f8a1
Commit 7499a04e65
2 geänderte Dateien mit 63 neuen und 40 gelöschten Zeilen

Datei anzeigen

@ -123,17 +123,7 @@ public class EditSession {
// Chests
} else if (block instanceof ChestBlock) {
ChestBlock chestBlock = (ChestBlock)block;
BaseItem blankItem = new BaseItem((short)1);
Map<Byte,Countable<BaseItem>> items = chestBlock.getItems();
for (byte i = 0; i <= 26; i++) {
Countable<BaseItem> item = items.get(i);
if (item != null) {
ServerInterface.setChestSlot(pt, i, item.getID(),
item.getAmount());
} else {
ServerInterface.setChestSlot(pt, i, blankItem, 0);
}
}
ServerInterface.setChestContents(pt, chestBlock.getItems());
// Mob spawners
} else if (block instanceof MobSpawnerBlock) {
MobSpawnerBlock mobSpawnerblock = (MobSpawnerBlock)block;
@ -248,7 +238,8 @@ public class EditSession {
return new SignBlock(type, data, text);
// Chest
} else if (type == 54) {
Map<Byte,Countable<BaseItem>> items = ServerInterface.getChestContents(pt);
Map<Byte,Countable<BaseItem>> items =
ServerInterface.getChestContents(pt);
return new ChestBlock(data, items);
// Mob spawner
} else if (type == 52) {

Datei anzeigen

@ -19,6 +19,8 @@
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BlockType;
import java.util.logging.Logger;
import java.util.Map;
import java.util.HashMap;
@ -126,28 +128,34 @@ public class ServerInterface {
}
/**
* Gets the contents of chests.
* Gets the contents of chests. Will return null if the chest does not
* really exist or it is the second block for a double chest.
*
* @param pt
* @return
*/
public static Map<Byte,Countable<BaseItem>> getChestContents(Vector pt) {
ComplexBlock cblock = etc.getServer().getComplexBlock(
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (!(cblock instanceof Chest)) {
Map<Byte,Countable<BaseItem>> items;
Item[] nativeItems;
if (cblock instanceof Chest) {
Chest chest = (Chest)cblock;
nativeItems = chest.getContents();
} else {
return null;
}
Chest chest = (Chest)cblock;
Map<Byte,Countable<BaseItem>> items =
new HashMap<Byte,Countable<BaseItem>>();
items = new HashMap<Byte,Countable<BaseItem>>();
for (byte i = 0; i <= 26; i++) {
Item item = chest.getItemFromSlot(i);
for (byte i = 0; i < nativeItems.length; i++) {
Item item = nativeItems[i];
if (item != null) {
items.put(i, new Countable<BaseItem>(new BaseItem((short)item.getItemId()),
item.getAmount()));
items.put(i,
new Countable<BaseItem>(
new BaseItem((short)item.getItemId()), item.getAmount()));
}
}
@ -158,23 +166,29 @@ public class ServerInterface {
* Sets a chest slot.
*
* @param pt
* @param slot
* @param item
* @param amount
* @param contents
* @return
*/
public static boolean setChestSlot(Vector pt, byte slot, BaseItem item, int amount) {
ComplexBlock cblock = etc.getServer().getComplexBlock(
public static boolean setChestContents(Vector pt,
Map<Byte,Countable<BaseItem>> contents) {
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (!(cblock instanceof Chest)) {
return false;
if (cblock instanceof Chest) {
Chest chest = (Chest)cblock;
Item[] nativeItems = new Item[contents.size()];
for (Map.Entry<Byte,Countable<BaseItem>> entry : contents.entrySet()) {
nativeItems[entry.getKey()] =
new Item(entry.getValue().getID().getID(),
entry.getValue().getAmount());
}
setContents(chest, nativeItems);
}
Chest chest = (Chest)cblock;
chest.addItem(new Item(item.getID(), amount, slot));
chest.update();
return true;
return false;
}
/**
@ -183,18 +197,36 @@ public class ServerInterface {
* @param pt
*/
public static boolean clearChest(Vector pt) {
ComplexBlock cblock = etc.getServer().getComplexBlock(
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (!(cblock instanceof Chest)) {
return false;
if (cblock instanceof Chest) {
Chest chest = (Chest)cblock;
chest.clearContents();
chest.update();
return true;
}
Chest chest = (Chest)cblock;
chest.clearContents();
chest.update();
return true;
return false;
}
/**
* Set the contents of an ItemArray.
*
* @param itemArray
* @param contents
*/
private static void setContents(ItemArray<?> itemArray, Item[] contents) {
int size = contents.length;
for (int i = 0; i < size; i++) {
if (contents[i] == null) {
itemArray.removeItem(i);
} else {
itemArray.setSlot(contents[i], i);
}
}
}
/**