use of net.minecraft.nbt.NbtList in project Liminal-Library by LudoCrypt.
the class NbtPlacerUtil method load.
public static Optional<NbtPlacerUtil> load(ResourceManager manager, Identifier id) {
try {
Optional<NbtCompound> nbtOptional = loadNbtFromFile(manager, id);
if (nbtOptional.isPresent()) {
NbtCompound nbt = nbtOptional.get();
NbtList paletteList = nbt.getList("palette", 10);
HashMap<Integer, BlockState> palette = new HashMap<Integer, BlockState>(paletteList.size());
List<NbtCompound> paletteCompoundList = paletteList.stream().filter(nbtElement -> nbtElement instanceof NbtCompound).map(element -> (NbtCompound) element).toList();
for (int i = 0; i < paletteCompoundList.size(); i++) {
palette.put(i, NbtHelper.toBlockState(paletteCompoundList.get(i)));
}
NbtList sizeList = nbt.getList("size", 3);
BlockPos sizeVectorRotated = new BlockPos(sizeList.getInt(0), sizeList.getInt(1), sizeList.getInt(2));
BlockPos sizeVector = new BlockPos(Math.abs(sizeVectorRotated.getX()), Math.abs(sizeVectorRotated.getY()), Math.abs(sizeVectorRotated.getZ()));
NbtList positionsList = nbt.getList("blocks", 10);
HashMap<BlockPos, Pair<BlockState, NbtCompound>> positions = new HashMap<BlockPos, Pair<BlockState, NbtCompound>>(positionsList.size());
List<Pair<BlockPos, Pair<BlockState, NbtCompound>>> positionsPairList = positionsList.stream().filter(nbtElement -> nbtElement instanceof NbtCompound).map(element -> (NbtCompound) element).map((nbtCompound) -> Pair.of(new BlockPos(nbtCompound.getList("pos", 3).getInt(0), nbtCompound.getList("pos", 3).getInt(1), nbtCompound.getList("pos", 3).getInt(2)), Pair.of(palette.get(nbtCompound.getInt("state")), nbtCompound.getCompound("nbt")))).sorted(Comparator.comparing((pair) -> pair.getFirst().getX())).sorted(Comparator.comparing((pair) -> pair.getFirst().getY())).sorted(Comparator.comparing((pair) -> pair.getFirst().getZ())).toList();
positionsPairList.forEach((pair) -> positions.put(pair.getFirst().subtract(positionsPairList.get(0).getFirst()), pair.getSecond()));
return Optional.of(new NbtPlacerUtil(nbt, positions, nbt.getList("entities", 10), positionsPairList.get(0).getFirst(), sizeVector));
}
throw new NullPointerException();
} catch (Exception e) {
e.printStackTrace();
return Optional.empty();
}
}
use of net.minecraft.nbt.NbtList in project Liminal-Library by LudoCrypt.
the class NbtPlacerUtil method rotate.
public NbtPlacerUtil rotate(BlockRotation rotation) {
NbtList paletteList = storedNbt.getList("palette", 10);
HashMap<Integer, BlockState> palette = new HashMap<Integer, BlockState>(paletteList.size());
List<NbtCompound> paletteCompoundList = paletteList.stream().filter(nbtElement -> nbtElement instanceof NbtCompound).map(element -> (NbtCompound) element).toList();
for (int i = 0; i < paletteCompoundList.size(); i++) {
palette.put(i, NbtHelper.toBlockState(paletteCompoundList.get(i)).rotate(rotation));
}
NbtList sizeList = storedNbt.getList("size", 3);
BlockPos sizeVectorRotated = new BlockPos(sizeList.getInt(0), sizeList.getInt(1), sizeList.getInt(2)).rotate(rotation);
BlockPos sizeVector = new BlockPos(Math.abs(sizeVectorRotated.getX()), Math.abs(sizeVectorRotated.getY()), Math.abs(sizeVectorRotated.getZ()));
NbtList positionsList = storedNbt.getList("blocks", 10);
HashMap<BlockPos, Pair<BlockState, NbtCompound>> positions = new HashMap<BlockPos, Pair<BlockState, NbtCompound>>(positionsList.size());
List<Pair<BlockPos, Pair<BlockState, NbtCompound>>> positionsPairList = positionsList.stream().filter(nbtElement -> nbtElement instanceof NbtCompound).map(element -> (NbtCompound) element).map((nbtCompound) -> Pair.of(new BlockPos(nbtCompound.getList("pos", 3).getInt(0), nbtCompound.getList("pos", 3).getInt(1), nbtCompound.getList("pos", 3).getInt(2)).rotate(rotation), Pair.of(palette.get(nbtCompound.getInt("state")), nbtCompound.getCompound("nbt")))).sorted(Comparator.comparing((pair) -> pair.getFirst().getX())).sorted(Comparator.comparing((pair) -> pair.getFirst().getY())).sorted(Comparator.comparing((pair) -> pair.getFirst().getZ())).toList();
positionsPairList.forEach((pair) -> positions.put(pair.getFirst().subtract(positionsPairList.get(0).getFirst()), pair.getSecond()));
return new NbtPlacerUtil(storedNbt, positions, storedNbt.getList("entities", 10), positionsPairList.get(0).getFirst(), sizeVector);
}
use of net.minecraft.nbt.NbtList in project Liminal-Library by LudoCrypt.
the class NbtPlacerUtil method createNbtIntList.
public static NbtList createNbtIntList(int... ints) {
NbtList nbtList = new NbtList();
int[] var3 = ints;
int var4 = ints.length;
for (int var5 = 0; var5 < var4; ++var5) {
int i = var3[var5];
nbtList.add(NbtInt.of(i));
}
return nbtList;
}
use of net.minecraft.nbt.NbtList in project frame-fabric by moddingplayground.
the class LoomScreenMixin method saveFrameBannerPatterns.
@Inject(method = "onInventoryChanged", at = @At("RETURN"))
private void saveFrameBannerPatterns(CallbackInfo ci) {
if (this.bannerPatterns != null) {
ItemStack banner = (this.handler).getOutputSlot().getStack();
NbtList ls = FrameBannerPatternConversions.getNbt(banner);
frame_bannerPatterns = FrameBannerPatternConversions.makeData(ls);
} else
frame_bannerPatterns = Collections.emptyList();
}
use of net.minecraft.nbt.NbtList in project frame-fabric by moddingplayground.
the class LoomScreenMixin method proxyPutPatterns.
/**
* If the pattern index indicates a Frame pattern, put the Frame
* pattern in the item NBT instead of a vanilla pattern.
*/
@Redirect(method = "drawBanner", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NbtCompound;put(Ljava/lang/String;Lnet/minecraft/nbt/NbtElement;)Lnet/minecraft/nbt/NbtElement;", ordinal = 0))
private NbtElement proxyPutPatterns(NbtCompound nbt, String key, NbtElement patterns) {
frame_singlePattern.clear();
if (frame_bannerPatternIndex < 0) {
int frameBannerPatternIdx = -frame_bannerPatternIndex - (1 + BannerPattern.LOOM_APPLICABLE_COUNT);
FrameBannerPattern pattern = FrameBannerPatternsInternal.get(frameBannerPatternIdx);
NbtList framePatterns = new NbtList();
NbtCompound patternNbtElement = new NbtCompound();
patternNbtElement.putString("Pattern", pattern.getId().toString());
patternNbtElement.putInt("Color", 0);
patternNbtElement.putInt("Index", 1);
framePatterns.add(patternNbtElement);
// pop dummy vanilla banner pattern
NbtList vanillaPatterns = (NbtList) patterns;
assert vanillaPatterns.size() == 2 : vanillaPatterns.size();
vanillaPatterns.remove(1);
nbt.put(FrameBannerPatternAccess.NBT_KEY, framePatterns);
frame_singlePattern.add(new FrameBannerPatternData(pattern, DyeColor.WHITE, 1));
}
FrameBannerPatternRenderContext.setFrameBannerPatterns(frame_singlePattern);
return nbt.put(key, patterns);
}
Aggregations