use of net.minecraft.nbt.NbtList in project Primeval by devs-immortal.
the class VesselItem method getBundledStacks.
private static Stream<ItemStack> getBundledStacks(ItemStack stack) {
NbtCompound nbtCompound = stack.getNbt();
if (nbtCompound == null) {
return Stream.empty();
} else {
NbtList nbtList = nbtCompound.getList("Items", 10);
Stream<NbtElement> var10000 = nbtList.stream();
Objects.requireNonNull(NbtCompound.class);
return var10000.map(NbtCompound.class::cast).map(ItemStack::fromNbt);
}
}
use of net.minecraft.nbt.NbtList in project Primeval by devs-immortal.
the class VesselItem method addToBundle.
private static int addToBundle(ItemStack bundle, ItemStack stack) {
if (!stack.isEmpty() && stack.getItem().canBeNested() && canAddItem(bundle)) {
NbtCompound nbtCompound = bundle.getOrCreateNbt();
if (!nbtCompound.contains("Items")) {
nbtCompound.put("Items", new NbtList());
}
int i = getBundleOccupancy(bundle);
int j = getItemOccupancy(stack);
int k = Math.min(stack.getCount(), (64 - i) / j);
if (k == 0) {
return 0;
} else {
NbtList nbtList = nbtCompound.getList("Items", 10);
Optional<NbtCompound> optional = canMergeStack(stack, nbtList);
if (optional.isPresent()) {
NbtCompound nbtCompound2 = optional.get();
ItemStack itemStack = ItemStack.fromNbt(nbtCompound2);
itemStack.increment(k);
itemStack.writeNbt(nbtCompound2);
nbtList.remove(nbtCompound2);
nbtList.add(0, nbtCompound2);
} else {
ItemStack nbtCompound2 = stack.copy();
nbtCompound2.setCount(k);
NbtCompound itemStack = new NbtCompound();
nbtCompound2.writeNbt(itemStack);
nbtList.add(0, itemStack);
}
return k;
}
} else {
return 0;
}
}
use of net.minecraft.nbt.NbtList in project meteor-rejects by AntiCope.
the class HeadScreen method createHeadStack.
private ItemStack createHeadStack(String uuid, String value, String name) {
ItemStack head = Items.PLAYER_HEAD.getDefaultStack();
NbtCompound tag = new NbtCompound();
NbtCompound skullOwner = new NbtCompound();
skullOwner.putUuid("Id", UUID.fromString(uuid));
NbtCompound properties = new NbtCompound();
NbtList textures = new NbtList();
NbtCompound Value = new NbtCompound();
Value.putString("Value", value);
textures.add(Value);
properties.put("textures", textures);
skullOwner.put("Properties", properties);
tag.put("SkullOwner", skullOwner);
head.setNbt(tag);
head.setCustomName(new LiteralText(name));
return head;
}
use of net.minecraft.nbt.NbtList in project FabricWaystones by LordDeatHunter.
the class WaystoneStorage method toTag.
public NbtCompound toTag(NbtCompound tag) {
if (tag == null) {
tag = new NbtCompound();
}
NbtList waystones = new NbtList();
for (Map.Entry<String, WaystoneValue> waystone : WAYSTONES.entrySet()) {
String hash = waystone.getKey();
WaystoneValue entity = waystone.getValue();
NbtCompound waystoneTag = new NbtCompound();
waystoneTag.putString("hash", hash);
waystoneTag.putString("name", entity.getWaystoneName());
BlockPos pos = entity.way_getPos();
waystoneTag.putIntArray("position", Arrays.asList(pos.getX(), pos.getY(), pos.getZ()));
waystoneTag.putString("dimension", entity.getWorldName());
waystones.add(waystoneTag);
}
tag.put("waystones", waystones);
NbtList globals = new NbtList();
var globalWaystones = getGlobals();
for (String globalWaystone : globalWaystones) {
globals.add(NbtString.of(globalWaystone));
}
tag.put("global_waystones", globals);
return tag;
}
use of net.minecraft.nbt.NbtList in project FabricWaystones by LordDeatHunter.
the class CompatibilityLayer method writeNbt.
public NbtCompound writeNbt(NbtCompound tag) {
if (COMPATABILITY_ENABLED)
return tag;
if (tag == null)
tag = new NbtCompound();
NbtList compatWaystones = new NbtList();
for (Map.Entry<String, HashSet<String>> player : COMPATABILITY_MAP.entrySet()) {
NbtCompound playerTag = new NbtCompound();
playerTag.putString("username", player.getKey());
NbtList knownWaystones = new NbtList();
for (String hash : player.getValue()) {
NbtCompound waystone = new NbtCompound();
waystone.putString("hash", hash);
knownWaystones.add(waystone);
}
playerTag.put("waystones", knownWaystones);
compatWaystones.add(playerTag);
}
tag.put("waystones_compat", compatWaystones);
return tag;
}
Aggregations