use of com.github.steveice10.opennbt.tag.builtin.IntArrayTag in project Geyser by GeyserMC.
the class FireworkBaseTranslator method translateExplosionToJava.
protected CompoundTag translateExplosionToJava(CompoundTag explosion, String newName) {
CompoundTag newExplosionData = new CompoundTag(newName);
if (explosion.get("FireworkType") != null) {
newExplosionData.put(new ByteTag("Type", MathUtils.getNbtByte(explosion.get("FireworkType").getValue())));
}
if (explosion.get("FireworkColor") != null) {
byte[] oldColors = (byte[]) explosion.get("FireworkColor").getValue();
int[] colors = new int[oldColors.length];
int i = 0;
for (byte color : oldColors) {
colors[i++] = FireworkColor.fromBedrockId(color);
}
newExplosionData.put(new IntArrayTag("Colors", colors));
}
if (explosion.get("FireworkFade") != null) {
byte[] oldColors = (byte[]) explosion.get("FireworkFade").getValue();
int[] colors = new int[oldColors.length];
int i = 0;
for (byte color : oldColors) {
colors[i++] = FireworkColor.fromBedrockId(color);
}
newExplosionData.put(new IntArrayTag("FadeColors", colors));
}
if (explosion.get("FireworkTrail") != null) {
newExplosionData.put(new ByteTag("Trail", MathUtils.getNbtByte(explosion.get("FireworkTrail").getValue())));
}
if (explosion.get("FireworkFlicker") != null) {
newExplosionData.put(new ByteTag("Flicker", MathUtils.getNbtByte(explosion.get("FireworkFlicker").getValue())));
}
return newExplosionData;
}
use of com.github.steveice10.opennbt.tag.builtin.IntArrayTag in project Geyser by GeyserMC.
the class FireworkStarTranslator method translateToBedrock.
@Override
public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
Tag explosion = itemTag.get("Explosion");
if (explosion instanceof CompoundTag) {
CompoundTag newExplosion = translateExplosionToBedrock((CompoundTag) explosion, "FireworksItem");
itemTag.remove("Explosion");
itemTag.put(newExplosion);
Tag color = ((CompoundTag) explosion).get("Colors");
if (color instanceof IntArrayTag) {
// Determine the custom color, if any.
// Mostly replicates Java's own rendering code, as Java determines the final firework star color client-side
// while Bedrock determines it server-side.
int[] colors = ((IntArrayTag) color).getValue();
if (colors.length == 0) {
return;
}
int finalColor;
if (colors.length == 1) {
finalColor = colors[0];
} else {
int r = 0;
int g = 0;
int b = 0;
for (int fireworkColor : colors) {
r += (fireworkColor & (255 << 16)) >> 16;
g += (fireworkColor & (255 << 8)) >> 8;
b += fireworkColor & 255;
}
r /= colors.length;
g /= colors.length;
b /= colors.length;
finalColor = r << 16 | g << 8 | b;
}
itemTag.put(new IntTag("customColor", finalColor));
}
}
}
use of com.github.steveice10.opennbt.tag.builtin.IntArrayTag in project ViaVersion by ViaVersion.
the class TagStringReader method array.
/**
* Similar to a list tag in syntax, but returning a single array tag rather than a list of tags.
*
* @return array-typed tag
*/
public Tag array(char elementType) throws StringTagParseException {
this.buffer.expect(Tokens.ARRAY_BEGIN).expect(elementType).expect(Tokens.ARRAY_SIGNATURE_SEPARATOR);
elementType = Character.toLowerCase(elementType);
if (elementType == Tokens.TYPE_BYTE) {
return new ByteArrayTag(this.byteArray());
} else if (elementType == Tokens.TYPE_INT) {
return new IntArrayTag(this.intArray());
} else if (elementType == Tokens.TYPE_LONG) {
return new LongArrayTag(this.longArray());
} else {
throw this.buffer.makeError("Type " + elementType + " is not a valid element type in an array!");
}
}
use of com.github.steveice10.opennbt.tag.builtin.IntArrayTag in project ViaVersion by ViaVersion.
the class InventoryPackets method handleItemToServer.
@Override
public Item handleItemToServer(Item item) {
if (item == null)
return null;
item.setIdentifier(Protocol1_16To1_15_2.MAPPINGS.getOldItemId(item.identifier()));
if (item.identifier() == 771 && item.tag() != null) {
CompoundTag tag = item.tag();
Tag ownerTag = tag.get("SkullOwner");
if (ownerTag instanceof CompoundTag) {
CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
Tag idTag = ownerCompundTag.get("Id");
if (idTag instanceof IntArrayTag) {
UUID id = UUIDIntArrayType.uuidFromIntArray((int[]) idTag.getValue());
ownerCompundTag.put("Id", new StringTag(id.toString()));
}
}
}
newToOldAttributes(item);
return item;
}
use of com.github.steveice10.opennbt.tag.builtin.IntArrayTag in project ViaVersion by ViaVersion.
the class InventoryPackets method newToOldAttributes.
public static void newToOldAttributes(Item item) {
if (item.tag() == null)
return;
ListTag attributes = item.tag().get("AttributeModifiers");
if (attributes == null)
return;
for (Tag tag : attributes) {
CompoundTag attribute = (CompoundTag) tag;
rewriteAttributeName(attribute, "AttributeName", true);
rewriteAttributeName(attribute, "Name", true);
IntArrayTag uuidTag = attribute.get("UUID");
if (uuidTag != null && uuidTag.getValue().length == 4) {
UUID uuid = UUIDIntArrayType.uuidFromIntArray(uuidTag.getValue());
attribute.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits()));
attribute.put("UUIDMost", new LongTag(uuid.getMostSignificantBits()));
}
}
}
Aggregations