use of net.minecraft.nbt.NbtCompound in project EdenClient by HahaOO7.
the class StringStringMapLoader method parse.
public NbtCompound parse(String s) {
NbtCompound tag = new NbtCompound();
if (s.isEmpty())
return tag;
String[] a = s.split(";");
for (int i = 0; i < a.length; i++) {
String k = a[i];
i++;
tag.putString(k, a[i]);
}
return tag;
}
use of net.minecraft.nbt.NbtCompound in project Industrious by Pbone3.
the class MachineBlockEntity method readNbt.
@Override
public void readNbt(NbtCompound tag) {
super.readNbt(tag);
NbtCompound components = tag.getCompound("components");
for (String key : machineComponents.keySet()) {
if (!components.contains(key, 10))
continue;
NbtCompound componentData = components.getCompound(key);
BaseComponent component = machineComponents.getOrDefault(key, null);
if (component != null) {
component.readNbt(componentData);
}
}
}
use of net.minecraft.nbt.NbtCompound in project Liminal-Library by LudoCrypt.
the class NbtPlacerUtil method spawnEntities.
public NbtPlacerUtil spawnEntities(ChunkRegion region, BlockPos pos, BlockRotation rotation) {
this.entities.forEach((nbtElement) -> {
NbtCompound entityCompound = (NbtCompound) nbtElement;
NbtList nbtPos = entityCompound.getList("blockPos", 3);
Vec3d realPosition = rotate(new Vec3d(nbtPos.getInt(0), nbtPos.getInt(1), nbtPos.getInt(2)), rotation).subtract(Vec3d.of(lowestPos)).add(pos.getX(), pos.getY(), pos.getZ());
NbtCompound nbt = entityCompound.getCompound("nbt").copy();
nbt.remove("Pos");
nbt.remove("UUID");
NbtList posList = new NbtList();
posList.add(NbtDouble.of(realPosition.x));
posList.add(NbtDouble.of(realPosition.y));
posList.add(NbtDouble.of(realPosition.z));
nbt.put("Pos", posList);
NbtList rotationList = new NbtList();
NbtList entityRotationList = nbt.getList("Rotation", 5);
float yawRotation = applyRotation(entityRotationList.getFloat(0), rotation);
rotationList.add(NbtFloat.of(yawRotation));
rotationList.add(NbtFloat.of(entityRotationList.getFloat(1)));
nbt.remove("Rotation");
nbt.put("Rotation", rotationList);
if (nbt.contains("Facing")) {
Direction dir = rotation.rotate(Direction.fromHorizontal(nbt.getByte("Facing")));
nbt.remove("Facing");
nbt.putByte("Facing", (byte) dir.getHorizontal());
}
getEntity(region, nbt).ifPresent((entity) -> {
entity.refreshPositionAndAngles(realPosition.x, realPosition.y, realPosition.z, yawRotation, entity.getPitch());
region.spawnEntity(entity);
});
});
return this;
}
use of net.minecraft.nbt.NbtCompound in project frame-fabric by moddingplayground.
the class FrameBannerPatternConversions method makeData.
/**
* Parses the given NBT data into a list of {@link FrameBannerPatternData} objects.
*
* @param nbt a nullable {@link NbtList} with Frame banner pattern data
*/
public static List<FrameBannerPatternData> makeData(NbtList nbt) {
List<FrameBannerPatternData> res = new ArrayList<>();
if (nbt != null) {
for (NbtElement t : nbt) {
NbtCompound patternNbt = (NbtCompound) t;
FrameBannerPattern pattern = FrameBannerPatterns.REGISTRY.get(new Identifier(patternNbt.getString("Pattern")));
if (pattern != null) {
DyeColor color = DyeColor.byId(patternNbt.getInt("Color"));
int index = patternNbt.getInt("Index");
res.add(new FrameBannerPatternData(pattern, color, index));
}
}
}
return res;
}
use of net.minecraft.nbt.NbtCompound in project frame-fabric by moddingplayground.
the class BannerBlockEntityMixin method cleanFrameBannerPattern.
/**
* Handles removing Frame banner patterns instead of vanilla banner patterns
* when a banner is cleaned in a cauldron. Yes, this is an "inject-and-cancel"
* callback. Let me know if there are incompatibilities.
*/
@Inject(method = "loadFromItemStack", at = @At("HEAD"), cancellable = true)
private static void cleanFrameBannerPattern(ItemStack stack, CallbackInfo info) {
NbtCompound beTag = stack.getSubNbt("BlockEntityTag");
if (beTag != null) {
NbtList framePatterns = beTag.getList(FrameBannerPatternAccess.NBT_KEY, 10);
NbtList patterns = beTag.getList("Patterns", 10);
boolean cleaned = false;
if (!framePatterns.isEmpty()) {
// determine if the last banner pattern is the topmost
int lastIndex = framePatterns.getCompound(framePatterns.size() - 1).getInt("Index");
if (lastIndex >= patterns.size()) {
framePatterns.remove(framePatterns.size() - 1);
cleaned = true;
}
}
if (!cleaned && !patterns.isEmpty()) {
patterns.remove(patterns.size() - 1);
}
if (framePatterns.isEmpty()) {
if (patterns.isEmpty()) {
stack.removeSubNbt("BlockEntityTag");
} else {
beTag.remove(FrameBannerPatternAccess.NBT_KEY);
}
} else if (patterns.isEmpty()) {
beTag.remove("Patterns");
}
}
info.cancel();
}
Aggregations