use of net.minecraft.nbt.ListTag in project SpongeCommon by SpongePowered.
the class SpongeEntityArchetype method getPosition.
public Optional<Vector3d> getPosition() {
if (this.position != null) {
return Optional.of(this.position);
}
if (!this.compound.contains(Constants.Entity.ENTITY_POSITION, Constants.NBT.TAG_LIST)) {
return Optional.empty();
}
try {
final ListTag pos = this.compound.getList(Constants.Entity.ENTITY_POSITION, Constants.NBT.TAG_DOUBLE);
final double x = pos.getDouble(0);
final double y = pos.getDouble(1);
final double z = pos.getDouble(2);
this.position = new Vector3d(x, y, z);
return Optional.of(this.position);
} catch (final Exception e) {
return Optional.empty();
}
}
use of net.minecraft.nbt.ListTag in project SpongeCommon by SpongePowered.
the class SpongeEntityArchetype method getRotation.
private Vector3d getRotation() {
final ListTag tag = this.compound.getList("Rotation", 5);
final float rotationYaw = tag.getFloat(0);
final float rotationPitch = tag.getFloat(1);
return new Vector3d(rotationPitch, rotationYaw, 0);
}
use of net.minecraft.nbt.ListTag in project SpongeCommon by SpongePowered.
the class DamageEventUtil method createAttackEnchantmentFunction.
public static List<DamageFunction> createAttackEnchantmentFunction(final net.minecraft.world.item.ItemStack heldItem, final MobType creatureAttribute, final float attackStrength) {
if (heldItem.isEmpty()) {
return Collections.emptyList();
}
final ListTag enchantmentCompounds = heldItem.getEnchantmentTags();
if (enchantmentCompounds.isEmpty()) {
return Collections.emptyList();
}
final Map<Enchantment, Collection<Integer>> enchantments = new HashMap<>();
for (int i = 0; i < enchantmentCompounds.size(); ++i) {
final String id = enchantmentCompounds.getCompound(i).getString("id");
final int enchantmentLevel = enchantmentCompounds.getCompound(i).getInt("lvl");
final Enchantment enchantment = Registry.ENCHANTMENT.get(new ResourceLocation(id));
if (enchantment != null) {
enchantments.computeIfAbsent(enchantment, k -> new ArrayList<>()).add(enchantmentLevel);
}
}
if (enchantments.isEmpty()) {
return Collections.emptyList();
}
final List<DamageFunction> damageModifierFunctions = new ArrayList<>();
final ItemStackSnapshot snapshot = ItemStackUtil.snapshotOf(heldItem);
for (final Map.Entry<Enchantment, Collection<Integer>> enchantment : enchantments.entrySet()) {
final DamageModifier enchantmentModifier = DamageModifier.builder().type(DamageModifierTypes.WEAPON_ENCHANTMENT).cause(Cause.of(EventContext.empty(), snapshot, enchantment)).build();
final DoubleUnaryOperator enchantmentFunction = (damage) -> {
double totalDamage = 0;
for (final int level : enchantment.getValue()) {
totalDamage += (double) enchantment.getKey().getDamageBonus(level, creatureAttribute) * attackStrength;
}
return totalDamage;
};
damageModifierFunctions.add(new DamageFunction(enchantmentModifier, enchantmentFunction));
}
return damageModifierFunctions;
}
use of net.minecraft.nbt.ListTag in project SpongeCommon by SpongePowered.
the class WritableBookItemMixin_LimitBookSize method impl$useMaxBookSizeFromConfig.
@Inject(method = "makeSureTagIsValid", cancellable = true, at = @At(value = "RETURN"))
private static void impl$useMaxBookSizeFromConfig(final CompoundTag p_150930_0_, final CallbackInfoReturnable<Boolean> cir) {
if (cir.getReturnValue()) {
final ListTag listnbt = p_150930_0_.getList("pages", 8);
final int size = IntStream.range(0, listnbt.size()).mapToObj(listnbt::getString).mapToInt(s -> s.getBytes(StandardCharsets.UTF_8).length).sum();
if (size > SpongeConfigs.getCommon().get().exploits.maxBookSize) {
cir.setReturnValue(false);
}
}
}
use of net.minecraft.nbt.ListTag in project SpongeCommon by SpongePowered.
the class BannerBlockEntityMixin method bridge$setLayers.
@Override
public void bridge$setLayers(final List<BannerPatternLayer> layers) {
this.impl$patternLayers = NonNullList.create();
this.impl$patternLayers.addAll(layers);
this.itemPatterns = new ListTag();
for (final BannerPatternLayer layer : this.impl$patternLayers) {
this.itemPatterns.add(ShieldItemStackData.layerToNbt(layer));
}
this.impl$markDirtyAndUpdate();
}
Aggregations