From 9b0a835294683c4b36e08bf6e68065477cec717c Mon Sep 17 00:00:00 2001 From: Pyrofab Date: Sun, 22 May 2022 11:16:56 +0200 Subject: [PATCH] Update to 1.19 --- README.md | 2 +- build.gradle | 12 +- .../cca/api/v3/component/ComponentAccess.java | 101 +++++++++++++ .../cca/api/v3/component/ComponentKey.java | 35 ++--- .../api/v3/component/ComponentProvider.java | 143 +----------------- .../dev/onyxstudios/cca/test/base/Vita.java | 2 +- .../cca/internal/CardinalComponentsBlock.java | 2 +- .../block/StaticBlockComponentPlugin.java | 16 +- .../block/common/MixinBlockDataObject.java | 2 +- .../mixin/block/common/MixinBlockEntity.java | 11 +- .../block/common/MixinBlockStateArgument.java | 2 +- .../block/common/MixinFallingBlockEntity.java | 2 +- .../src/main/resources/fabric.mod.json | 2 +- .../chunk/ComponentsChunkNetworking.java | 3 +- .../chunk/common/MixinChunkSerializer.java | 4 +- .../chunk/common/MixinReadOnlyChunk.java | 2 +- .../mixin/chunk/common/MixinServerWorld.java | 2 +- .../mixin/chunk/common/MixinWorldChunk.java | 17 +-- .../src/main/resources/fabric.mod.json | 2 +- .../onyxstudios/cca/test/chunk/ChunkVita.java | 5 +- .../mixin/entity/common/BucketableMixin.java | 4 +- .../cca/mixin/entity/common/MixinEntity.java | 14 +- .../src/main/resources/fabric.mod.json | 2 +- .../cca/test/entity/CcaEntityTestMod.java | 4 +- .../cca/test/entity/CcaEntityTestSuite.java | 2 +- .../cca/test/entity/PlayerVita.java | 5 +- .../cca/api/v3/level/LevelComponents.java | 6 +- .../level/ComponentsLevelNetworking.java | 4 +- .../level/common/MixinLevelProperties.java | 3 +- .../level/common/MixinMinecraftServer.java | 2 +- .../MixinUnmodifiableLevelProperties.java | 2 +- .../src/main/resources/fabric.mod.json | 2 +- .../ComponentsScoreboardNetworking.java | 12 +- .../scoreboard/MixinMinecraftServer.java | 4 +- .../scoreboard/MixinServerScoreboard.java | 9 +- .../cca/mixin/scoreboard/MixinTeam.java | 5 +- .../src/main/resources/fabric.mod.json | 4 +- .../mixin/world/common/MixinServerWorld.java | 5 +- .../src/main/resources/fabric.mod.json | 2 +- .../cca/test/world/AmbientVita.java | 8 +- changelog.md | 10 ++ gradle.properties | 17 +-- .../componenttest/content/CCATestClient.java | 4 +- .../content/CardinalComponentsTest.java | 10 +- .../componenttest/content/VitaCommand.java | 2 +- .../content/VitalityCondenser.java | 8 +- .../content/VitalityStickItem.java | 9 +- .../content/vita/AmbientVita.java | 94 ------------ .../componenttest/tests/CcaTestSuite.java | 6 +- 49 files changed, 242 insertions(+), 384 deletions(-) create mode 100644 cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/ComponentAccess.java delete mode 100644 src/testmod/java/dev/onyxstudios/componenttest/content/vita/AmbientVita.java diff --git a/README.md b/README.md index ed1c0b7b..55981119 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ Now, all that is left is to actually use that component. You can access individu ```java public static void useMagik(Entity provider) { // anything will work, as long as a module allows it! // Retrieve a provided component - int magik = MAGIK.get(provider).getValue(); + int magik = provider.getComponent(MAGIK).getValue(); // Or, if the object is not guaranteed to provide that component: int magik = MAGIK.maybeGet(provider).map(IntComponent::getValue).orElse(0); // ... diff --git a/build.gradle b/build.gradle index ca8dd6fa..aebc0caf 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ import net.fabricmc.loom.task.RemapJarTask import java.time.Year plugins { - id "fabric-loom" version "0.11-SNAPSHOT" apply false + id "fabric-loom" version "0.12-SNAPSHOT" apply false id 'io.github.juuxel.loom-quiltflower' version "1.6.0" id "org.cadixdev.licenser" version "0.6.1" id "com.matthewprenger.cursegradle" version "1.4.0" @@ -292,7 +292,7 @@ dependencies { // used by the test mod modImplementation fabricApi.module("fabric-api-base", fabric_api_version) modImplementation fabricApi.module("fabric-object-builder-api-v1", fabric_api_version) - modImplementation fabricApi.module("fabric-renderer-registries-v1", fabric_api_version) + modImplementation fabricApi.module("fabric-rendering-v1", fabric_api_version) modImplementation fabricApi.module("fabric-lifecycle-events-v1", fabric_api_version) modImplementation fabricApi.module("fabric-item-api-v1", fabric_api_version) modImplementation fabricApi.module("fabric-item-groups-v0", fabric_api_version) @@ -300,17 +300,15 @@ dependencies { modImplementation fabricApi.module("fabric-api-lookup-api-v1", fabric_api_version) modImplementation fabricApi.module("fabric-command-api-v1", fabric_api_version) modImplementation fabricApi.module("fabric-gametest-api-v1", fabric_api_version) - modRuntimeOnly fabricApi.module("fabric-networking-v0", fabric_api_version) + modRuntimeOnly fabricApi.module("fabric-networking-api-v1", fabric_api_version) modRuntimeOnly fabricApi.module("fabric-resource-loader-v0", fabric_api_version) - modRuntimeOnly fabricApi.module("fabric-mining-levels-v0", fabric_api_version) - modRuntimeOnly fabricApi.module("fabric-tag-extensions-v0", fabric_api_version) - modRuntimeOnly fabricApi.module("fabric-tool-attribute-api-v1", fabric_api_version) modRuntimeOnly fabricApi.module("fabric-events-interaction-v0", fabric_api_version) + modRuntimeOnly fabricApi.module("fabric-registry-sync-v0", fabric_api_version) testCompileOnly "com.google.code.findbugs:jsr305:3.0.2" include fabricApi.module("fabric-api-base", fabric_api_version) - include fabricApi.module("fabric-networking-v0", fabric_api_version) + include fabricApi.module("fabric-networking-api-v1", fabric_api_version) afterEvaluate { subprojects.each { diff --git a/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/ComponentAccess.java b/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/ComponentAccess.java new file mode 100644 index 00000000..c54ae824 --- /dev/null +++ b/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/ComponentAccess.java @@ -0,0 +1,101 @@ +/* + * Cardinal-Components-API + * Copyright (C) 2019-2022 OnyxStudios + * + * 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 dev.onyxstudios.cca.api.v3.component; + +import dev.onyxstudios.cca.api.v3.component.sync.ComponentPacketWriter; +import dev.onyxstudios.cca.api.v3.component.sync.PlayerSyncPredicate; + +import java.util.NoSuchElementException; + +/** + * Interface injected into classes that support the Cardinal Components API. + * + *

Implementations of this interface should do so through {@link ComponentProvider}. + * + * @see ComponentProvider + * @since 5.0.0 + */ +// Note: no method in this interface can be abstract, as it is injected into commonly inherited types by Loom +public interface ComponentAccess { + /** + * @param key the key object for the type of component to retrieve + * @return the nonnull value of the held component of this type + * @param the type of component to retrieve + * @throws NullPointerException if {@code key} is null + * @throws NoSuchElementException if this provider does not provide the desired type of component + */ + default C getComponent(ComponentKey key) { + return key.get(this.asComponentProvider()); + } + + /** + * Attempts to synchronize the component of the desired type with watching clients. + * + *

This method has no visible effect if {@linkplain #asComponentProvider() this provider} does not support synchronization, or + * the associated component does not implement an adequate {@linkplain dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent synchronization interface}. + * + * @param key the key object for the type of component to synchronize + * @throws NoSuchElementException if the provider does not provide this type of component + * @throws ClassCastException if provider does not implement {@link ComponentProvider} + * @see ComponentKey#sync(Object) + */ + default void syncComponent(ComponentKey key) { + key.sync(this.asComponentProvider()); + } + + /** + * Attempts to synchronize the component of the desired type with watching clients using the specified {@code packetWriter}. + * + *

This method has no visible effect if {@linkplain #asComponentProvider() this provider} does not support synchronization, or + * the associated component does not implement an adequate {@linkplain dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent synchronization interface}. + * + * @param key the key object for the type of component to synchronize + * @param packetWriter a writer for the sync packet + * @throws NoSuchElementException if the provider does not provide this type of component + * @throws ClassCastException if provider does not implement {@link ComponentProvider} + * @see ComponentKey#sync(Object, ComponentPacketWriter) + */ + default void syncComponent(ComponentKey key, ComponentPacketWriter packetWriter) { + key.sync(this.asComponentProvider(), packetWriter); + } + + /** + * Attempts to synchronize the component of the desired type with watching clients matching the {@code predicate}, + * using the specified {@code packetWriter}. + * + *

This method has no visible effect if {@linkplain #asComponentProvider() this provider} does not support synchronization, or + * the associated component does not implement an adequate {@linkplain dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent synchronization interface}. + * + * @param key the key object for the type of component to synchronize + * @throws NoSuchElementException if the provider does not provide this type of component + * @throws ClassCastException if provider does not implement {@link ComponentProvider} + * @see ComponentKey#sync(Object, ComponentPacketWriter, PlayerSyncPredicate) + */ + default void syncComponent(ComponentKey key, ComponentPacketWriter packetWriter, PlayerSyncPredicate predicate) { + key.sync(this.asComponentProvider(), packetWriter, predicate); + } + + default ComponentProvider asComponentProvider() { + return (ComponentProvider) this; + } +} diff --git a/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/ComponentKey.java b/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/ComponentKey.java index 6d27e935..58356295 100644 --- a/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/ComponentKey.java +++ b/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/ComponentKey.java @@ -33,7 +33,6 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; -import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Optional; @@ -58,28 +57,32 @@ public final Class getComponentClass() { } /** + * Attempts to retrieve a component instance from the given {@code provider}. + * * @param provider a component provider * @return the attached component associated with this key, or * {@code null} if the provider does not support this type of component - * @throws ClassCastException if the {@code provider} is + * @throws ClassCastException if provider does not implement {@link ComponentProvider} * @see #get(Object) * @see #maybeGet(Object) */ @Contract(pure = true) - public @Nullable C getNullable(V provider) { + public @Nullable C getNullable(Object provider) { return this.getInternal(((ComponentProvider) provider).getComponentContainer()); } /** + * Retrieves a component instance from the given {@code provider}. + * * @param provider a component provider - * @param the class of the component provider * @return the nonnull value of the held component of this type * @throws NullPointerException if {@code provider} is null * @throws NoSuchElementException if the provider does not provide this type of component * @throws ClassCastException if provider does not implement {@link ComponentProvider} * @see #maybeGet(Object) + * @see ComponentAccess#getComponent(ComponentKey) */ - public final C get(V provider) { + public final C get(Object provider) { C component = this.getInternal(((ComponentProvider) provider).getComponentContainer()); assert component == null || this.getComponentClass().isInstance(component); @@ -99,12 +102,11 @@ public final C get(V provider) { /** * @param provider a component provider - * @param the class of the component provider * @return an {@code Optional} describing a component of this type, or an empty * {@code Optional} if {@code provider} does not have such a component. * @see #get(Object) */ - public final Optional maybeGet(@Nullable V provider) { + public final Optional maybeGet(@Nullable Object provider) { if (provider instanceof ComponentProvider p) { return Optional.ofNullable(this.getInternal(p.getComponentContainer())); } @@ -112,7 +114,7 @@ public final Optional maybeGet(@Nullable V provider) { } @Contract(pure = true) - public boolean isProvidedBy(V provider) { + public boolean isProvidedBy(Object provider) { return this.getNullable(provider) != null; } @@ -123,11 +125,11 @@ public boolean isProvidedBy(V provider) { * the associated component does not implement an adequate synchronization interface. * * @param provider a component provider - * @param the class of the component provider * @throws NoSuchElementException if the provider does not provide this type of component * @throws ClassCastException if provider does not implement {@link ComponentProvider} + * @see ComponentAccess#syncComponent(ComponentKey) */ - public void sync(V provider) { + public void sync(Object provider) { if (this.get(provider) instanceof AutoSyncedComponent synced) { this.sync(provider, synced, synced); } @@ -139,13 +141,13 @@ public void sync(V provider) { *

This method has no visible effect if the given provider does not support synchronization, or * the associated component does not implement an adequate synchronization interface. * - * @param the class of the component provider * @param provider a component provider * @param packetWriter a writer for the sync packet * @throws NoSuchElementException if the provider does not provide this type of component * @throws ClassCastException if provider does not implement {@link ComponentProvider} + * @see ComponentAccess#syncComponent(ComponentKey, ComponentPacketWriter) */ - public void sync(V provider, ComponentPacketWriter packetWriter) { + public void sync(Object provider, ComponentPacketWriter packetWriter) { if (this.get(provider) instanceof AutoSyncedComponent synced) { this.sync(provider, packetWriter, synced); } @@ -157,17 +159,16 @@ public void sync(V provider, ComponentPacketWriter packetWriter) { *

This method has no visible effect if the given provider does not support synchronization, or * the associated component does not implement an adequate synchronization interface. * - * @param the class of the component provider * @param provider a component provider * @param packetWriter a writer for the sync packet * @param predicate a predicate for which players should receive the packet * @throws NoSuchElementException if the provider does not provide this type of component * @throws ClassCastException if provider does not implement {@link ComponentProvider} + * @see ComponentAccess#syncComponent(ComponentKey, ComponentPacketWriter, PlayerSyncPredicate) */ - public void sync(V provider, ComponentPacketWriter packetWriter, PlayerSyncPredicate predicate) { - ComponentProvider prov = (ComponentProvider) provider; - for (Iterator it = prov.getRecipientsForComponentSync(); it.hasNext();) { - this.syncWith(it.next(), prov, packetWriter, predicate); + public void sync(Object provider, ComponentPacketWriter packetWriter, PlayerSyncPredicate predicate) { + for (ServerPlayerEntity player : ((ComponentProvider) provider).getRecipientsForComponentSync()) { + this.syncWith(player, (ComponentProvider) provider, packetWriter, predicate); } } diff --git a/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/ComponentProvider.java b/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/ComponentProvider.java index 21b12da5..f715c535 100644 --- a/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/ComponentProvider.java +++ b/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/ComponentProvider.java @@ -25,140 +25,22 @@ import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent; import dev.onyxstudios.cca.api.v3.component.sync.ComponentPacketWriter; import dev.onyxstudios.cca.api.v3.component.sync.PlayerSyncPredicate; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.entity.Entity; -import net.minecraft.item.ItemStack; -import net.minecraft.network.PacketByteBuf; import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; -import net.minecraft.scoreboard.AbstractTeam; -import net.minecraft.scoreboard.Scoreboard; -import net.minecraft.scoreboard.Team; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.world.World; -import net.minecraft.world.WorldProperties; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.level.LevelProperties; -import org.jetbrains.annotations.ApiStatus; import javax.annotation.Nullable; -import java.util.Collections; -import java.util.Iterator; -import java.util.NoSuchElementException; +import java.util.List; /** - * used to access an object's components. + * @see ComponentAccess + * @see ComponentContainer */ -public interface ComponentProvider { - - /** - * Convenience method to retrieve ComponentProvider from a given {@link BlockEntity} - * Requires the cardinal-components-block module. - * @deprecated this interface is now injected by loom; update to 0.11 if you don't see it - */ - @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") - @Deprecated(forRemoval = true, since = "4.1.0") - static ComponentProvider fromBlockEntity(BlockEntity blockEntity) { - return (ComponentProvider) blockEntity; - } - - /** - * Convenience method to retrieve a ComponentProvider from given {@link Chunk}. - * Requires the cardinal-components-chunk module. - * @deprecated this interface is now injected by loom; update to 0.11 if you don't see it - */ - @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") - @Deprecated(forRemoval = true, since = "4.1.0") - static ComponentProvider fromChunk(Chunk chunk) { - return (ComponentProvider) chunk; - } - - /** - * Convenience method to retrieve a ComponentProvider from a given {@link Entity}. - * Requires the cardinal-components-entity module. - * @deprecated this interface is now injected by loom; update to 0.11 if you don't see it - */ - @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") - @Deprecated(forRemoval = true, since = "4.1.0") - static ComponentProvider fromEntity(Entity entity) { - return (ComponentProvider) entity; - } - - /** - * Convenience method to retrieve ComponentProvider from a given {@link ItemStack} - * Requires the cardinal-components-item module. - * @deprecated this module is getting removed; use Fabric's API-Lookup-API instead - */ - @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") - @Deprecated(forRemoval = true, since = "4.1.0") - @SuppressWarnings("ConstantConditions") - static ComponentProvider fromItemStack(ItemStack stack) { - return (ComponentProvider) (Object) stack; - } - - /** - * Convenience method to retrieve a ComponentProvider from given {@link LevelProperties}. - * Requires the cardinal-components-level module. - * @deprecated this interface is now injected by loom; update to 0.11 if you don't see it - */ - @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") - @Deprecated(forRemoval = true, since = "4.1.0") - static ComponentProvider fromLevel(WorldProperties level) { - return (ComponentProvider) level; - } - - /** - * Convenience method to retrieve a ComponentProvider from given {@link Scoreboard}. - * Requires the cardinal-components-scoreboard module. - * @deprecated this interface is now injected by loom; update to 0.11 if you don't see it - */ - @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") - @Deprecated(forRemoval = true, since = "4.1.0") - static ComponentProvider fromScoreboard(Scoreboard scoreboard) { - return (ComponentProvider) scoreboard; - } - - /** - * Convenience method to retrieve a ComponentProvider from given {@link Team}. - * Requires the cardinal-components-scoreboard module. - * @deprecated this interface is now injected by loom; update to 0.11 if you don't see it - */ - @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") - @Deprecated(forRemoval = true, since = "4.1.0") - static ComponentProvider fromTeam(AbstractTeam team) { - return (ComponentProvider) team; - } - - /** - * Convenience method to retrieve a ComponentProvider from a given {@link World}. - * Requires the cardinal-components-world module. - * @deprecated this interface is now injected by loom; update to 0.11 if you don't see it - */ - @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") - @Deprecated(forRemoval = true, since = "4.1.0") - static ComponentProvider fromWorld(World world) { - return (ComponentProvider) world; - } +public interface ComponentProvider extends ComponentAccess { /** * @return a runtime-generated component container storing statically declared components. */ - default ComponentContainer getComponentContainer() { - throw new UnsupportedOperationException("Please implement me"); - } - - /** - * @param key the key object for the type of component to retrieve - * @return the nonnull value of the held component of this type - * @param the type of component to retrieve - * @throws NullPointerException if {@code key} is null - * @throws NoSuchElementException if this provider does not provide the desired type of component - * @since 4.1.0 - */ - @ApiStatus.Experimental - default C getComponent(ComponentKey key) { - return key.get(this); - } + ComponentContainer getComponentContainer(); /** * Retrieves an iterator describing the list of players who may receive @@ -171,9 +53,8 @@ default C getComponent(ComponentKey key) { * * @return a list of player candidates for receiving component sync packets */ - default Iterator getRecipientsForComponentSync() { - // TODO 5.0.0 replace with Iterable - return Collections.emptyIterator(); + default Iterable getRecipientsForComponentSync() { + return List.of(); } /** @@ -187,16 +68,6 @@ default Iterator getRecipientsForComponentSync() { */ @Nullable default CustomPayloadS2CPacket toComponentPacket(ComponentKey key, ComponentPacketWriter writer, ServerPlayerEntity recipient) { - // TODO 4.0.0 inline - return toComponentPacket(PacketByteBufs.create(), key, writer, recipient); - } - - /** - * @deprecated override/call {@link #toComponentPacket(ComponentKey, ComponentPacketWriter, ServerPlayerEntity)} instead - */ - @SuppressWarnings("unused") @Deprecated(since = "3.0.0", forRemoval = true) - @Nullable - default CustomPayloadS2CPacket toComponentPacket(PacketByteBuf buf, ComponentKey key, ComponentPacketWriter writer, ServerPlayerEntity recipient) { return null; } } diff --git a/cardinal-components-base/src/testmod/java/dev/onyxstudios/cca/test/base/Vita.java b/cardinal-components-base/src/testmod/java/dev/onyxstudios/cca/test/base/Vita.java index 6178df10..c6122939 100644 --- a/cardinal-components-base/src/testmod/java/dev/onyxstudios/cca/test/base/Vita.java +++ b/cardinal-components-base/src/testmod/java/dev/onyxstudios/cca/test/base/Vita.java @@ -31,7 +31,7 @@ Vita extends ComponentV3 { ComponentKey KEY = ComponentRegistryV3.INSTANCE.getOrCreate(new Identifier("cca-base-test", "vita"), Vita.class); - static Vita get(T provider) { + static Vita get(Object provider) { return KEY.get(provider); } diff --git a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/internal/CardinalComponentsBlock.java b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/internal/CardinalComponentsBlock.java index 9b5271c1..c5dabf62 100644 --- a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/internal/CardinalComponentsBlock.java +++ b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/internal/CardinalComponentsBlock.java @@ -58,7 +58,7 @@ public static void init() { }); BlockEntitySyncAroundCallback.EVENT.register(tracked -> { for (ComponentKey key : ((ComponentProvider) tracked).getComponentContainer().keys()) { - key.sync(tracked); + tracked.syncComponent(key); } }); } diff --git a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/internal/block/StaticBlockComponentPlugin.java b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/internal/block/StaticBlockComponentPlugin.java index d915dbc3..a588a6c3 100644 --- a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/internal/block/StaticBlockComponentPlugin.java +++ b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/internal/block/StaticBlockComponentPlugin.java @@ -41,13 +41,7 @@ import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.function.Predicate; public final class StaticBlockComponentPlugin extends LazyDispatcher implements BlockComponentFactoryRegistry { @@ -69,15 +63,15 @@ private StaticBlockComponentPlugin() { @Nullable public BlockEntityTicker getComponentTicker(World world, T be, @Nullable BlockEntityTicker base) { if (world.isClient && this.clientTicking.contains(be.getClass())) { - if (base == null) return (w, pos, state, blockEntity) -> blockEntity.getComponentContainer().tickClientComponents(); + if (base == null) return (w, pos, state, blockEntity) -> blockEntity.asComponentProvider().getComponentContainer().tickClientComponents(); return (w, pos, state, blockEntity) -> { - blockEntity.getComponentContainer().tickClientComponents(); + blockEntity.asComponentProvider().getComponentContainer().tickClientComponents(); base.tick(w, pos, state, blockEntity); }; } else if (!world.isClient && this.serverTicking.contains(be.getClass())) { - if (base == null) return (w, pos, state, blockEntity) -> blockEntity.getComponentContainer().tickServerComponents(); + if (base == null) return (w, pos, state, blockEntity) -> blockEntity.asComponentProvider().getComponentContainer().tickServerComponents(); return (w, pos, state, blockEntity) -> { - blockEntity.getComponentContainer().tickServerComponents(); + blockEntity.asComponentProvider().getComponentContainer().tickServerComponents(); base.tick(w, pos, state, blockEntity); }; } diff --git a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinBlockDataObject.java b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinBlockDataObject.java index a8a80ffa..3f6f8d06 100644 --- a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinBlockDataObject.java +++ b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinBlockDataObject.java @@ -40,6 +40,6 @@ public abstract class MixinBlockDataObject { @Inject(method = "setNbt", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/BlockEntity;markDirty()V")) void readComponentData(NbtCompound nbt, CallbackInfo ci) { - this.blockEntity.getComponentContainer().fromTag(nbt); + this.blockEntity.asComponentProvider().getComponentContainer().fromTag(nbt); } } diff --git a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinBlockEntity.java b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinBlockEntity.java index ebf83209..9667e51b 100644 --- a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinBlockEntity.java +++ b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinBlockEntity.java @@ -50,8 +50,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Collections; -import java.util.Iterator; +import java.util.List; @Mixin(BlockEntity.class) public abstract class MixinBlockEntity implements ComponentProvider { @@ -71,7 +70,7 @@ public abstract class MixinBlockEntity implements ComponentProvider { @Inject(method = "createFromNbt", at = @At("RETURN")) private static void readComponentData(BlockPos pos, BlockState state, NbtCompound nbt, CallbackInfoReturnable cir) { if (cir.getReturnValue() != null) { - cir.getReturnValue().getComponentContainer().fromTag(nbt); + cir.getReturnValue().asComponentProvider().getComponentContainer().fromTag(nbt); } } @@ -109,13 +108,13 @@ public ComponentContainer getComponentContainer() { } @Override - public Iterator getRecipientsForComponentSync() { + public Iterable getRecipientsForComponentSync() { World world = this.getWorld(); if (world != null && !world.isClient) { - return PlayerLookup.tracking((BlockEntity) (Object) this).iterator(); + return PlayerLookup.tracking((BlockEntity) (Object) this); } - return Collections.emptyIterator(); + return List.of(); } @Nullable diff --git a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinBlockStateArgument.java b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinBlockStateArgument.java index 360c006a..563d74b6 100644 --- a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinBlockStateArgument.java +++ b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinBlockStateArgument.java @@ -42,7 +42,7 @@ public class MixinBlockStateArgument { @ModifyVariable(method = "setBlockState", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/BlockEntity;readNbt(Lnet/minecraft/nbt/NbtCompound;)V", shift = At.Shift.AFTER)) private BlockEntity readComponentData(BlockEntity be) { if (this.data != null) { - be.getComponentContainer().fromTag(this.data); + be.asComponentProvider().getComponentContainer().fromTag(this.data); } return be; } diff --git a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinFallingBlockEntity.java b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinFallingBlockEntity.java index 59bd1f10..91192987 100644 --- a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinFallingBlockEntity.java +++ b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinFallingBlockEntity.java @@ -44,6 +44,6 @@ public MixinFallingBlockEntity(EntityType type, World world) { @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/BlockEntity;readNbt(Lnet/minecraft/nbt/NbtCompound;)V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILSOFT) void readComponentData(CallbackInfo ci, Block $$0, BlockPos $$2, BlockEntity be, NbtCompound nbt) { - be.getComponentContainer().fromTag(nbt); + be.asComponentProvider().getComponentContainer().fromTag(nbt); } } diff --git a/cardinal-components-block/src/main/resources/fabric.mod.json b/cardinal-components-block/src/main/resources/fabric.mod.json index 2332f490..d2ccf168 100644 --- a/cardinal-components-block/src/main/resources/fabric.mod.json +++ b/cardinal-components-block/src/main/resources/fabric.mod.json @@ -26,7 +26,7 @@ }, "loom:injected_interfaces": { "net/minecraft/class_2586": [ - "dev/onyxstudios/cca/api/v3/component/ComponentProvider" + "dev/onyxstudios/cca/api/v3/component/ComponentAccess" ] } }, diff --git a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/internal/chunk/ComponentsChunkNetworking.java b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/internal/chunk/ComponentsChunkNetworking.java index 3b85c8c5..c7c9c044 100644 --- a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/internal/chunk/ComponentsChunkNetworking.java +++ b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/internal/chunk/ComponentsChunkNetworking.java @@ -34,11 +34,10 @@ public final class ComponentsChunkNetworking { public static void init() { if (FabricLoader.getInstance().isModLoaded("fabric-networking-api-v1")) { ChunkSyncCallback.EVENT.register((player, tracked) -> { - for (ComponentKey key : tracked.getComponentContainer().keys()) { + for (ComponentKey key : tracked.asComponentProvider().getComponentContainer().keys()) { key.syncWith(player, (ComponentProvider) tracked); } }); } } - } diff --git a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinChunkSerializer.java b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinChunkSerializer.java index 6ad91fdb..5e531fba 100644 --- a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinChunkSerializer.java +++ b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinChunkSerializer.java @@ -41,12 +41,12 @@ public abstract class MixinChunkSerializer { private static void deserialize(ServerWorld world, PointOfInterestStorage pointOfInterestStorage, ChunkPos chunkPos, NbtCompound tag, CallbackInfoReturnable cir) { ProtoChunk ret = cir.getReturnValue(); Chunk chunk = ret instanceof ReadOnlyChunk ? ((ReadOnlyChunk) ret).getWrappedChunk() : ret; - chunk.getComponentContainer().fromTag(tag); + chunk.asComponentProvider().getComponentContainer().fromTag(tag); } @Inject(method = "serialize", at = @At("RETURN")) private static void serialize(ServerWorld world, Chunk chunk, CallbackInfoReturnable cir) { NbtCompound ret = cir.getReturnValue(); - chunk.getComponentContainer().toTag(ret); + chunk.asComponentProvider().getComponentContainer().toTag(ret); } } diff --git a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinReadOnlyChunk.java b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinReadOnlyChunk.java index 8bb6a3ac..3d58871a 100644 --- a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinReadOnlyChunk.java +++ b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinReadOnlyChunk.java @@ -39,6 +39,6 @@ public abstract class MixinReadOnlyChunk implements ComponentProvider { @Nonnull @Override public ComponentContainer getComponentContainer() { - return this.wrapped.getComponentContainer(); + return this.wrapped.asComponentProvider().getComponentContainer(); } } diff --git a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinServerWorld.java b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinServerWorld.java index 27e1205e..1c79e1bc 100644 --- a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinServerWorld.java +++ b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinServerWorld.java @@ -33,6 +33,6 @@ public abstract class MixinServerWorld { @Inject(method = "tickChunk", at = @At("RETURN")) private void tick(WorldChunk chunk, int randomTickSpeed, CallbackInfo ci) { - chunk.getComponentContainer().tickServerComponents(); + chunk.asComponentProvider().getComponentContainer().tickServerComponents(); } } diff --git a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinWorldChunk.java b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinWorldChunk.java index 4a3d6d81..c6d4d819 100644 --- a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinWorldChunk.java +++ b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinWorldChunk.java @@ -38,11 +38,7 @@ import net.minecraft.world.HeightLimitView; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.ChunkSection; -import net.minecraft.world.chunk.ProtoChunk; -import net.minecraft.world.chunk.UpgradeData; -import net.minecraft.world.chunk.WorldChunk; +import net.minecraft.world.chunk.*; import net.minecraft.world.gen.chunk.BlendingData; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; @@ -51,8 +47,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.Collections; -import java.util.Iterator; +import java.util.List; @Mixin(WorldChunk.class) public abstract class MixinWorldChunk extends Chunk implements ComponentProvider { @@ -64,11 +59,11 @@ public MixinWorldChunk(ChunkPos pos, UpgradeData upgradeData, HeightLimitView he public abstract World getWorld(); @Override - public Iterator getRecipientsForComponentSync() { + public Iterable getRecipientsForComponentSync() { if (!this.getWorld().isClient()) { - return PlayerLookup.tracking((ServerWorld) this.getWorld(), this.getPos()).iterator(); + return PlayerLookup.tracking((ServerWorld) this.getWorld(), this.getPos()); } - return Collections.emptyIterator(); + return List.of(); } @Override @@ -84,6 +79,6 @@ public CustomPayloadS2CPacket toComponentPacket( @Inject(method = "(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/ProtoChunk;Lnet/minecraft/world/chunk/WorldChunk$EntityLoader;)V", at = @At("RETURN")) private void copyFromProto(ServerWorld world, ProtoChunk proto, WorldChunk.EntityLoader entityLoader, CallbackInfo ci) { - this.getComponentContainer().copyFrom(proto.getComponentContainer()); + this.getComponentContainer().copyFrom(proto.asComponentProvider().getComponentContainer()); } } diff --git a/cardinal-components-chunk/src/main/resources/fabric.mod.json b/cardinal-components-chunk/src/main/resources/fabric.mod.json index 6ad973af..5001cf4c 100644 --- a/cardinal-components-chunk/src/main/resources/fabric.mod.json +++ b/cardinal-components-chunk/src/main/resources/fabric.mod.json @@ -26,7 +26,7 @@ }, "loom:injected_interfaces": { "net/minecraft/class_2791": [ - "dev/onyxstudios/cca/api/v3/component/ComponentProvider" + "dev/onyxstudios/cca/api/v3/component/ComponentAccess" ] } }, diff --git a/cardinal-components-chunk/src/testmod/java/dev/onyxstudios/cca/test/chunk/ChunkVita.java b/cardinal-components-chunk/src/testmod/java/dev/onyxstudios/cca/test/chunk/ChunkVita.java index dba6cab8..54b9820b 100644 --- a/cardinal-components-chunk/src/testmod/java/dev/onyxstudios/cca/test/chunk/ChunkVita.java +++ b/cardinal-components-chunk/src/testmod/java/dev/onyxstudios/cca/test/chunk/ChunkVita.java @@ -24,7 +24,6 @@ import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent; import dev.onyxstudios.cca.test.base.BaseVita; -import dev.onyxstudios.cca.test.base.Vita; import net.minecraft.world.chunk.Chunk; public class ChunkVita extends BaseVita implements AutoSyncedComponent { @@ -37,7 +36,7 @@ public ChunkVita(Chunk owner) { @Override public void setVitality(int value) { super.setVitality(value); - Vita.KEY.sync(this.owner); - this.owner.setShouldSave(true); + this.owner.syncComponent(KEY); + this.owner.setNeedsSaving(true); } } diff --git a/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/BucketableMixin.java b/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/BucketableMixin.java index 71ed60b4..2b397a12 100644 --- a/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/BucketableMixin.java +++ b/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/BucketableMixin.java @@ -37,12 +37,12 @@ public interface BucketableMixin { private static void writeComponentsToStack(MobEntity entity, ItemStack stack, CallbackInfo ci) { NbtCompound nbt = stack.getNbt(); if (nbt != null) { - entity.getComponentContainer().toTag(nbt); + entity.asComponentProvider().getComponentContainer().toTag(nbt); } } @Inject(method = "copyDataFromNbt(Lnet/minecraft/entity/mob/MobEntity;Lnet/minecraft/nbt/NbtCompound;)V", at = @At("RETURN")) private static void readComponentsFromStack(MobEntity entity, NbtCompound nbt, CallbackInfo ci) { - entity.getComponentContainer().fromTag(nbt); + entity.asComponentProvider().getComponentContainer().fromTag(nbt); } } diff --git a/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/MixinEntity.java b/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/MixinEntity.java index 54ffebc9..e49d2669 100644 --- a/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/MixinEntity.java +++ b/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/MixinEntity.java @@ -22,7 +22,6 @@ */ package dev.onyxstudios.cca.mixin.entity.common; -import com.google.common.collect.Iterators; import dev.onyxstudios.cca.api.v3.component.ComponentContainer; import dev.onyxstudios.cca.api.v3.component.ComponentKey; import dev.onyxstudios.cca.api.v3.component.ComponentProvider; @@ -49,8 +48,9 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Collections; -import java.util.Iterator; +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.List; @Mixin(Entity.class) public abstract class MixinEntity implements ComponentProvider { @@ -87,16 +87,16 @@ public ComponentContainer getComponentContainer() { } @Override - public Iterator getRecipientsForComponentSync() { + public Iterable getRecipientsForComponentSync() { Entity holder = (Entity) (Object) this; if (!this.world.isClient) { - Iterator watchers = PlayerLookup.tracking(holder).iterator(); + Deque watchers = new ArrayDeque<>(PlayerLookup.tracking(holder)); if (holder instanceof ServerPlayerEntity player && player.networkHandler != null) { - return Iterators.concat(Iterators.singletonIterator(player), watchers); + watchers.addFirst(player); } return watchers; } - return Collections.emptyIterator(); + return List.of(); } @Nullable diff --git a/cardinal-components-entity/src/main/resources/fabric.mod.json b/cardinal-components-entity/src/main/resources/fabric.mod.json index ca1e7eda..e94f5f07 100644 --- a/cardinal-components-entity/src/main/resources/fabric.mod.json +++ b/cardinal-components-entity/src/main/resources/fabric.mod.json @@ -26,7 +26,7 @@ }, "loom:injected_interfaces": { "net/minecraft/class_1297": [ - "dev/onyxstudios/cca/api/v3/component/ComponentProvider" + "dev/onyxstudios/cca/api/v3/component/ComponentAccess" ] } }, diff --git a/cardinal-components-entity/src/testmod/java/dev/onyxstudios/cca/test/entity/CcaEntityTestMod.java b/cardinal-components-entity/src/testmod/java/dev/onyxstudios/cca/test/entity/CcaEntityTestMod.java index d73f0fe8..6bb8f7b7 100644 --- a/cardinal-components-entity/src/testmod/java/dev/onyxstudios/cca/test/entity/CcaEntityTestMod.java +++ b/cardinal-components-entity/src/testmod/java/dev/onyxstudios/cca/test/entity/CcaEntityTestMod.java @@ -26,15 +26,15 @@ import dev.onyxstudios.cca.api.v3.entity.EntityComponentInitializer; import dev.onyxstudios.cca.test.base.Vita; import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; import net.minecraft.entity.EntityType; +import net.minecraft.entity.SpawnGroup; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; public class CcaEntityTestMod implements ModInitializer, EntityComponentInitializer { - public static final EntityType TEST_ENTITY = FabricEntityTypeBuilder.create().entityFactory(TestEntity::new).build(); + public static final EntityType TEST_ENTITY = EntityType.Builder.create(TestEntity::new, SpawnGroup.MISC).build("cca-entity-test"); @Override public void registerEntityComponentFactories(EntityComponentFactoryRegistry registry) { diff --git a/cardinal-components-entity/src/testmod/java/dev/onyxstudios/cca/test/entity/CcaEntityTestSuite.java b/cardinal-components-entity/src/testmod/java/dev/onyxstudios/cca/test/entity/CcaEntityTestSuite.java index 99caac64..f62eec05 100644 --- a/cardinal-components-entity/src/testmod/java/dev/onyxstudios/cca/test/entity/CcaEntityTestSuite.java +++ b/cardinal-components-entity/src/testmod/java/dev/onyxstudios/cca/test/entity/CcaEntityTestSuite.java @@ -42,7 +42,7 @@ public void bucketableWorks(TestContext ctx) { player.setStackInHand(Hand.MAIN_HAND, new ItemStack(Items.WATER_BUCKET)); BlockPos pos = new BlockPos(2, 0, 2); var axolotl = ctx.spawnMob(EntityType.AXOLOTL, pos); - Vita.get(axolotl).setVitality(3); + axolotl.getComponent(Vita.KEY).setVitality(3); Bucketable.tryBucket(player, Hand.MAIN_HAND, axolotl); ((EntityBucketItem) Items.AXOLOTL_BUCKET).onEmptied(player, ctx.getWorld(), player.getStackInHand(Hand.MAIN_HAND), ctx.getAbsolutePos(pos)); ctx.expectEntityWithDataEnd(pos, EntityType.AXOLOTL, a -> a.getComponent(Vita.KEY).getVitality(), 3); diff --git a/cardinal-components-entity/src/testmod/java/dev/onyxstudios/cca/test/entity/PlayerVita.java b/cardinal-components-entity/src/testmod/java/dev/onyxstudios/cca/test/entity/PlayerVita.java index f61ed8b0..e79363e9 100644 --- a/cardinal-components-entity/src/testmod/java/dev/onyxstudios/cca/test/entity/PlayerVita.java +++ b/cardinal-components-entity/src/testmod/java/dev/onyxstudios/cca/test/entity/PlayerVita.java @@ -34,6 +34,7 @@ import net.minecraft.network.PacketByteBuf; import net.minecraft.particle.ParticleTypes; import net.minecraft.server.network.ServerPlayerEntity; +import org.jetbrains.annotations.NotNull; /** * A Vita component attached to players, and automatically synchronized with their owner @@ -51,7 +52,7 @@ public void setVitality(int value) { if (value != this.vitality) { int increase = value - this.vitality; super.setVitality(value); - Vita.KEY.sync(this.owner, (buf, recipient) -> this.writeSyncPacket(buf, recipient, increase), PlayerSyncPredicate.all()); + this.owner.syncComponent(Vita.KEY, (buf, recipient) -> this.writeSyncPacket(buf, recipient, increase), PlayerSyncPredicate.all()); } } @@ -100,7 +101,7 @@ public boolean shouldCopyForRespawn(boolean lossless, boolean keepInventory, boo } @Override - public void copyForRespawn(BaseVita original, boolean lossless, boolean keepInventory, boolean switchingCharacter) { + public void copyForRespawn(@NotNull BaseVita original, boolean lossless, boolean keepInventory, boolean switchingCharacter) { PlayerComponent.super.copyForRespawn(original, lossless, keepInventory, switchingCharacter); if (!lossless && !keepInventory) { this.vitality -= 5; diff --git a/cardinal-components-level/src/main/java/dev/onyxstudios/cca/api/v3/level/LevelComponents.java b/cardinal-components-level/src/main/java/dev/onyxstudios/cca/api/v3/level/LevelComponents.java index 87cefe8a..7703db02 100644 --- a/cardinal-components-level/src/main/java/dev/onyxstudios/cca/api/v3/level/LevelComponents.java +++ b/cardinal-components-level/src/main/java/dev/onyxstudios/cca/api/v3/level/LevelComponents.java @@ -48,7 +48,7 @@ public final class LevelComponents { public static void sync(ComponentKey key, MinecraftServer server) { WorldProperties props = server.getSaveProperties().getMainWorldProperties(); for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) { - key.syncWith(player, props); + key.syncWith(player, props.asComponentProvider()); } } @@ -66,7 +66,7 @@ public static void sync(ComponentKey key, MinecraftServer server, ComponentPa Component c = key.get(props); if (c instanceof AutoSyncedComponent sc) { for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) { - key.syncWith(player, props, packetWriter, sc); + key.syncWith(player, props.asComponentProvider(), packetWriter, sc); } } } @@ -84,7 +84,7 @@ public static void sync(ComponentKey key, MinecraftServer server, ComponentPa public static void sync(ComponentKey key, MinecraftServer server, ComponentPacketWriter packetWriter, PlayerSyncPredicate predicate) { WorldProperties props = server.getSaveProperties().getMainWorldProperties(); for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) { - key.syncWith(player, props, packetWriter, predicate); + key.syncWith(player, props.asComponentProvider(), packetWriter, predicate); } } } diff --git a/cardinal-components-level/src/main/java/dev/onyxstudios/cca/internal/level/ComponentsLevelNetworking.java b/cardinal-components-level/src/main/java/dev/onyxstudios/cca/internal/level/ComponentsLevelNetworking.java index a86602d3..4cf6ba57 100644 --- a/cardinal-components-level/src/main/java/dev/onyxstudios/cca/internal/level/ComponentsLevelNetworking.java +++ b/cardinal-components-level/src/main/java/dev/onyxstudios/cca/internal/level/ComponentsLevelNetworking.java @@ -49,8 +49,8 @@ public static void init() { WorldSyncCallback.EVENT.register((player, world) -> { WorldProperties props = world.getLevelProperties(); - for (ComponentKey key : props.getComponentContainer().keys()) { - key.syncWith(player, props); + for (ComponentKey key : props.asComponentProvider().getComponentContainer().keys()) { + key.syncWith(player, props.asComponentProvider()); } }); } diff --git a/cardinal-components-level/src/main/java/dev/onyxstudios/cca/mixin/level/common/MixinLevelProperties.java b/cardinal-components-level/src/main/java/dev/onyxstudios/cca/mixin/level/common/MixinLevelProperties.java index 402569a4..79dfd36f 100644 --- a/cardinal-components-level/src/main/java/dev/onyxstudios/cca/mixin/level/common/MixinLevelProperties.java +++ b/cardinal-components-level/src/main/java/dev/onyxstudios/cca/mixin/level/common/MixinLevelProperties.java @@ -56,7 +56,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Iterator; import java.util.Set; import java.util.UUID; @@ -87,7 +86,7 @@ public ComponentContainer getComponentContainer() { } @Override - public Iterator getRecipientsForComponentSync() { + public Iterable getRecipientsForComponentSync() { throw new UnsupportedOperationException("Please call LevelComponents#sync(MinecraftServer) instead of ComponentKey#sync"); } diff --git a/cardinal-components-level/src/main/java/dev/onyxstudios/cca/mixin/level/common/MixinMinecraftServer.java b/cardinal-components-level/src/main/java/dev/onyxstudios/cca/mixin/level/common/MixinMinecraftServer.java index f9555819..9d948bf5 100644 --- a/cardinal-components-level/src/main/java/dev/onyxstudios/cca/mixin/level/common/MixinMinecraftServer.java +++ b/cardinal-components-level/src/main/java/dev/onyxstudios/cca/mixin/level/common/MixinMinecraftServer.java @@ -38,6 +38,6 @@ public abstract class MixinMinecraftServer { @Inject(at = @At("TAIL"), method = "tick") private void onEndTick(BooleanSupplier shouldKeepTicking, CallbackInfo info) { - this.getSaveProperties().getMainWorldProperties().getComponentContainer().tickServerComponents(); + this.getSaveProperties().getMainWorldProperties().asComponentProvider().getComponentContainer().tickServerComponents(); } } diff --git a/cardinal-components-level/src/main/java/dev/onyxstudios/cca/mixin/level/common/MixinUnmodifiableLevelProperties.java b/cardinal-components-level/src/main/java/dev/onyxstudios/cca/mixin/level/common/MixinUnmodifiableLevelProperties.java index 08e841cd..13d8369e 100644 --- a/cardinal-components-level/src/main/java/dev/onyxstudios/cca/mixin/level/common/MixinUnmodifiableLevelProperties.java +++ b/cardinal-components-level/src/main/java/dev/onyxstudios/cca/mixin/level/common/MixinUnmodifiableLevelProperties.java @@ -40,6 +40,6 @@ public abstract class MixinUnmodifiableLevelProperties implements ComponentProvi @Nonnull @Override public ComponentContainer getComponentContainer() { - return this.worldProperties.getComponentContainer(); + return this.worldProperties.asComponentProvider().getComponentContainer(); } } diff --git a/cardinal-components-level/src/main/resources/fabric.mod.json b/cardinal-components-level/src/main/resources/fabric.mod.json index 7c897c46..506cc575 100644 --- a/cardinal-components-level/src/main/resources/fabric.mod.json +++ b/cardinal-components-level/src/main/resources/fabric.mod.json @@ -26,7 +26,7 @@ }, "loom:injected_interfaces": { "net/minecraft/class_5217": [ - "dev/onyxstudios/cca/api/v3/component/ComponentProvider" + "dev/onyxstudios/cca/api/v3/component/ComponentAccess" ] } }, diff --git a/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/internal/scoreboard/ComponentsScoreboardNetworking.java b/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/internal/scoreboard/ComponentsScoreboardNetworking.java index 7b7b6cbf..8b0f9e30 100644 --- a/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/internal/scoreboard/ComponentsScoreboardNetworking.java +++ b/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/internal/scoreboard/ComponentsScoreboardNetworking.java @@ -56,19 +56,19 @@ public final class ComponentsScoreboardNetworking { public static void init() { if (FabricLoader.getInstance().isModLoaded("fabric-networking-api-v1")) { ScoreboardSyncCallback.EVENT.register((player, tracked) -> { - for (ComponentKey key : tracked.getComponentContainer().keys()) { - key.syncWith(player, tracked); + for (ComponentKey key : tracked.asComponentProvider().getComponentContainer().keys()) { + key.syncWith(player, tracked.asComponentProvider()); } for (Team team : tracked.getTeams()) { - for (ComponentKey key : team.getComponentContainer().keys()) { - key.syncWith(player, team); + for (ComponentKey key : team.asComponentProvider().getComponentContainer().keys()) { + key.syncWith(player, team.asComponentProvider()); } } }); TeamAddCallback.EVENT.register((tracked) -> { - for (ComponentKey key : tracked.getComponentContainer().keys()) { - key.sync(tracked); + for (ComponentKey key : tracked.asComponentProvider().getComponentContainer().keys()) { + tracked.syncComponent(key); } }); } diff --git a/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinMinecraftServer.java b/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinMinecraftServer.java index fd570727..e77ee7d6 100644 --- a/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinMinecraftServer.java +++ b/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinMinecraftServer.java @@ -40,10 +40,10 @@ public abstract class MixinMinecraftServer { @Inject(at = @At("TAIL"), method = "tick") private void onEndTick(BooleanSupplier shouldKeepTicking, CallbackInfo info) { ServerScoreboard scoreboard = this.getScoreboard(); - scoreboard.getComponentContainer().tickServerComponents(); + scoreboard.asComponentProvider().getComponentContainer().tickServerComponents(); for (Team team : scoreboard.getTeams()) { - team.getComponentContainer().tickServerComponents(); + team.asComponentProvider().getComponentContainer().tickServerComponents(); } } } diff --git a/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinServerScoreboard.java b/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinServerScoreboard.java index 220da2b8..f9bca0f8 100644 --- a/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinServerScoreboard.java +++ b/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinServerScoreboard.java @@ -46,8 +46,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import javax.annotation.Nullable; -import java.util.Collections; -import java.util.Iterator; +import java.util.List; import java.util.function.Supplier; @Mixin(ServerScoreboard.class) @@ -60,13 +59,13 @@ public abstract class MixinServerScoreboard extends MixinScoreboard { private MinecraftServer server; @Override - public Iterator getRecipientsForComponentSync() { + public Iterable getRecipientsForComponentSync() { MinecraftServer server = this.server; if (server.getPlayerManager() != null) { - return server.getPlayerManager().getPlayerList().iterator(); + return server.getPlayerManager().getPlayerList(); } - return Collections.emptyIterator(); + return List.of(); } @Nullable diff --git a/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinTeam.java b/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinTeam.java index b2d65686..b93a60d5 100644 --- a/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinTeam.java +++ b/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinTeam.java @@ -45,7 +45,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Iterator; @Mixin(Team.class) public abstract class MixinTeam implements ComponentProvider, TeamAccessor { @@ -74,8 +73,8 @@ public ComponentContainer getComponentContainer() { } @Override - public Iterator getRecipientsForComponentSync() { - return ((ComponentProvider) this.scoreboard).getRecipientsForComponentSync(); + public Iterable getRecipientsForComponentSync() { + return this.scoreboard.asComponentProvider().getRecipientsForComponentSync(); } @Nullable diff --git a/cardinal-components-scoreboard/src/main/resources/fabric.mod.json b/cardinal-components-scoreboard/src/main/resources/fabric.mod.json index 53bac4e6..cf325fce 100644 --- a/cardinal-components-scoreboard/src/main/resources/fabric.mod.json +++ b/cardinal-components-scoreboard/src/main/resources/fabric.mod.json @@ -26,10 +26,10 @@ }, "loom:injected_interfaces": { "net/minecraft/class_269": [ - "dev/onyxstudios/cca/api/v3/component/ComponentProvider" + "dev/onyxstudios/cca/api/v3/component/ComponentAccess" ], "net/minecraft/class_268": [ - "dev/onyxstudios/cca/api/v3/component/ComponentProvider" + "dev/onyxstudios/cca/api/v3/component/ComponentAccess" ] } }, diff --git a/cardinal-components-world/src/main/java/dev/onyxstudios/cca/mixin/world/common/MixinServerWorld.java b/cardinal-components-world/src/main/java/dev/onyxstudios/cca/mixin/world/common/MixinServerWorld.java index 6124096e..808522ca 100644 --- a/cardinal-components-world/src/main/java/dev/onyxstudios/cca/mixin/world/common/MixinServerWorld.java +++ b/cardinal-components-world/src/main/java/dev/onyxstudios/cca/mixin/world/common/MixinServerWorld.java @@ -41,7 +41,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import javax.annotation.Nullable; -import java.util.Iterator; import java.util.List; import java.util.function.BooleanSupplier; @@ -70,8 +69,8 @@ private void tick(BooleanSupplier shouldKeepTicking, CallbackInfo ci) { } @Override - public Iterator getRecipientsForComponentSync() { - return this.getPlayers().iterator(); + public Iterable getRecipientsForComponentSync() { + return this.getPlayers(); } @Nullable diff --git a/cardinal-components-world/src/main/resources/fabric.mod.json b/cardinal-components-world/src/main/resources/fabric.mod.json index 5101c50d..b51f296f 100644 --- a/cardinal-components-world/src/main/resources/fabric.mod.json +++ b/cardinal-components-world/src/main/resources/fabric.mod.json @@ -26,7 +26,7 @@ }, "loom:injected_interfaces": { "net/minecraft/class_1937": [ - "dev/onyxstudios/cca/api/v3/component/ComponentProvider" + "dev/onyxstudios/cca/api/v3/component/ComponentAccess" ] } }, diff --git a/cardinal-components-world/src/testmod/java/dev/onyxstudios/cca/test/world/AmbientVita.java b/cardinal-components-world/src/testmod/java/dev/onyxstudios/cca/test/world/AmbientVita.java index f63aeb32..bb6f3dbc 100644 --- a/cardinal-components-world/src/testmod/java/dev/onyxstudios/cca/test/world/AmbientVita.java +++ b/cardinal-components-world/src/testmod/java/dev/onyxstudios/cca/test/world/AmbientVita.java @@ -32,9 +32,7 @@ import net.minecraft.network.PacketByteBuf; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.LiteralText; import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; import net.minecraft.world.World; import java.util.Objects; @@ -49,10 +47,10 @@ public void applySyncPacket(PacketByteBuf buf) { this.setVitality(vita); World world = Objects.requireNonNull(MinecraftClient.getInstance().player).world; // Very bad shortcut to get a dimension's name - Text worldName = new LiteralText( + Text worldName = Text.literal( Objects.requireNonNull(world.getRegistryKey() == World.OVERWORLD ? "Overworld" : "Alien World") ); - Text worldVita = new TranslatableText( + Text worldVita = Text.translatable( "componenttest:title.world_vitality", Vita.get(world).getVitality(), Vita.get(world.getLevelProperties()).getVitality() @@ -80,7 +78,7 @@ public WorldVita(World world) { @Override public void syncWithAll(MinecraftServer server) { - Vita.KEY.sync(this.world); + this.world.syncComponent(KEY); } @Override diff --git a/changelog.md b/changelog.md index 07314b4a..f6028efc 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,13 @@ +------------------------------------------------------ +Version 5.0.0 +------------------------------------------------------ +Updated to MC 1.19 + +**Additions** +- Component providers now expose the `ComponentAccess` interface through Loom's interface injection + - `ComponentAccess` adds `getComponent` as an alternative to `ComponentKey#get`, and `syncComponent` as an alternative to `ComponentKey#sync` + - It is now recommended to use e.g. `entity.getComponent(KEY)` instead of `KEY.get(entity)`, as this enforces type checking + ------------------------------------------------------ Version 4.1.3 ------------------------------------------------------ diff --git a/gradle.properties b/gradle.properties index bf1e9508..c8f1018c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,21 +2,20 @@ org.gradle.jvmargs = -Xmx3G #see https://modmuss50.me/fabric.html -minecraft_version=1.18.1 -yarn_mappings=22 -loader_version=0.12.12 - +minecraft_version=1.19-pre1 +yarn_mappings=1 +loader_version=0.14.5 #Fabric api -fabric_api_version=0.46.2+1.18 +fabric_api_version=0.52.4+1.19 -elmendorf_version=0.4.0 +elmendorf_version=0.6.0 #Publishing -mod_version = 4.1.3 +mod_version = 5.0.0-beta.1 curseforge_id = 318449 modrinth_id = K01OU20C -curseforge_versions = 1.18-Snapshot; 1.18; 1.18.1 -modrinth_versions = 1.18; 1.18.1 +curseforge_versions = 1.19-Snapshot +modrinth_versions = 1.19 changelog_url = https://github.com/OnyxStudios/Cardinal-Components-API/blob release_type = release display_name = Cardinal-Components-API diff --git a/src/testmod/java/dev/onyxstudios/componenttest/content/CCATestClient.java b/src/testmod/java/dev/onyxstudios/componenttest/content/CCATestClient.java index 1ce16004..7a40ee25 100644 --- a/src/testmod/java/dev/onyxstudios/componenttest/content/CCATestClient.java +++ b/src/testmod/java/dev/onyxstudios/componenttest/content/CCATestClient.java @@ -25,13 +25,13 @@ import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback; import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; import net.minecraft.client.render.entity.ZombieEntityRenderer; -import net.minecraft.text.TranslatableText; +import net.minecraft.text.Text; public final class CCATestClient { public static void clientInit() { EntityRendererRegistry.register(CardinalComponentsTest.VITALITY_ZOMBIE, ZombieEntityRenderer::new); ItemTooltipCallback.EVENT.register((stack, tooltipContext, lines) -> - TestComponents.ALT_VITA.maybeGet(stack).ifPresent(vita -> lines.add(new TranslatableText("componenttest:tooltip.vitality.native", vita.getVitality()))) + TestComponents.ALT_VITA.maybeGet(stack).ifPresent(vita -> lines.add(Text.translatable("componenttest:tooltip.vitality.native", vita.getVitality()))) ); } } diff --git a/src/testmod/java/dev/onyxstudios/componenttest/content/CardinalComponentsTest.java b/src/testmod/java/dev/onyxstudios/componenttest/content/CardinalComponentsTest.java index dd4f4f1b..480b290f 100644 --- a/src/testmod/java/dev/onyxstudios/componenttest/content/CardinalComponentsTest.java +++ b/src/testmod/java/dev/onyxstudios/componenttest/content/CardinalComponentsTest.java @@ -31,7 +31,6 @@ import dev.onyxstudios.cca.test.base.Vita; import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder; import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; -import net.fabricmc.fabric.api.event.player.UseItemCallback; import net.fabricmc.fabric.api.lookup.v1.block.BlockApiLookup; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry; @@ -47,7 +46,6 @@ import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; -import net.minecraft.util.TypedActionResult; import net.minecraft.util.math.Direction; import net.minecraft.util.registry.Registry; import net.minecraft.world.chunk.ChunkStatus; @@ -72,7 +70,7 @@ public class CardinalComponentsTest { public static final VitalityStickItem VITALITY_STICK = Registry.register(Registry.ITEM, VITA_STICK_ID, new VitalityStickItem(new Item.Settings().group(ITEM_GROUP).maxDamage(50))); - public static final VitalityCondenser VITALITY_CONDENSER = new VitalityCondenser(FabricBlockSettings.of(Material.STONE).dropsNothing().luminance(5).ticksRandomly()); + public static final VitalityCondenser VITALITY_CONDENSER = new VitalityCondenser(FabricBlockSettings.of(Material.STONE).dropsNothing().luminance(s -> 5).ticksRandomly()); public static final EntityType VITALITY_ZOMBIE = Registry.register(Registry.ENTITY_TYPE, "componenttest:vita_zombie", FabricEntityTypeBuilder.create(SpawnGroup.MONSTER, VitalityZombieEntity::new).dimensions(EntityType.ZOMBIE.getDimensions()).build()); @@ -123,12 +121,6 @@ public static void init() { assert false : "Only one factory should be created for any given provider type"; } catch (IllegalStateException ignored) { } - UseItemCallback.EVENT.register((playerEntity, world, hand) -> { - ItemStack stack = playerEntity.getStackInHand(hand); - LOGGER.info("{} vitality: {}", stack, TestComponents.ALT_VITA.get(stack).getVitality()); // init components - return TypedActionResult.pass(stack); - }); - VITA_API_LOOKUP.registerForBlocks( (world, pos, state, blockEntity, context) -> Vita.KEY.get(Objects.requireNonNull(world.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.FULL, false))), VITALITY_CONDENSER diff --git a/src/testmod/java/dev/onyxstudios/componenttest/content/VitaCommand.java b/src/testmod/java/dev/onyxstudios/componenttest/content/VitaCommand.java index 64a589a5..34900992 100644 --- a/src/testmod/java/dev/onyxstudios/componenttest/content/VitaCommand.java +++ b/src/testmod/java/dev/onyxstudios/componenttest/content/VitaCommand.java @@ -45,7 +45,7 @@ public static void register(CommandDispatcher dispatcher) { .executes(context -> { Chunk chunk = context.getSource().getWorld().getChunk(BlockPosArgumentType.getBlockPos(context, "pos")); Vita.get(chunk).setVitality(IntegerArgumentType.getInteger(context, "amount")); - chunk.setShouldSave(true); + chunk.setNeedsSaving(true); context.getSource().sendFeedback(Text.of("success!"), false); return 1; }) diff --git a/src/testmod/java/dev/onyxstudios/componenttest/content/VitalityCondenser.java b/src/testmod/java/dev/onyxstudios/componenttest/content/VitalityCondenser.java index 9c7ed360..b8d6f218 100644 --- a/src/testmod/java/dev/onyxstudios/componenttest/content/VitalityCondenser.java +++ b/src/testmod/java/dev/onyxstudios/componenttest/content/VitalityCondenser.java @@ -27,16 +27,16 @@ import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.TranslatableText; +import net.minecraft.text.Text; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.random.AbstractRandom; import net.minecraft.world.World; import org.jetbrains.annotations.ApiStatus; import java.util.Objects; -import java.util.Random; public class VitalityCondenser extends Block { public VitalityCondenser(Settings settings) { @@ -46,7 +46,7 @@ public VitalityCondenser(Settings settings) { @SuppressWarnings("deprecation") @ApiStatus.OverrideOnly @Override - public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random rand) { + public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, AbstractRandom rand) { Vita.get(world).transferTo(Vita.get(world.getChunk(pos)), 1); } @@ -56,7 +56,7 @@ public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Ran public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hitInfo) { // only on client side, to confirm that sync works if (world.isClient) { - player.sendMessage(new TranslatableText("componenttest:action.chunk_vitality", + player.sendMessage(Text.translatable("componenttest:action.chunk_vitality", Objects.requireNonNull(CardinalComponentsTest.VITA_API_LOOKUP.find(world, pos, state, null, hitInfo.getSide())).getVitality()), true); } return ActionResult.SUCCESS; diff --git a/src/testmod/java/dev/onyxstudios/componenttest/content/VitalityStickItem.java b/src/testmod/java/dev/onyxstudios/componenttest/content/VitalityStickItem.java index 4320ee4a..8591cc27 100644 --- a/src/testmod/java/dev/onyxstudios/componenttest/content/VitalityStickItem.java +++ b/src/testmod/java/dev/onyxstudios/componenttest/content/VitalityStickItem.java @@ -22,8 +22,8 @@ */ package dev.onyxstudios.componenttest.content; -import dev.onyxstudios.componenttest.content.vita.AmbientVita; import dev.onyxstudios.cca.test.base.Vita; +import dev.onyxstudios.cca.test.world.AmbientVita; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.block.BlockState; @@ -38,7 +38,6 @@ import net.minecraft.scoreboard.AbstractTeam; import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; @@ -85,7 +84,7 @@ public ActionResult useOnBlock(ItemUsageContext context) { context.getSide() ); if (vita != null) { - context.getPlayer().sendMessage(new TranslatableText("componenttest:action.block_vitality", + context.getPlayer().sendMessage(Text.translatable("componenttest:action.block_vitality", vita.getVitality()), true); } } @@ -115,10 +114,10 @@ public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity holder @Override public void appendTooltip(ItemStack stack, @Nullable World world, List lines, TooltipContext ctx) { super.appendTooltip(stack, world, lines, ctx); - lines.add(new TranslatableText("componenttest:tooltip.vitality", Vita.KEY.get(stack).getVitality())); + lines.add(Text.translatable("componenttest:tooltip.vitality", Vita.KEY.get(stack).getVitality())); PlayerEntity holder = MinecraftClient.getInstance().player; if (holder != null) { - lines.add(new TranslatableText("componenttest:tooltip.self_vitality", Vita.KEY.get(holder).getVitality())); + lines.add(Text.translatable("componenttest:tooltip.self_vitality", holder.getComponent(Vita.KEY).getVitality())); } } diff --git a/src/testmod/java/dev/onyxstudios/componenttest/content/vita/AmbientVita.java b/src/testmod/java/dev/onyxstudios/componenttest/content/vita/AmbientVita.java deleted file mode 100644 index 86f19cf8..00000000 --- a/src/testmod/java/dev/onyxstudios/componenttest/content/vita/AmbientVita.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Cardinal-Components-API - * Copyright (C) 2019-2022 OnyxStudios - * - * 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 dev.onyxstudios.componenttest.content.vita; - -import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent; -import dev.onyxstudios.cca.api.v3.component.tick.ClientTickingComponent; -import dev.onyxstudios.cca.test.base.BaseVita; -import dev.onyxstudios.cca.test.base.Vita; -import dev.onyxstudios.componenttest.content.CardinalComponentsTest; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.hud.InGameHud; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; -import net.minecraft.world.World; - -import java.util.Objects; - -public abstract class AmbientVita extends BaseVita implements AutoSyncedComponent { - - public abstract void syncWithAll(MinecraftServer server); - - @Override - public void applySyncPacket(PacketByteBuf buf) { - int vita = buf.readInt(); - this.setVitality(vita); - World world = Objects.requireNonNull(MinecraftClient.getInstance().player).world; - // Very bad shortcut to get a dimension's name - Text worldName = new LiteralText( - Objects.requireNonNull(world.getRegistryKey() == World.OVERWORLD ? "Overworld" : "Alien World") - ); - Text worldVita = new TranslatableText( - "componenttest:title.world_vitality", - Vita.get(world).getVitality(), - Vita.get(world.getLevelProperties()).getVitality() - ); - InGameHud inGameHud = MinecraftClient.getInstance().inGameHud; - inGameHud.setTitleTicks(-1, -1, -1); - inGameHud.setTitle(worldName); - inGameHud.setSubtitle(worldVita); - } - - /** - * proper implementation of {@code writeToPacket}, writes a single int instead of a whole tag - */ - @Override - public void writeSyncPacket(PacketByteBuf buf, ServerPlayerEntity player) { - buf.writeInt(this.getVitality()); - } - - public static class WorldVita extends AmbientVita implements ClientTickingComponent { - private final World world; - - public WorldVita(World world) { - this.world = world; - } - - @Override - public void syncWithAll(MinecraftServer server) { - Vita.KEY.sync(this.world); - } - - @Override - public void clientTick() { - if (this.world.getTime() % 2400 == 0) { - CardinalComponentsTest.LOGGER.info("The world still runs, and is now worth {}", this.vitality); - } - } - } - -} diff --git a/src/testmod/java/dev/onyxstudios/componenttest/tests/CcaTestSuite.java b/src/testmod/java/dev/onyxstudios/componenttest/tests/CcaTestSuite.java index edd708ec..136e42a1 100644 --- a/src/testmod/java/dev/onyxstudios/componenttest/tests/CcaTestSuite.java +++ b/src/testmod/java/dev/onyxstudios/componenttest/tests/CcaTestSuite.java @@ -22,7 +22,7 @@ */ package dev.onyxstudios.componenttest.tests; -import dev.onyxstudios.cca.api.v3.component.ComponentProvider; +import dev.onyxstudios.cca.api.v3.component.ComponentAccess; import io.github.ladysnake.elmendorf.GameTestUtil; import net.fabricmc.fabric.api.gametest.v1.FabricGameTest; import net.minecraft.block.Blocks; @@ -52,8 +52,8 @@ public void interfacesGetInjected(TestContext context) { context.complete(); } - private void checkContainer(ComponentProvider provider) { + private void checkContainer(ComponentAccess provider) { //noinspection ConstantConditions - GameTestUtil.assertTrue(provider + " should correctly implement ComponentProvider", provider.getComponentContainer() != null); + GameTestUtil.assertTrue(provider + " should correctly implement ComponentProvider", provider.asComponentProvider().getComponentContainer() != null); } }