Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.event.cause.entity.damage.source.DamageSource;
import org.spongepowered.api.registry.DefaultedRegistryValue;
import org.spongepowered.api.tag.Tag;
import org.spongepowered.api.tag.Taggable;
import org.spongepowered.api.util.CopyableBuilder;
import org.spongepowered.api.util.Nameable;
Expand Down Expand Up @@ -65,15 +64,6 @@ static Builder builder() {
*/
double exhaustion();

/**
* Checks whether this damage types matches a damage type tag.
*
* @param tag The tag to check.
* @return true if this damage type matches the damage type tag.
*/
@Override
boolean is(Tag<DamageType> tag);

/**
* Returns the damage scaling.
*
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/spongepowered/api/registry/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -128,7 +127,7 @@ default <V extends T> Optional<V> findValue(final RegistryKey<T> key) {
*
* @return The registered types associated with given tag
*/
<V extends T> Set<V> taggedValues(Tag<T> tag);
<V extends T> Stream<V> taggedValues(Tag<T> tag);

/**
* Gets the tags associated with this registry.
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/org/spongepowered/api/registry/RegistryTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
package org.spongepowered.api.registry;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.spongepowered.api.ResourceKey;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.advancement.Advancement;
Expand Down Expand Up @@ -103,7 +102,6 @@
import org.spongepowered.api.effect.potion.PotionEffectType;
import org.spongepowered.api.effect.sound.SoundType;
import org.spongepowered.api.effect.sound.music.MusicDisc;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityCategory;
import org.spongepowered.api.entity.EntityType;
import org.spongepowered.api.entity.ai.goal.GoalExecutorType;
Expand Down Expand Up @@ -234,7 +232,7 @@ public final class RegistryTypes {

public static final DefaultedRegistryType<EntityCategory> ENTITY_CATEGORY = RegistryTypes.spongeKeyInGame("mob_category");

public static final DefaultedRegistryType<EntityType<? extends @NonNull Entity>> ENTITY_TYPE = RegistryTypes.minecraftKeyInGame("entity_type");
public static final DefaultedRegistryType<EntityType<?>> ENTITY_TYPE = RegistryTypes.minecraftKeyInGame("entity_type");

public static final DefaultedRegistryType<Feature> FEATURE = RegistryTypes.minecraftKeyInServer("worldgen/configured_feature");

Expand Down Expand Up @@ -270,7 +268,7 @@ public final class RegistryTypes {

public static final DefaultedRegistryType<PotionType> POTION_TYPE = RegistryTypes.minecraftKeyInGame("potion");

public static final DefaultedRegistryType<RecipeType<? extends @NonNull Recipe<?>>> RECIPE_TYPE = RegistryTypes.minecraftKeyInGame("recipe_type");
public static final DefaultedRegistryType<RecipeType<?>> RECIPE_TYPE = RegistryTypes.minecraftKeyInGame("recipe_type");

public static final DefaultedRegistryType<SoundType> SOUND_TYPE = RegistryTypes.minecraftKeyInGame("sound_event");

Expand All @@ -284,7 +282,7 @@ public final class RegistryTypes {

public static final DefaultedRegistryType<StructureType> STRUCTURE_TYPE = RegistryTypes.minecraftKeyInGame("worldgen/structure_type");

public static final DefaultedRegistryType<Trigger<? extends @NonNull Object>> TRIGGER = RegistryTypes.minecraftKeyInGame("trigger_type");
public static final DefaultedRegistryType<Trigger<?>> TRIGGER = RegistryTypes.minecraftKeyInGame("trigger_type");

public static final DefaultedRegistryType<TrimMaterial> TRIM_MATERIAL = RegistryTypes.minecraftKeyInServer("trim_material");

Expand Down Expand Up @@ -337,7 +335,7 @@ public final class RegistryTypes {

public static final DefaultedRegistryType<CommandRegistrarType<?>> COMMAND_REGISTRAR_TYPE = RegistryTypes.spongeKeyInGame("command_registrar_type");

public static final DefaultedRegistryType<CommandTreeNodeType<? extends @NonNull Object>> COMMAND_TREE_NODE_TYPE = RegistryTypes.spongeKeyInServer("command_tree_node_type");
public static final DefaultedRegistryType<CommandTreeNodeType<?>> COMMAND_TREE_NODE_TYPE = RegistryTypes.spongeKeyInServer("command_tree_node_type");

public static final DefaultedRegistryType<ComparatorMode> COMPARATOR_MODE = RegistryTypes.spongeKeyInGame("comparator_mode");

Expand Down
144 changes: 72 additions & 72 deletions src/main/java/org/spongepowered/api/tag/BiomeTags.java

Large diffs are not rendered by default.

376 changes: 188 additions & 188 deletions src/main/java/org/spongepowered/api/tag/BlockTypeTags.java

Large diffs are not rendered by default.

70 changes: 35 additions & 35 deletions src/main/java/org/spongepowered/api/tag/DamageTypeTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,76 +37,76 @@
@RegistryScopes(scopes = RegistryScope.GAME)
public final class DamageTypeTags {

public static final Tag<DamageType> ALWAYS_HURTS_ENDER_DRAGONS = DamageTypeTags.key(ResourceKey.minecraft("always_hurts_ender_dragons"));
public static final DefaultedTag<DamageType> ALWAYS_HURTS_ENDER_DRAGONS = DamageTypeTags.key(ResourceKey.minecraft("always_hurts_ender_dragons"));

public static final Tag<DamageType> ALWAYS_KILLS_ARMOR_STANDS = DamageTypeTags.key(ResourceKey.minecraft("always_kills_armor_stands"));
public static final DefaultedTag<DamageType> ALWAYS_KILLS_ARMOR_STANDS = DamageTypeTags.key(ResourceKey.minecraft("always_kills_armor_stands"));

public static final Tag<DamageType> ALWAYS_MOST_SIGNIFICANT_FALL = DamageTypeTags.key(ResourceKey.minecraft("always_most_significant_fall"));
public static final DefaultedTag<DamageType> ALWAYS_MOST_SIGNIFICANT_FALL = DamageTypeTags.key(ResourceKey.minecraft("always_most_significant_fall"));

public static final Tag<DamageType> ALWAYS_TRIGGERS_SILVERFISH = DamageTypeTags.key(ResourceKey.minecraft("always_triggers_silverfish"));
public static final DefaultedTag<DamageType> ALWAYS_TRIGGERS_SILVERFISH = DamageTypeTags.key(ResourceKey.minecraft("always_triggers_silverfish"));

public static final Tag<DamageType> AVOIDS_GUARDIAN_THORNS = DamageTypeTags.key(ResourceKey.minecraft("avoids_guardian_thorns"));
public static final DefaultedTag<DamageType> AVOIDS_GUARDIAN_THORNS = DamageTypeTags.key(ResourceKey.minecraft("avoids_guardian_thorns"));

public static final Tag<DamageType> BURN_FROM_STEPPING = DamageTypeTags.key(ResourceKey.minecraft("burn_from_stepping"));
public static final DefaultedTag<DamageType> BURN_FROM_STEPPING = DamageTypeTags.key(ResourceKey.minecraft("burn_from_stepping"));

public static final Tag<DamageType> BURNS_ARMOR_STANDS = DamageTypeTags.key(ResourceKey.minecraft("burns_armor_stands"));
public static final DefaultedTag<DamageType> BURNS_ARMOR_STANDS = DamageTypeTags.key(ResourceKey.minecraft("burns_armor_stands"));

public static final Tag<DamageType> BYPASSES_ARMOR = DamageTypeTags.key(ResourceKey.minecraft("bypasses_armor"));
public static final DefaultedTag<DamageType> BYPASSES_ARMOR = DamageTypeTags.key(ResourceKey.minecraft("bypasses_armor"));

public static final Tag<DamageType> BYPASSES_EFFECTS = DamageTypeTags.key(ResourceKey.minecraft("bypasses_effects"));
public static final DefaultedTag<DamageType> BYPASSES_EFFECTS = DamageTypeTags.key(ResourceKey.minecraft("bypasses_effects"));

public static final Tag<DamageType> BYPASSES_ENCHANTMENTS = DamageTypeTags.key(ResourceKey.minecraft("bypasses_enchantments"));
public static final DefaultedTag<DamageType> BYPASSES_ENCHANTMENTS = DamageTypeTags.key(ResourceKey.minecraft("bypasses_enchantments"));

public static final Tag<DamageType> BYPASSES_INVULNERABILITY = DamageTypeTags.key(ResourceKey.minecraft("bypasses_invulnerability"));
public static final DefaultedTag<DamageType> BYPASSES_INVULNERABILITY = DamageTypeTags.key(ResourceKey.minecraft("bypasses_invulnerability"));

public static final Tag<DamageType> BYPASSES_RESISTANCE = DamageTypeTags.key(ResourceKey.minecraft("bypasses_resistance"));
public static final DefaultedTag<DamageType> BYPASSES_RESISTANCE = DamageTypeTags.key(ResourceKey.minecraft("bypasses_resistance"));

public static final Tag<DamageType> BYPASSES_SHIELD = DamageTypeTags.key(ResourceKey.minecraft("bypasses_shield"));
public static final DefaultedTag<DamageType> BYPASSES_SHIELD = DamageTypeTags.key(ResourceKey.minecraft("bypasses_shield"));

public static final Tag<DamageType> BYPASSES_WOLF_ARMOR = DamageTypeTags.key(ResourceKey.minecraft("bypasses_wolf_armor"));
public static final DefaultedTag<DamageType> BYPASSES_WOLF_ARMOR = DamageTypeTags.key(ResourceKey.minecraft("bypasses_wolf_armor"));

public static final Tag<DamageType> CAN_BREAK_ARMOR_STAND = DamageTypeTags.key(ResourceKey.minecraft("can_break_armor_stand"));
public static final DefaultedTag<DamageType> CAN_BREAK_ARMOR_STAND = DamageTypeTags.key(ResourceKey.minecraft("can_break_armor_stand"));

public static final Tag<DamageType> DAMAGES_HELMET = DamageTypeTags.key(ResourceKey.minecraft("damages_helmet"));
public static final DefaultedTag<DamageType> DAMAGES_HELMET = DamageTypeTags.key(ResourceKey.minecraft("damages_helmet"));

public static final Tag<DamageType> IGNITES_ARMOR_STANDS = DamageTypeTags.key(ResourceKey.minecraft("ignites_armor_stands"));
public static final DefaultedTag<DamageType> IGNITES_ARMOR_STANDS = DamageTypeTags.key(ResourceKey.minecraft("ignites_armor_stands"));

public static final Tag<DamageType> IS_DROWNING = DamageTypeTags.key(ResourceKey.minecraft("is_drowning"));
public static final DefaultedTag<DamageType> IS_DROWNING = DamageTypeTags.key(ResourceKey.minecraft("is_drowning"));

public static final Tag<DamageType> IS_EXPLOSION = DamageTypeTags.key(ResourceKey.minecraft("is_explosion"));
public static final DefaultedTag<DamageType> IS_EXPLOSION = DamageTypeTags.key(ResourceKey.minecraft("is_explosion"));

public static final Tag<DamageType> IS_FALL = DamageTypeTags.key(ResourceKey.minecraft("is_fall"));
public static final DefaultedTag<DamageType> IS_FALL = DamageTypeTags.key(ResourceKey.minecraft("is_fall"));

public static final Tag<DamageType> IS_FIRE = DamageTypeTags.key(ResourceKey.minecraft("is_fire"));
public static final DefaultedTag<DamageType> IS_FIRE = DamageTypeTags.key(ResourceKey.minecraft("is_fire"));

public static final Tag<DamageType> IS_FREEZING = DamageTypeTags.key(ResourceKey.minecraft("is_freezing"));
public static final DefaultedTag<DamageType> IS_FREEZING = DamageTypeTags.key(ResourceKey.minecraft("is_freezing"));

public static final Tag<DamageType> IS_LIGHTNING = DamageTypeTags.key(ResourceKey.minecraft("is_lightning"));
public static final DefaultedTag<DamageType> IS_LIGHTNING = DamageTypeTags.key(ResourceKey.minecraft("is_lightning"));

public static final Tag<DamageType> IS_PLAYER_ATTACK = DamageTypeTags.key(ResourceKey.minecraft("is_player_attack"));
public static final DefaultedTag<DamageType> IS_PLAYER_ATTACK = DamageTypeTags.key(ResourceKey.minecraft("is_player_attack"));

public static final Tag<DamageType> IS_PROJECTILE = DamageTypeTags.key(ResourceKey.minecraft("is_projectile"));
public static final DefaultedTag<DamageType> IS_PROJECTILE = DamageTypeTags.key(ResourceKey.minecraft("is_projectile"));

public static final Tag<DamageType> MACE_SMASH = DamageTypeTags.key(ResourceKey.minecraft("mace_smash"));
public static final DefaultedTag<DamageType> MACE_SMASH = DamageTypeTags.key(ResourceKey.minecraft("mace_smash"));

public static final Tag<DamageType> NO_ANGER = DamageTypeTags.key(ResourceKey.minecraft("no_anger"));
public static final DefaultedTag<DamageType> NO_ANGER = DamageTypeTags.key(ResourceKey.minecraft("no_anger"));

public static final Tag<DamageType> NO_IMPACT = DamageTypeTags.key(ResourceKey.minecraft("no_impact"));
public static final DefaultedTag<DamageType> NO_IMPACT = DamageTypeTags.key(ResourceKey.minecraft("no_impact"));

public static final Tag<DamageType> NO_KNOCKBACK = DamageTypeTags.key(ResourceKey.minecraft("no_knockback"));
public static final DefaultedTag<DamageType> NO_KNOCKBACK = DamageTypeTags.key(ResourceKey.minecraft("no_knockback"));

public static final Tag<DamageType> PANIC_CAUSES = DamageTypeTags.key(ResourceKey.minecraft("panic_causes"));
public static final DefaultedTag<DamageType> PANIC_CAUSES = DamageTypeTags.key(ResourceKey.minecraft("panic_causes"));

public static final Tag<DamageType> PANIC_ENVIRONMENTAL_CAUSES = DamageTypeTags.key(ResourceKey.minecraft("panic_environmental_causes"));
public static final DefaultedTag<DamageType> PANIC_ENVIRONMENTAL_CAUSES = DamageTypeTags.key(ResourceKey.minecraft("panic_environmental_causes"));

public static final Tag<DamageType> WITCH_RESISTANT_TO = DamageTypeTags.key(ResourceKey.minecraft("witch_resistant_to"));
public static final DefaultedTag<DamageType> WITCH_RESISTANT_TO = DamageTypeTags.key(ResourceKey.minecraft("witch_resistant_to"));

public static final Tag<DamageType> WITHER_IMMUNE_TO = DamageTypeTags.key(ResourceKey.minecraft("wither_immune_to"));
public static final DefaultedTag<DamageType> WITHER_IMMUNE_TO = DamageTypeTags.key(ResourceKey.minecraft("wither_immune_to"));

private DamageTypeTags() {
}

private static Tag<DamageType> key(final ResourceKey key) {
return Tag.of(RegistryTypes.DAMAGE_TYPE, key);
private static DefaultedTag<DamageType> key(final ResourceKey key) {
return DefaultedTag.of(RegistryTypes.DAMAGE_TYPE, key);
}
}
77 changes: 77 additions & 0 deletions src/main/java/org/spongepowered/api/tag/DefaultedTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.api.tag;

import org.spongepowered.api.ResourceKey;
import org.spongepowered.api.registry.DefaultedRegistryType;
import org.spongepowered.api.registry.RegistryHolder;
import org.spongepowered.api.registry.ValueNotFoundException;

import java.util.function.Supplier;
import java.util.stream.Stream;

/**
* A {@link Tag} paired with the {@link RegistryHolder}.
*/
public interface DefaultedTag<T> extends Tag<T> {

static <T> DefaultedTag<T> of(final DefaultedRegistryType<T> registryType, final ResourceKey location) {
return Tag.of(registryType, location).asDefaultedTag(registryType.defaultHolder());
}

Supplier<RegistryHolder> defaultHolder();

/**
* Returns the {@link Stream} of values tagged by this tag.
*
* <p>Great care needs to be made in calling this method with any uncertainty as to
* if the {@link #registry()} will exist in the holder. Should the key lack a value,
* a {@link ValueNotFoundException} will be thrown. Therefore, it is advised to call
* {@link #findValues()} instead.</p>
*
* @return The {@link Stream} of values
*/
default Stream<T> values() {
return this.defaultHolder().get().registry(this.registry()).taggedValues(this);
}

/**
* Returns the {@link Stream} of values tagged by this tag in the holder
* if it contains this tag's {@link #registry()}, or {@link Stream#empty()} otherwise.
*
* @return The {@link Stream} of values
*/
default Stream<T> findValues() {
return this.defaultHolder().get().findRegistry(this.registry()).map(r -> r.taggedValues(this)).orElseGet(Stream::empty);
}

/**
* Returns whether this tag is associated with the given value.
*
* @param value The value
* @return true if this tag is associated with the given value
*/
boolean contains(T value);
}
Loading