use of net.minecraft.nbt.NbtList 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.NbtList 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();
}
use of net.minecraft.nbt.NbtList in project frame-fabric by moddingplayground.
the class BannerBlockEntityMixin method frame_setBannerPatternNbt.
@Override
public void frame_setBannerPatternNbt(NbtList nbt) {
frame_bannerPatternsTag = nbt;
if (frame_bannerPatternsTag != null) {
// validate NBT data, removing and/or resetting invalid data
for (Iterator<NbtElement> itr = frame_bannerPatternsTag.iterator(); itr.hasNext(); ) {
NbtCompound element = (NbtCompound) itr.next();
Identifier id = Identifier.tryParse(element.getString("Pattern"));
int colorId = element.getInt("Color");
int index = element.getInt("Index");
if (id == null || !FrameBannerPatterns.REGISTRY.getIds().contains(id)) {
itr.remove();
} else {
int rtColorId = DyeColor.byId(colorId).getId();
if (rtColorId != colorId) {
element.putInt("Color", rtColorId);
}
if (index < 0) {
element.putInt("Index", 0);
}
}
}
// the Java API requires that this sort be stable
frame_bannerPatternsTag.sort(comparingInt(t -> ((NbtCompound) t).getInt("Index")));
}
}
use of net.minecraft.nbt.NbtList in project frame-fabric by moddingplayground.
the class ClientBannerBlockEntityMixin method putFrameBannerPatternsInPickStack.
/**
* Adds Frame banner pattern data to the pick block stack.
*/
@Inject(method = "getPickStack", at = @At("RETURN"))
private void putFrameBannerPatternsInPickStack(CallbackInfoReturnable<ItemStack> info) {
ItemStack stack = info.getReturnValue();
NbtList tag = ((Internal) this).frame_getBannerPatternNbt();
if (tag != null) {
stack.getOrCreateSubNbt("BlockEntityTag").put(NBT_KEY, tag);
}
}
use of net.minecraft.nbt.NbtList in project frame-fabric by moddingplayground.
the class BuiltinModelItemRendererMixin method setFrameBannerPatterns.
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/block/entity/BannerBlockEntityRenderer;renderCanvas(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/model/ModelPart;Lnet/minecraft/client/util/SpriteIdentifier;ZLjava/util/List;Z)V"))
private void setFrameBannerPatterns(ItemStack stack, ModelTransformation.Mode mode, MatrixStack matrices, VertexConsumerProvider vertices, int light, int overlay, CallbackInfo ci) {
NbtList nbt = FrameBannerPatternConversions.getNbt(stack);
FrameBannerPatternRenderContext.setFrameBannerPatterns(FrameBannerPatternConversions.makeData(nbt));
}
Aggregations