forked from Minestom/Minestom
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
245ea95
commit 510a62a
Showing
9 changed files
with
353 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package net.minestom.server.gametag; | ||
|
||
import net.minestom.server.instance.block.Block; | ||
import net.minestom.server.registry.Registry; | ||
import net.minestom.server.utils.NamespaceID; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.function.Function; | ||
|
||
public record BlockTag(Registry.TagEntry registry, int id, List<String> stringValue) implements Tag, BlockTags { | ||
private static final AtomicInteger INDEX = new AtomicInteger(); | ||
private static final Function<NamespaceID, Integer> TAG_TO_ID = namespaceID -> Block.fromNamespaceId(namespaceID).id(); | ||
private static final Registry.Container<Tag> CONTAINER = Registry.createStaticContainer(Registry.Resource.BLOCK_TAGS, BlockTag::createImpl); | ||
|
||
public static final String IDENTIFIER = "minecraft:block"; | ||
|
||
public BlockTag(Registry.TagEntry registry) { | ||
this(registry, INDEX.getAndIncrement(), registry.values()); | ||
} | ||
|
||
private static Tag createImpl(String namespace, Registry.Properties properties) { | ||
return new BlockTag(Registry.tag(namespace, properties)); | ||
} | ||
|
||
static Tag get(String namespace) { | ||
return CONTAINER.get(namespace); | ||
} | ||
|
||
public static @NotNull Collection<Tag> values() { | ||
return CONTAINER.values(); | ||
} | ||
|
||
@Override | ||
public @NotNull Collection<@NotNull NamespaceID> tagValues() { | ||
var concatinatedTags = stringValue.stream().filter(s -> s.startsWith("#")).toList(); | ||
var result = new ArrayList<>(stringValue.stream().filter(s -> !s.startsWith("#")).map(NamespaceID::from).toList()); | ||
concatinatedTags.stream().map(BlockTag::getSafe).filter(Objects::nonNull).map(Tag::tagValues).forEach(result::addAll); | ||
return result; | ||
} | ||
|
||
@Override | ||
public @NotNull Function<NamespaceID, Integer> getMapper() { | ||
return TAG_TO_ID; | ||
} | ||
|
||
static Tag getSafe(@NotNull String namespace) { | ||
return CONTAINER.getSafe(namespace); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package net.minestom.server.gametag; | ||
|
||
import net.minestom.server.entity.EntityType; | ||
import net.minestom.server.registry.Registry; | ||
import net.minestom.server.utils.NamespaceID; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.function.Function; | ||
|
||
public record EntityTag(Registry.TagEntry registry, int id, List<String> stringValue) implements Tag, EntityTags { | ||
private static final AtomicInteger INDEX = new AtomicInteger(); | ||
private static final Registry.Container<Tag> CONTAINER = Registry.createStaticContainer(Registry.Resource.ENTITY_TYPE_TAGS, EntityTag::createImpl); | ||
private static final Function<NamespaceID, Integer> TAG_TO_ID = namespaceID -> Objects.requireNonNull(EntityType.fromNamespaceId(namespaceID)).id(); | ||
|
||
public static final String IDENTIFIER = "minecraft:entity_type"; | ||
|
||
public EntityTag(Registry.TagEntry registry) { | ||
this(registry, INDEX.getAndIncrement(), registry.values()); | ||
} | ||
|
||
private static Tag createImpl(String namespace, Registry.Properties properties) { | ||
return new EntityTag(Registry.tag(namespace, properties)); | ||
} | ||
|
||
public static Tag get(String namespace) { | ||
return CONTAINER.get(namespace); | ||
} | ||
|
||
public static @NotNull Collection<Tag> values() { | ||
return CONTAINER.values(); | ||
} | ||
|
||
static Tag getSafe(@NotNull String namespace) { | ||
return CONTAINER.getSafe(namespace); | ||
} | ||
@Override | ||
public @NotNull Collection<@NotNull NamespaceID> tagValues() { | ||
var concatinatedTags = stringValue.stream().filter(s -> s.startsWith("#")).toList(); | ||
var result = new ArrayList<>(stringValue.stream().filter(s -> !s.startsWith("#")).map(NamespaceID::from).toList()); | ||
concatinatedTags.stream().map(EntityTag::getSafe).filter(Objects::nonNull).map(Tag::tagValues).forEach(result::addAll); | ||
return result; | ||
} | ||
|
||
@Override | ||
public @NotNull Function<NamespaceID, Integer> getMapper() { | ||
return TAG_TO_ID; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package net.minestom.server.gametag; | ||
|
||
import net.minestom.server.fluid.Fluid; | ||
import net.minestom.server.registry.Registry; | ||
import net.minestom.server.utils.NamespaceID; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.function.Function; | ||
|
||
public record FluidTag(Registry.TagEntry registry, int id, List<String> stringValue) implements Tag, FluidTags { | ||
private static final AtomicInteger INDEX = new AtomicInteger(); | ||
private static final Registry.Container<Tag> CONTAINER = Registry.createStaticContainer(Registry.Resource.FLUID_TAGS, FluidTag::createImpl); | ||
private static final Function<NamespaceID, Integer> TAG_TO_ID = namespaceID -> Objects.requireNonNull(Fluid.fromNamespaceId(namespaceID)).id(); | ||
|
||
public static final String IDENTIFIER = "minecraft:fluid"; | ||
|
||
public FluidTag(Registry.TagEntry registry) { | ||
this(registry, INDEX.getAndIncrement(), registry.values()); | ||
} | ||
|
||
private static Tag createImpl(String namespace, Registry.Properties properties) { | ||
return new FluidTag(Registry.tag(namespace, properties)); | ||
} | ||
|
||
public static Tag get(String namespace) { | ||
return CONTAINER.get(namespace); | ||
} | ||
|
||
public static @NotNull Collection<Tag> values() { | ||
return CONTAINER.values(); | ||
} | ||
|
||
static Tag getSafe(@NotNull String namespace) { | ||
return CONTAINER.getSafe(namespace); | ||
} | ||
|
||
@Override | ||
public @NotNull Collection<@NotNull NamespaceID> tagValues() { | ||
var concatinatedTags = stringValue.stream().filter(s -> s.startsWith("#")).toList(); | ||
var result = new ArrayList<>(stringValue.stream().filter(s -> !s.startsWith("#")).map(NamespaceID::from).toList()); | ||
concatinatedTags.stream().map(FluidTag::getSafe).filter(Objects::nonNull).map(Tag::tagValues).forEach(result::addAll); | ||
return result; | ||
} | ||
|
||
@Override | ||
public @NotNull Function<NamespaceID, Integer> getMapper() { | ||
return TAG_TO_ID; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/net/minestom/server/gametag/GameEventTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package net.minestom.server.gametag; | ||
|
||
import net.minestom.server.registry.Registry; | ||
import net.minestom.server.utils.NamespaceID; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.function.Function; | ||
|
||
public record GameEventTag(Registry.TagEntry registry, int id, List<String> stringValue) implements Tag, GameEventTags { | ||
private static final AtomicInteger INDEX = new AtomicInteger(); | ||
private static final Registry.Container<Tag> CONTAINER = Registry.createStaticContainer(Registry.Resource.GAMEPLAY_TAGS, GameEventTag::createImpl); | ||
private static final Function<NamespaceID, Integer> TAG_TO_ID = namespaceID -> Objects.requireNonNull(GameEventTag.getSafe(namespaceID.asString())).id(); | ||
|
||
public static final String IDENTIFIER = "minecraft:game_event"; | ||
|
||
public GameEventTag(Registry.TagEntry registry) { | ||
this(registry, INDEX.getAndIncrement(), registry.values()); | ||
} | ||
|
||
private static Tag createImpl(String namespace, Registry.Properties properties) { | ||
return new GameEventTag(Registry.tag(namespace, properties)); | ||
} | ||
|
||
public static Tag get(String namespace) { | ||
return CONTAINER.get(namespace); | ||
} | ||
|
||
public static @NotNull Collection<Tag> values() { | ||
return CONTAINER.values(); | ||
} | ||
|
||
static Tag getSafe(@NotNull String namespace) { | ||
return CONTAINER.getSafe(namespace); | ||
} | ||
|
||
@Override | ||
public @NotNull Collection<@NotNull NamespaceID> tagValues() { | ||
var concatinatedTags = stringValue.stream().filter(s -> s.startsWith("#")).toList(); | ||
var result = new ArrayList<>(stringValue.stream().filter(s -> !s.startsWith("#")).map(NamespaceID::from).toList()); | ||
concatinatedTags.stream().map(GameEventTag::getSafe).filter(Objects::nonNull).map(Tag::tagValues).forEach(result::addAll); | ||
return result; | ||
} | ||
|
||
@Override | ||
public @NotNull Function<NamespaceID, Integer> getMapper() { | ||
return TAG_TO_ID; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package net.minestom.server.gametag; | ||
|
||
import net.minestom.server.item.Material; | ||
import net.minestom.server.registry.Registry; | ||
import net.minestom.server.utils.NamespaceID; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.function.Function; | ||
|
||
public record ItemTag(Registry.TagEntry registry, int id, List<String> stringValue) implements Tag, ItemTags { | ||
private static final AtomicInteger INDEX = new AtomicInteger(); | ||
private static final Registry.Container<Tag> CONTAINER = Registry.createStaticContainer(Registry.Resource.ITEM_TAGS, ItemTag::createImpl); | ||
public static final Function<NamespaceID, Integer> TAG_TO_ID = namespaceID -> Objects.requireNonNull(Material.fromNamespaceId(namespaceID)).id(); | ||
|
||
public static final String IDENTIFIER = "minecraft:item"; | ||
|
||
public ItemTag(Registry.TagEntry registry) { | ||
this(registry, INDEX.getAndIncrement(), registry.values()); | ||
} | ||
|
||
private static Tag createImpl(String namespace, Registry.Properties properties) { | ||
return new ItemTag(Registry.tag(namespace, properties)); | ||
} | ||
|
||
public static Tag get(String namespace) { | ||
return CONTAINER.get(namespace); | ||
} | ||
|
||
public static @NotNull Collection<Tag> values() { | ||
return CONTAINER.values(); | ||
} | ||
|
||
static Tag getSafe(@NotNull String namespace) { | ||
return CONTAINER.getSafe(namespace); | ||
} | ||
@Override | ||
public @NotNull Collection<@NotNull NamespaceID> tagValues() { | ||
var concatinatedTags = stringValue.stream().filter(s -> s.startsWith("#")).toList(); | ||
var result = new ArrayList<>(stringValue.stream().filter(s -> !s.startsWith("#")).map(NamespaceID::from).toList()); | ||
concatinatedTags.stream().map(ItemTag::getSafe).filter(Objects::nonNull).map(Tag::tagValues).forEach(result::addAll); | ||
return result; | ||
} | ||
|
||
@Override | ||
public @NotNull Function<NamespaceID, Integer> getMapper() { | ||
return TAG_TO_ID; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.minestom.server.gametag; | ||
|
||
import net.minestom.server.registry.Registry; | ||
import net.minestom.server.registry.StaticProtocolObject; | ||
import net.minestom.server.utils.NamespaceID; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collection; | ||
import java.util.function.Function; | ||
|
||
public sealed interface Tag extends StaticProtocolObject permits BlockTag, EntityTag, FluidTag, GameEventTag, ItemTag { | ||
|
||
@Contract(pure = true) | ||
@NotNull Registry.TagEntry registry(); | ||
|
||
@Override | ||
default @NotNull NamespaceID namespace() { | ||
return registry().namespace(); | ||
} | ||
|
||
@NotNull Collection<@NotNull NamespaceID> tagValues(); | ||
|
||
@NotNull Function<NamespaceID, Integer> getMapper(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.