mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-06 20:56:41 +00:00
Remove a tonne of code from WorldEdit. This breaks backwards compatibility. More will be removed. Sorry :)
This commit is contained in:
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.blocks;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.NBTUtils;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.storage.InvalidFormatException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents a chest block.
|
||||
*/
|
||||
public class ChestBlock extends ContainerBlock {
|
||||
|
||||
/**
|
||||
* Construct an empty chest block with the default orientation (data value).
|
||||
*/
|
||||
public ChestBlock() {
|
||||
super(BlockID.CHEST, 27);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an empty chest block with a custom data value.
|
||||
*
|
||||
* @param data data indicating the position of the chest
|
||||
*/
|
||||
public ChestBlock(int data) {
|
||||
super(BlockID.CHEST, data, 27);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the chest block with a custom data value and a list of items.
|
||||
*
|
||||
* @param data data indicating the position of the chest
|
||||
* @param items array of items
|
||||
*/
|
||||
public ChestBlock(int data, BaseItemStack[] items) {
|
||||
super(BlockID.CHEST, data, 27);
|
||||
setItems(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNbtId() {
|
||||
return "Chest";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getNbtData() {
|
||||
Map<String, Tag> values = new HashMap<String, Tag>();
|
||||
values.put("Items", new ListTag(CompoundTag.class, serializeInventory(getItems())));
|
||||
return new CompoundTag(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNbtData(CompoundTag rootTag) {
|
||||
if (rootTag == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Tag> values = rootTag.getValue();
|
||||
|
||||
Tag t = values.get("id");
|
||||
if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Chest")) {
|
||||
throw new RuntimeException("'Chest' tile entity expected");
|
||||
}
|
||||
|
||||
List<CompoundTag> items = new ArrayList<CompoundTag>();
|
||||
|
||||
try {
|
||||
for (Tag tag : NBTUtils.getChildTag(values, "Items", ListTag.class).getValue()) {
|
||||
if (!(tag instanceof CompoundTag)) {
|
||||
throw new RuntimeException("CompoundTag expected as child tag of Chest's Items");
|
||||
}
|
||||
|
||||
items.add((CompoundTag) tag);
|
||||
}
|
||||
|
||||
setItems(deserializeInventory(items));
|
||||
} catch (InvalidFormatException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (DataException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.blocks;
|
||||
|
||||
import com.sk89q.jnbt.ByteTag;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.NBTUtils;
|
||||
import com.sk89q.jnbt.ShortTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents a block that stores items.
|
||||
*/
|
||||
public abstract class ContainerBlock extends BaseBlock implements TileEntityBlock {
|
||||
|
||||
private BaseItemStack[] items;
|
||||
|
||||
public ContainerBlock(int type, int inventorySize) {
|
||||
super(type);
|
||||
this.items = new BaseItemStack[inventorySize];
|
||||
}
|
||||
|
||||
public ContainerBlock(int type, int data, int inventorySize) {
|
||||
super(type, data);
|
||||
this.items = new BaseItemStack[inventorySize];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of items.
|
||||
*
|
||||
* @return an array of stored items
|
||||
*/
|
||||
public BaseItemStack[] getItems() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of items.
|
||||
*
|
||||
* @param items an array of stored items
|
||||
*/
|
||||
public void setItems(BaseItemStack[] items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNbtData() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Map<String, Tag> serializeItem(BaseItemStack item) {
|
||||
Map<String, Tag> data = new HashMap<String, Tag>();
|
||||
data.put("id", new ShortTag((short) item.getType()));
|
||||
data.put("Damage", new ShortTag(item.getData()));
|
||||
data.put("Count", new ByteTag((byte) item.getAmount()));
|
||||
if (!item.getEnchantments().isEmpty()) {
|
||||
List<CompoundTag> enchantmentList = new ArrayList<CompoundTag>();
|
||||
for(Map.Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) {
|
||||
Map<String, Tag> enchantment = new HashMap<String, Tag>();
|
||||
enchantment.put("id", new ShortTag(entry.getKey().shortValue()));
|
||||
enchantment.put("lvl", new ShortTag(entry.getValue().shortValue()));
|
||||
enchantmentList.add(new CompoundTag(enchantment));
|
||||
}
|
||||
|
||||
Map<String, Tag> auxData = new HashMap<String, Tag>();
|
||||
auxData.put("ench", new ListTag(CompoundTag.class, enchantmentList));
|
||||
data.put("tag", new CompoundTag(auxData));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public BaseItemStack deserializeItem(Map<String, Tag> data) throws DataException {
|
||||
short id = NBTUtils.getChildTag(data, "id", ShortTag.class).getValue();
|
||||
short damage = NBTUtils.getChildTag(data, "Damage", ShortTag.class).getValue();
|
||||
byte count = NBTUtils.getChildTag(data, "Count", ByteTag.class).getValue();
|
||||
|
||||
BaseItemStack stack = new BaseItemStack(id, count, damage);
|
||||
|
||||
if (data.containsKey("tag")) {
|
||||
Map<String, Tag> auxData = NBTUtils.getChildTag(data, "tag", CompoundTag.class).getValue();
|
||||
ListTag ench = (ListTag)auxData.get("ench");
|
||||
for(Tag e : ench.getValue()) {
|
||||
Map<String, Tag> vars = ((CompoundTag) e).getValue();
|
||||
short enchId = NBTUtils.getChildTag(vars, "id", ShortTag.class).getValue();
|
||||
short enchLevel = NBTUtils.getChildTag(vars, "lvl", ShortTag.class).getValue();
|
||||
stack.getEnchantments().put((int) enchId, (int) enchLevel);
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
public BaseItemStack[] deserializeInventory(List<CompoundTag> items) throws DataException {
|
||||
BaseItemStack[] stacks = new BaseItemStack[items.size()];
|
||||
for (CompoundTag tag : items) {
|
||||
Map<String, Tag> item = tag.getValue();
|
||||
BaseItemStack stack = deserializeItem(item);
|
||||
byte slot = NBTUtils.getChildTag(item, "Slot", ByteTag.class).getValue();
|
||||
if (slot >= 0 && slot < stacks.length) {
|
||||
stacks[slot] = stack;
|
||||
}
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
public List<CompoundTag> serializeInventory(BaseItemStack[] items) {
|
||||
List<CompoundTag> tags = new ArrayList<CompoundTag>();
|
||||
for (int i = 0; i < items.length; ++i) {
|
||||
if (items[i] != null) {
|
||||
Map<String, Tag> tagData = serializeItem(items[i]);
|
||||
tagData.put("Slot", new ByteTag((byte) i));
|
||||
tags.add(new CompoundTag(tagData));
|
||||
}
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.blocks;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.NBTUtils;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents dispensers.
|
||||
*/
|
||||
public class DispenserBlock extends ContainerBlock {
|
||||
|
||||
/**
|
||||
* Construct an empty dispenser block.
|
||||
*/
|
||||
public DispenserBlock() {
|
||||
super(BlockID.DISPENSER, 9);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an empty dispenser block.
|
||||
*
|
||||
* @param data data value (orientation)
|
||||
*/
|
||||
public DispenserBlock(int data) {
|
||||
super(BlockID.DISPENSER, data, 9);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a dispenser block with the given orientation and inventory.
|
||||
*
|
||||
* @param data data value (orientation)
|
||||
* @param items array of items in the inventory
|
||||
*/
|
||||
public DispenserBlock(int data, BaseItemStack[] items) {
|
||||
super(BlockID.DISPENSER, data, 9);
|
||||
this.setItems(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNbtId() {
|
||||
return "Trap";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getNbtData() {
|
||||
Map<String, Tag> values = new HashMap<String, Tag>();
|
||||
values.put("Items", new ListTag(CompoundTag.class, serializeInventory(getItems())));
|
||||
return new CompoundTag(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNbtData(CompoundTag rootTag) {
|
||||
try {
|
||||
if (rootTag == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Tag> values = rootTag.getValue();
|
||||
|
||||
Tag t = values.get("id");
|
||||
if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Trap")) {
|
||||
throw new DataException("'Trap' tile entity expected");
|
||||
}
|
||||
|
||||
List<CompoundTag> items = new ArrayList<CompoundTag>();
|
||||
for (Tag tag : NBTUtils.getChildTag(values, "Items", ListTag.class).getValue()) {
|
||||
if (!(tag instanceof CompoundTag)) {
|
||||
throw new DataException("CompoundTag expected as child tag of Trap Items");
|
||||
}
|
||||
|
||||
items.add((CompoundTag) tag);
|
||||
}
|
||||
|
||||
setItems(deserializeInventory(items));
|
||||
} catch (DataException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,165 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.blocks;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.NBTUtils;
|
||||
import com.sk89q.jnbt.ShortTag;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents a furnace block.
|
||||
*/
|
||||
public class FurnaceBlock extends ContainerBlock {
|
||||
|
||||
private short burnTime;
|
||||
private short cookTime;
|
||||
|
||||
/**
|
||||
* Construct an empty furnace block with the default orientation.
|
||||
*
|
||||
* @param type type ID
|
||||
*/
|
||||
public FurnaceBlock(int type) {
|
||||
super(type, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an empty furnace block with a given orientation.
|
||||
*
|
||||
* @param type type ID
|
||||
* @param data orientation
|
||||
*/
|
||||
public FurnaceBlock(int type, int data) {
|
||||
super(type, data, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an furnace block with a given orientation and inventory.
|
||||
*
|
||||
* @param type type ID
|
||||
* @param data orientation
|
||||
* @param items inventory items
|
||||
*/
|
||||
public FurnaceBlock(int type, int data, BaseItemStack[] items) {
|
||||
super(type, data, 2);
|
||||
setItems(items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the burn time.
|
||||
*
|
||||
* @return the burn time
|
||||
*/
|
||||
public short getBurnTime() {
|
||||
return burnTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the burn time.
|
||||
*
|
||||
* @param burnTime the burn time
|
||||
*/
|
||||
public void setBurnTime(short burnTime) {
|
||||
this.burnTime = burnTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cook time.
|
||||
*
|
||||
* @return the cook time
|
||||
*/
|
||||
public short getCookTime() {
|
||||
return cookTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cook time.
|
||||
*
|
||||
* @param cookTime the cook time to set
|
||||
*/
|
||||
public void setCookTime(short cookTime) {
|
||||
this.cookTime = cookTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNbtId() {
|
||||
return "Furnace";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getNbtData() {
|
||||
Map<String, Tag> values = new HashMap<String, Tag>();
|
||||
values.put("Items", new ListTag(CompoundTag.class, serializeInventory(getItems())));
|
||||
values.put("BurnTime", new ShortTag(burnTime));
|
||||
values.put("CookTime", new ShortTag(cookTime));
|
||||
return new CompoundTag(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNbtData(CompoundTag rootTag) {
|
||||
if (rootTag == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Map<String, Tag> values = rootTag.getValue();
|
||||
|
||||
Tag t = values.get("id");
|
||||
if (!(t instanceof StringTag)
|
||||
|| !((StringTag) t).getValue().equals("Furnace")) {
|
||||
throw new RuntimeException("'Furnace' tile entity expected");
|
||||
}
|
||||
|
||||
ListTag items = NBTUtils.getChildTag(values, "Items", ListTag.class);
|
||||
|
||||
List<CompoundTag> compound = new ArrayList<CompoundTag>();
|
||||
|
||||
for (Tag tag : items.getValue()) {
|
||||
if (!(tag instanceof CompoundTag)) {
|
||||
throw new RuntimeException("CompoundTag expected as child tag of Furnace Items");
|
||||
}
|
||||
compound.add((CompoundTag) tag);
|
||||
}
|
||||
setItems(deserializeInventory(compound));
|
||||
|
||||
t = values.get("BurnTime");
|
||||
if (t instanceof ShortTag) {
|
||||
burnTime = ((ShortTag) t).getValue();
|
||||
}
|
||||
|
||||
t = values.get("CookTime");
|
||||
if (t instanceof ShortTag) {
|
||||
cookTime = ((ShortTag) t).getValue();
|
||||
}
|
||||
} catch (DataException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user