Skip to content

Commit 9f5e3ea

Browse files
committed
Implement remaining unimplemented registries
* Add Angle class as suggested by TODO, slight break in Orientation. * Slight style cleanup * Adjust javadocs in ChunkRegenerateFlag for andNotFlag, as it was identical to andFlag. See SpongePowered/Sponge#3328
1 parent a6ca030 commit 9f5e3ea

File tree

6 files changed

+163
-59
lines changed

6 files changed

+163
-59
lines changed

src/main/java/org/spongepowered/api/registry/RegistryTypes.java

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package org.spongepowered.api.registry;
2626

27+
import org.checkerframework.checker.nullness.qual.NonNull;
2728
import org.spongepowered.api.ResourceKey;
2829
import org.spongepowered.api.Sponge;
2930
import org.spongepowered.api.advancement.AdvancementType;
@@ -181,30 +182,30 @@ public final class RegistryTypes {
181182

182183
public static final DefaultedRegistryType<EnchantmentType> ENCHANTMENT_TYPE = RegistryTypes.minecraftKeyInGame("enchantment");
183184

184-
public static final DefaultedRegistryType<EntityType<?>> ENTITY_TYPE = RegistryTypes.minecraftKeyInGame("entity_type");
185+
public static final DefaultedRegistryType<EntityType<@NonNull ?>> ENTITY_TYPE = RegistryTypes.minecraftKeyInGame("entity_type");
185186

186187
public static final DefaultedRegistryType<FluidType> FLUID_TYPE = RegistryTypes.minecraftKeyInGame("fluid");
187188

188189
public static final DefaultedRegistryType<ItemType> ITEM_TYPE = RegistryTypes.minecraftKeyInGame("item");
189190

190191
public static final DefaultedRegistryType<ParticleType> PARTICLE_TYPE = RegistryTypes.minecraftKeyInGame("particle_type");
191192

192-
public static final DefaultedRegistryType<RecipeType<?>> RECIPE_TYPE = RegistryTypes.minecraftKeyInGame("recipe_type");
193+
public static final DefaultedRegistryType<ProfessionType> PROFESSION_TYPE = RegistryTypes.minecraftKeyInGame("villager_profession");
194+
195+
public static final DefaultedRegistryType<PotionType> POTION_TYPE = RegistryTypes.minecraftKeyInGame("potion");
196+
197+
public static final DefaultedRegistryType<RecipeType<@NonNull ?>> RECIPE_TYPE = RegistryTypes.minecraftKeyInGame("recipe_type");
193198

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

196201
public static final DefaultedRegistryType<Statistic> STATISTIC = RegistryTypes.minecraftKeyInGame("custom_stat");
197202

198-
public static final DefaultedRegistryType<StatisticCategory> STATISTIC_CATEGORY = RegistryTypes.minecraftKeyInGame("statistic_category");
203+
public static final DefaultedRegistryType<StatisticCategory> STATISTIC_CATEGORY = RegistryTypes.minecraftKeyInGame("stat_type");
199204

200205
public static final DefaultedRegistryType<Structure> STRUCTURE = RegistryTypes.minecraftKeyInGame("worldgen/structure_feature");
201206

202207
public static final DefaultedRegistryType<VillagerType> VILLAGER_TYPE = RegistryTypes.minecraftKeyInGame("villager_type");
203208

204-
public static final DefaultedRegistryType<ProfessionType> PROFESSION_TYPE = RegistryTypes.minecraftKeyInGame("villager_profession");
205-
206-
public static final DefaultedRegistryType<PotionType> POTION_TYPE = RegistryTypes.minecraftKeyInGame("potion");
207-
208209
// ----
209210

210211
public static final DefaultedRegistryType<AccountDeletionResultType> ACCOUNT_DELETION_RESULT_TYPE = RegistryTypes.spongeKeyInGame("account_deletion_result_type");
@@ -221,6 +222,8 @@ public final class RegistryTypes {
221222

222223
public static final DefaultedRegistryType<BannerPatternShape> BANNER_PATTERN_SHAPE = RegistryTypes.spongeKeyInGame("banner_pattern_shape");
223224

225+
public static final DefaultedRegistryType<Tag<BlockType>> BLOCK_TYPE_TAGS = RegistryTypes.spongeKeyInGame("block_type_tags");
226+
224227
public static final DefaultedRegistryType<BoatType> BOAT_TYPE = RegistryTypes.spongeKeyInGame("boat_type");
225228

226229
public static final DefaultedRegistryType<BodyPart> BODY_PART = RegistryTypes.spongeKeyInGame("body_part");
@@ -229,8 +232,6 @@ public final class RegistryTypes {
229232

230233
public static final DefaultedRegistryType<CatType> CAT_TYPE = RegistryTypes.spongeKeyInGame("cat_type");
231234

232-
public static final DefaultedRegistryType<ValueParameter<?>> REGISTRY_KEYED_VALUE_PARAMETER = RegistryTypes.spongeKeyInGame("value_parameter");
233-
234235
public static final DefaultedRegistryType<ChatVisibility> CHAT_VISIBILITY = RegistryTypes.spongeKeyInGame("chat_visibility");
235236

236237
public static final DefaultedRegistryType<ChestAttachmentType> CHEST_ATTACHMENT_TYPE = RegistryTypes.spongeKeyInGame("chest_attachment_type");
@@ -247,7 +248,7 @@ public final class RegistryTypes {
247248

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

250-
public static final DefaultedRegistryType<CommandTreeNodeType<?>> COMMAND_TREE_NODE_TYPE = RegistryTypes.spongeKeyInGame("command_tree_node_type");
251+
public static final DefaultedRegistryType<CommandTreeNodeType<@NonNull ?>> COMMAND_TREE_NODE_TYPE = RegistryTypes.spongeKeyInGame("command_tree_node_type");
251252

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

@@ -273,14 +274,18 @@ public final class RegistryTypes {
273274

274275
public static final DefaultedRegistryType<DyeColor> DYE_COLOR = RegistryTypes.spongeKeyInGame("dye_color");
275276

276-
public static final DefaultedRegistryType<EnumStateProperty<?>> ENUM_STATE_PROPERTY = RegistryTypes.spongeKeyInGame("enum_state_property");
277+
public static final DefaultedRegistryType<EnumStateProperty<@NonNull ?>> ENUM_STATE_PROPERTY = RegistryTypes.spongeKeyInGame("enum_state_property");
278+
279+
public static final DefaultedRegistryType<Tag<EntityType<@NonNull ?>>> ENTITY_TYPE_TAGS = RegistryTypes.spongeKeyInGame("entity_type_tags");
277280

278281
public static final DefaultedRegistryType<EquipmentGroup> EQUIPMENT_GROUP = RegistryTypes.spongeKeyInGame("equipment_group");
279282

280283
public static final DefaultedRegistryType<EquipmentType> EQUIPMENT_TYPE = RegistryTypes.spongeKeyInGame("equipment_type");
281284

282285
public static final DefaultedRegistryType<FireworkShape> FIREWORK_SHAPE = RegistryTypes.spongeKeyInGame("firework_shape");
283286

287+
public static final DefaultedRegistryType<Tag<FluidType>> FLUID_TYPE_TAGS = RegistryTypes.spongeKeyInGame("fluid_type_tags");
288+
284289
public static final DefaultedRegistryType<FoxType> FOX_TYPE = RegistryTypes.spongeKeyInGame("fox_type");
285290

286291
public static final DefaultedRegistryType<GameMode> GAME_MODE = RegistryTypes.spongeKeyInGame("game_mode");
@@ -309,10 +314,20 @@ public final class RegistryTypes {
309314

310315
public static final DefaultedRegistryType<ItemTier> ITEM_TIER = RegistryTypes.spongeKeyInGame("item_tier");
311316

317+
public static final DefaultedRegistryType<Tag<ItemType>> ITEM_TYPE_TAGS = RegistryTypes.spongeKeyInGame("item_type_tags");
318+
312319
public static final DefaultedRegistryType<LightType> LIGHT_TYPE = RegistryTypes.spongeKeyInGame("light_type");
313320

314321
public static final DefaultedRegistryType<LlamaType> LLAMA_TYPE = RegistryTypes.spongeKeyInGame("llama_type");
315322

323+
public static final DefaultedRegistryType<MapColorType> MAP_COLOR_TYPE = RegistryTypes.spongeKeyInGame("map_color_type");
324+
325+
public static final DefaultedRegistryType<MapDecorationOrientation> MAP_DECORATION_ORIENTATION = RegistryTypes.spongeKeyInGame("map_decoration_orientation");
326+
327+
public static final DefaultedRegistryType<MapDecorationType> MAP_DECORATION_TYPE = RegistryTypes.spongeKeyInGame("map_decoration_type");
328+
329+
public static final DefaultedRegistryType<MapShade> MAP_SHADE = RegistryTypes.spongeKeyInGame("map_shade");
330+
316331
public static final DefaultedRegistryType<MatterType> MATTER_TYPE = RegistryTypes.spongeKeyInGame("matter_type");
317332

318333
public static final DefaultedRegistryType<Mirror> MIRROR = RegistryTypes.spongeKeyInGame("mirror");
@@ -361,6 +376,8 @@ public final class RegistryTypes {
361376

362377
public static final DefaultedRegistryType<RailDirection> RAIL_DIRECTION = RegistryTypes.spongeKeyInGame("rail_direction");
363378

379+
public static final DefaultedRegistryType<ValueParameter<?>> REGISTRY_KEYED_VALUE_PARAMETER = RegistryTypes.spongeKeyInGame("value_parameter");
380+
364381
public static final DefaultedRegistryType<ResolveOperation> RESOLVE_OPERATION = RegistryTypes.spongeKeyInGame("resolve_operation");
365382

366383
public static final DefaultedRegistryType<Rotation> ROTATION = RegistryTypes.spongeKeyInGame("rotation");
@@ -381,6 +398,8 @@ public final class RegistryTypes {
381398

382399
public static final DefaultedRegistryType<StructureMode> STRUCTURE_MODE = RegistryTypes.spongeKeyInGame("structure_mode");
383400

401+
public static final DefaultedRegistryType<TagType<@NonNull ?>> TAG_TYPES = RegistryTypes.spongeKeyInGame("tag_type");
402+
384403
public static final DefaultedRegistryType<TaskPriority> TASK_PRIORITY = RegistryTypes.spongeKeyInGame("task_priority");
385404

386405
public static final DefaultedRegistryType<TeleportHelperFilter> TELEPORT_HELPER_FILTER = RegistryTypes.spongeKeyInGame("teleport_helper_filter");
@@ -389,7 +408,7 @@ public final class RegistryTypes {
389408

390409
public static final DefaultedRegistryType<TransactionType> TRANSACTION_TYPE = RegistryTypes.spongeKeyInGame("transaction_type");
391410

392-
public static final DefaultedRegistryType<Trigger<?>> TRIGGER = RegistryTypes.spongeKeyInGame("trigger");
411+
public static final DefaultedRegistryType<Trigger<@NonNull ?>> TRIGGER = RegistryTypes.spongeKeyInGame("trigger");
393412

394413
public static final DefaultedRegistryType<TropicalFishShape> TROPICAL_FISH_SHAPE = RegistryTypes.spongeKeyInGame("tropical_fish_shape");
395414

@@ -399,24 +418,6 @@ public final class RegistryTypes {
399418

400419
public static final DefaultedRegistryType<WireAttachmentType> WIRE_ATTACHMENT_TYPE = RegistryTypes.spongeKeyInGame("wire_attachment_type");
401420

402-
public static final DefaultedRegistryType<MapColorType> MAP_COLOR_TYPE = RegistryTypes.spongeKeyInGame("map_color_type");
403-
404-
public static final DefaultedRegistryType<MapDecorationOrientation> MAP_DECORATION_ORIENTATION = RegistryTypes.spongeKeyInGame("map_decoration_orientation");
405-
406-
public static final DefaultedRegistryType<MapDecorationType> MAP_DECORATION_TYPE = RegistryTypes.spongeKeyInGame("map_decoration_type");
407-
408-
public static final DefaultedRegistryType<MapShade> MAP_SHADE = RegistryTypes.spongeKeyInGame("map_shade");
409-
410-
public static final DefaultedRegistryType<TagType<?>> TAG_TYPES = RegistryTypes.spongeKeyInGame("tag_type");
411-
412-
public static final DefaultedRegistryType<Tag<BlockType>> BLOCK_TYPE_TAGS = RegistryTypes.spongeKeyInGame("block_type_tags");
413-
414-
public static final DefaultedRegistryType<Tag<ItemType>> ITEM_TYPE_TAGS = RegistryTypes.spongeKeyInGame("item_type_tags");
415-
416-
public static final DefaultedRegistryType<Tag<EntityType<?>>> ENTITY_TYPE_TAGS = RegistryTypes.spongeKeyInGame("entity_type_tags");
417-
418-
public static final DefaultedRegistryType<Tag<FluidType>> FLUID_TYPE_TAGS = RegistryTypes.spongeKeyInGame("fluid_type_tags");
419-
420421
// @formatter:on
421422

422423
private static <V> RegistryType<V> minecraftKey(final String key) {
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.api.util;
26+
27+
import java.util.Objects;
28+
29+
/**
30+
* Represents an angle in the range of 0 (inclusive) to 360 (exclusive) degrees.
31+
*/
32+
public final class Angle {
33+
34+
private static final double DEGREES_TO_RADIANS = Math.PI / 180.0;
35+
36+
/**
37+
* Creates an {@link Angle} based on the provided angle in degrees.
38+
*
39+
* <p>Any angle that falls outside of the range 0 (inclusive) to
40+
* 360 (exclusive) degrees will be mapped to be within this range.
41+
* </p>
42+
*
43+
* @param degrees The angle in degrees.
44+
* @return The {@link Angle}
45+
*/
46+
public static Angle fromDegrees(final double degrees) {
47+
return new Angle(degrees, degrees * Angle.DEGREES_TO_RADIANS);
48+
}
49+
50+
/**
51+
* Creates an {@link Angle} based on the provided angle in degrees.
52+
*
53+
* <p>Any angle that falls outside of the range 0 (inclusive) to
54+
* 2*pi (exclusive) degrees will be mapped to be within this range.
55+
* </p>
56+
*
57+
* @param radians The angle in radians.
58+
* @return The {@link Angle}
59+
*/
60+
public static Angle fromRadians(final double radians) {
61+
return new Angle(radians / Angle.DEGREES_TO_RADIANS, radians);
62+
}
63+
64+
private final double degrees;
65+
private final double radians;
66+
67+
private Angle(final double degrees, final double radians) {
68+
this.degrees = degrees;
69+
this.radians = radians;
70+
}
71+
72+
/**
73+
* Gets this angle in degrees.
74+
*
75+
* @return The angle in degrees.
76+
*/
77+
public double degrees() {
78+
return this.degrees;
79+
}
80+
81+
/**
82+
* Gets this angle in radians.
83+
*
84+
* @return The angle in radians.
85+
*/
86+
public double radians() {
87+
return this.radians;
88+
}
89+
90+
// Note that radians and degrees should always have a 1-1 mapping,
91+
// so we'll just use degrees for checks.
92+
@Override
93+
public boolean equals(final Object o) {
94+
if (this == o) {
95+
return true;
96+
}
97+
if (o == null || this.getClass() != o.getClass()) {
98+
return false;
99+
}
100+
final Angle angle = (Angle) o;
101+
return Double.compare(angle.degrees, this.degrees) == 0;
102+
}
103+
104+
@Override
105+
public int hashCode() {
106+
return Objects.hash(this.degrees);
107+
}
108+
}

src/main/java/org/spongepowered/api/util/orientation/Orientation.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.spongepowered.api.Sponge;
2828
import org.spongepowered.api.registry.DefaultedRegistryValue;
29+
import org.spongepowered.api.util.Angle;
2930
import org.spongepowered.api.util.annotation.CatalogedBy;
3031

3132
import java.util.Optional;
@@ -37,25 +38,21 @@
3738
public interface Orientation extends DefaultedRegistryValue {
3839

3940
/**
40-
* Gets the {@link Orientation} with the provided degrees.
41+
* Gets the {@link Orientation} that represents the provided {@link Angle}.
4142
*
42-
* @param degrees The degrees of the rotation
43-
* @return The {@link Orientation} with the given degrees or {@link Optional#empty()} if not found
43+
* @param angle The {@link Angle}
44+
* @return The {@link Orientation} with the given {@link Angle}, if it
45+
* exists
4446
*/
45-
static Optional<Orientation> fromDegrees(int degrees) {
46-
return Sponge.game().factoryProvider().provide(Factory.class).fromDegrees(degrees);
47+
static Optional<Orientation> fromAngle(final Angle angle) {
48+
return Orientations.registry().stream().filter(x -> x.angle().equals(angle)).findAny();
4749
}
4850

4951
/**
50-
* The angle in degrees.
52+
* The {@link Angle} this orientation represents.
5153
*
52-
* @return The angle in degrees
54+
* @return The angle
5355
*/
54-
//TODO we should have an Angle class in the future
55-
int angle();
56+
Angle angle();
5657

57-
interface Factory {
58-
59-
Optional<Orientation> fromDegrees(int degrees);
60-
}
6158
}

src/main/java/org/spongepowered/api/util/orientation/Orientations.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
import org.spongepowered.api.entity.hanging.ItemFrame;
3030
import org.spongepowered.api.item.inventory.ItemStack;
3131
import org.spongepowered.api.registry.DefaultedRegistryReference;
32+
import org.spongepowered.api.registry.Registry;
3233
import org.spongepowered.api.registry.RegistryKey;
3334
import org.spongepowered.api.registry.RegistryScope;
3435
import org.spongepowered.api.registry.RegistryScopes;
3536
import org.spongepowered.api.registry.RegistryTypes;
3637

3738
/**
3839
* An enumeration of possible rotations for something that can rotate,
39-
* such as an {@link ItemStack} within
40-
* an {@link ItemFrame}.
40+
* such as an {@link ItemStack} within an {@link ItemFrame}.
4141
*/
4242
@SuppressWarnings("unused")
4343
@RegistryScopes(scopes = RegistryScope.GAME)
@@ -70,6 +70,10 @@ public final class Orientations {
7070
private Orientations() {
7171
}
7272

73+
public static Registry<Orientation> registry() {
74+
return Sponge.game().registries().registry(RegistryTypes.ORIENTATION);
75+
}
76+
7377
private static DefaultedRegistryReference<Orientation> key(final ResourceKey location) {
7478
return RegistryKey.of(RegistryTypes.ORIENTATION, location).asDefaultedReference(() -> Sponge.game().registries());
7579
}

src/main/java/org/spongepowered/api/world/ChunkRegenerateFlag.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,15 @@ public interface ChunkRegenerateFlag extends DefaultedRegistryValue {
9090
ChunkRegenerateFlag andFlag(ChunkRegenerateFlag flag);
9191

9292
/**
93-
* Gets the equivalent {@link ChunkRegenerateFlag} of this flag with the
94-
* {@code true}s set for this flag and the provided {@code flag}, such that
95-
* only if both flags have the same {@code true} flags set will persist.
93+
* Gets the equivalent {@link ChunkRegenerateFlag} of this flag where the
94+
* provided {@code flag} has its values inverted before performing an
95+
* and operation between this flag and the provided flag. Therefore, the
96+
* returned flag will only have {@code true} for a value if the value is
97+
* {@code true} for this flag and {@code false} for the provided flag.
9698
*
97-
* <p>For example, if this flag has {@link #create()} and the incoming flag
98-
* has {@link #create()} returning {@code true}, the resulting flag will
99-
* have {@link #create()} return {@code true} as well. The inverse is also
100-
* true. If either has differing flags for any of the above methods, the
101-
* resulting flag will have a {@code false} value.</p>
102-
*
103-
* @param flag The incoming flag to and with this flag
99+
* @param flag The incoming flag to compare against
104100
* @return The resulting flag with matched values
105101
*/
106102
ChunkRegenerateFlag andNotFlag(ChunkRegenerateFlag flag);
107103

108-
public interface Factory {
109-
110-
ChunkRegenerateFlag empty();
111-
}
112104
}

src/main/java/org/spongepowered/api/world/ChunkRegenerateFlags.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
import org.spongepowered.api.ResourceKey;
2828
import org.spongepowered.api.Sponge;
2929
import org.spongepowered.api.registry.DefaultedRegistryReference;
30+
import org.spongepowered.api.registry.Registry;
3031
import org.spongepowered.api.registry.RegistryKey;
3132
import org.spongepowered.api.registry.RegistryScope;
3233
import org.spongepowered.api.registry.RegistryScopes;
34+
import org.spongepowered.api.registry.RegistryType;
3335
import org.spongepowered.api.registry.RegistryTypes;
3436

3537
/**

0 commit comments

Comments
 (0)