use of net.minecraft.nbt.NBTBase in project RFToolsDimensions by McJty.
the class RFToolsTools method convertNBTtoJson.
public static void convertNBTtoJson(StringBuffer buffer, NBTTagCompound tagCompound, int indent) {
boolean first = true;
for (Object o : tagCompound.getKeySet()) {
if (!first) {
buffer.append(",\n");
}
first = false;
String key = (String) o;
NBTBase tag = tagCompound.getTag(key);
appendIndent(buffer, indent).append(key).append(':');
if (tag instanceof NBTTagCompound) {
NBTTagCompound compound = (NBTTagCompound) tag;
buffer.append("{\n");
convertNBTtoJson(buffer, compound, indent + 4);
appendIndent(buffer, indent).append('}');
} else if (tag instanceof NBTTagList) {
NBTTagList list = (NBTTagList) tag;
buffer.append("[\n");
convertNBTtoJson(buffer, list, indent + 4);
appendIndent(buffer, indent).append(']');
} else {
buffer.append(tag);
}
}
if (!first) {
buffer.append("\n");
}
}
use of net.minecraft.nbt.NBTBase in project RecurrentComplex by Ivorforce.
the class TableDataSourceNBTTagCompound method cellForIndexInSegment.
@Override
public TableCell cellForIndexInSegment(GuiTable table, int index, int segment) {
if (segment == 0) {
TableCellButton load = new TableCellButton(null, "toString", "->", Collections.singletonList("Convert to String (slightly lossy)"), true);
TableCellButton perform = new TableCellButton(null, "fromString", "O", Collections.singletonList("Load from String"), false);
TableCellString cell = new TableCellString("tileEntityInfo", "");
cell.addPropertyConsumer(val -> perform.setEnabled(WeightedBlockState.tryParse(val) != null));
// FromGuiCommandBlock
cell.setMaxStringLength(32500);
load.addAction(() -> {
cell.setPropertyValue(nbt.toString());
perform.setEnabled(true);
});
perform.addAction(() -> {
NBTTagCompound other = WeightedBlockState.tryParse(cell.getPropertyValue());
if (other != null) {
nbt.getKeySet().clear();
other.getKeySet().forEach(s -> nbt.setTag(s, other.getTag(s)));
resetSortedKeys();
delegate.reloadData();
}
});
TableCellMulti multi = new TableCellMulti(load, cell, perform);
multi.setSize(0, 0.1f);
multi.setSize(2, 0.1f);
return new TitledCell("As String", multi);
} else if (segment == 1 || segment == 3) {
return new TableCellPresetAction(null, IntStream.range(0, 12).mapToObj((id) -> TableDataSourceNBT.addButton(id, n -> {
nbt.setTag("", n);
sortedKeys.removeIf(s -> s.equals(""));
sortedKeys.add(segment == 1 ? 0 : sortedKeys.size(), "");
delegate.reloadData();
})).collect(Collectors.toList()));
} else {
String key = sortedKeys.get(index);
String[] nextKey = new String[] { key };
NBTBase cellNBT = nbt.getTag(key);
TableCell nbtCell = TableDataSourceNBT.cell(cellNBT, delegate, navigator);
TableCellString keyCell = new TableCellString(null, key);
TableCellButton setKeyCell = new TableCellButton(null, "setKey", "O", Collections.singletonList("Set Key"), false);
setKeyCell.addAction(() -> {
sortedKeys.set(index, nextKey[0]);
// If there was a previous entry
sortedKeys.subList(index + 1, sortedKeys.size()).remove(nextKey[0]);
sortedKeys.subList(0, index).remove(nextKey[0]);
nbt.removeTag(key);
nbt.setTag(nextKey[0], cellNBT);
delegate.reloadData();
});
keyCell.addPropertyConsumer(value -> {
nextKey[0] = value;
setKeyCell.setEnabled(true);
});
TableCellButton deleteCell = new TableCellButton(null, null, TextFormatting.RED + "-");
deleteCell.addAction(() -> {
sortedKeys.remove(key);
nbt.removeTag(key);
delegate.reloadData();
});
TableCellMulti multi = new TableCellMulti(keyCell, setKeyCell, nbtCell, deleteCell);
multi.setSize(1, 0.2f);
multi.setSize(3, 0.2f);
return multi;
}
}
use of net.minecraft.nbt.NBTBase in project Engine by VoltzEngine-Project.
the class EffectList method trigger.
@Override
public void trigger(World world, double x, double y, double z, double mx, double my, double mz, boolean endPoint, NBTTagCompound nbt) {
for (IEffectData layer : layers) {
NBTTagCompound usedNBT;
if (nbt != null && !nbt.hasNoTags()) {
usedNBT = (NBTTagCompound) nbt.copy();
//Merges base NBT with server nbt
if (this.getNbt() != null) {
for (Object o : getNbt().func_150296_c()) {
if (o instanceof String) {
String key = (String) o;
NBTBase tag = getNbt().getTag(key);
if (tag != null) {
usedNBT.setTag(key, tag);
}
}
}
}
} else if (this.getNbt() != null) {
usedNBT = nbt;
} else {
usedNBT = new NBTTagCompound();
}
Pos renderOffset = this.renderOffset;
if (renderOffset != Pos.zero && (usedNBT.hasKey("yaw") || usedNBT.hasKey("pitch"))) {
float yaw = usedNBT.getFloat("yaw");
float pitch = usedNBT.getFloat("pitch");
angle.set(yaw, pitch, 0);
renderOffset = (Pos) angle.transform(renderOffset);
}
layer.trigger(world, x + renderOffset.x(), y + renderOffset.y(), z + renderOffset.z(), mx, my, mz, endPoint, usedNBT);
}
}
Aggregations