use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.
the class SpongeTagTemplate method toJson.
public JsonObject toJson() {
final Tag.Builder builder = new Tag.Builder();
this.elements.forEach((k, v) -> {
final ResourceLocation location = (ResourceLocation) (Object) k;
// "N/A" is supposed to be the source, but we don't know it, and we're serializing it so it isn't used anyway. (Gone when we serializeToJson)
builder.add(v ? new Tag.ElementEntry(location) : new Tag.OptionalElementEntry(location), "N/A");
});
this.subTags.forEach((k, v) -> {
final ResourceLocation location = (ResourceLocation) (Object) k;
builder.add(v ? new Tag.TagEntry(location) : new Tag.OptionalTagEntry(location), "N/A");
});
return builder.serializeToJson();
}
use of net.minecraft.resources.ResourceLocation 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.resources.ResourceLocation in project SpongeCommon by SpongePowered.
the class RegistryMixin_API method valueKey.
@Override
public ResourceKey valueKey(final T value) {
Objects.requireNonNull(value, "value");
final ResourceLocation key = this.shadow$getKey(value);
if (key == null) {
throw new IllegalStateException(String.format("No key was found for '%s'!", value));
}
return (ResourceKey) (Object) key;
}
use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.
the class LevelMixin_API method playSound.
// ArchetypeVolumeCreator
// Audience
@Override
public void playSound(final Sound sound, final double x, final double y, final double z) {
// Check if the event is registered (ie has an integer ID)
final ResourceLocation soundKey = SpongeAdventure.asVanilla(sound.name());
final Optional<SoundEvent> event = Registry.SOUND_EVENT.getOptional(soundKey);
final SoundSource soundCategory = SpongeAdventure.asVanilla(sound.source());
if (event.isPresent()) {
this.shadow$playSound(null, x, y, z, event.get(), soundCategory, sound.volume(), sound.pitch());
} else {
// Otherwise send it as a custom sound
final float volume = sound.volume();
final double radius = volume > 1.0f ? (16.0f * volume) : 16.0d;
final ClientboundCustomSoundPacket packet = new ClientboundCustomSoundPacket(soundKey, soundCategory, new net.minecraft.world.phys.Vec3(x, y, z), volume, sound.pitch());
this.shadow$getServer().getPlayerList().broadcast(null, x, y, z, radius, this.shadow$dimension(), packet);
}
}
use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.
the class SpongeAdvancementBuilder method build0.
@Override
public Advancement build0() {
final Tuple<Map<String, Criterion>, String[][]> result = SpongeCriterionUtil.toVanillaCriteriaData(this.criterion);
final AdvancementRewards rewards = AdvancementRewards.EMPTY;
final ResourceLocation resourceLocation = (ResourceLocation) (Object) key;
final net.minecraft.advancements.DisplayInfo displayInfo = this.displayInfo == null ? null : new net.minecraft.advancements.DisplayInfo(ItemStackUtil.fromSnapshotToNative(this.displayInfo.icon()), SpongeAdventure.asVanilla(this.displayInfo.title()), SpongeAdventure.asVanilla(this.displayInfo.description()), this.backgroundPath, (FrameType) (Object) this.displayInfo.type(), this.displayInfo.doesShowToast(), this.displayInfo.doesAnnounceToChat(), this.displayInfo.isHidden());
final net.minecraft.advancements.Advancement parent = (net.minecraft.advancements.Advancement) this.parent;
final Advancement advancement = (Advancement) new net.minecraft.advancements.Advancement(resourceLocation, parent, displayInfo, rewards, result.first(), result.second());
((AdvancementBridge) advancement).bridge$setCriterion(this.criterion);
return advancement;
}
Aggregations