mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 10:56:42 +00:00
The goal is to replace use of CuboidClipboard with these new classes. Support for entities, //flip, //rotate, and //distr still needs to be re-implemented. DataException was also removed from BaseBlock because The Base(...) classes should be "dumb" blocks without any validation.
113 lines
3.4 KiB
Java
113 lines
3.4 KiB
Java
/*
|
|
* 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.
|
|
*
|
|
* @author sk89q
|
|
*/
|
|
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("Items", CompoundTag.class, serializeInventory(getItems())));
|
|
return new CompoundTag(getNbtId(), 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);
|
|
}
|
|
}
|
|
}
|