From 5e0d2ae9bc725973c449faa47ebfda084151598e Mon Sep 17 00:00:00 2001 From: Pyrofab Date: Mon, 15 Nov 2021 15:27:47 +0100 Subject: [PATCH] Update to 1.18-pre1 --- README.md | 24 ++++++++---- .../cca/api/v3/component/ComponentKey.java | 38 +++++++++---------- .../base/asm/StaticComponentPluginBase.java | 13 ------- .../block/common/MixinServerPlayerEntity.java | 8 ++-- .../cca/mixin/chunk/common/MixinChunk.java | 6 +-- .../mixin/chunk/common/MixinWorldChunk.java | 12 ++---- changelog.md | 5 +-- gradle.properties | 10 ++--- 8 files changed, 51 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index 41e8fd04..b5357388 100644 --- a/README.md +++ b/README.md @@ -35,9 +35,13 @@ repositories { } dependencies { + // Adds a dependency on the base cardinal components module (required by every other module) // Replace modImplementation with modApi if you expose components in your own API + modImplementation "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-base:" + // Adds a dependency on a specific module modImplementation "io.github.onyxstudios.Cardinal-Components-API::" // Includes Cardinal Components API as a Jar-in-Jar dependency (optional) + include "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-base:" include "io.github.onyxstudios.Cardinal-Components-API::" } ``` @@ -59,7 +63,10 @@ modImplementation "io.github.onyxstudios.Cardinal-Components-API:cardinal-compon ## Basic Usage -To get started, you only need a class implementing `Component`. It is recommended to have it split into an interface and an implementation, so that internals get properly encapsulated and so that the component itself can be used as an API by other mods. +To get started, you only need a class implementing `Component`. +It is recommended to have it split into an interface and an implementation, +so that internals get properly encapsulated and so that the component itself can be used +as an API by other mods. **Minimal code example:** ```java @@ -76,7 +83,9 @@ class RandomIntComponent implements IntComponent { ``` *Note: a component class can be reused for several component types* -If you want your component to be **automatically synchronized with watching clients**, you can also add the [`AutoSyncedComponent`](https://github.com/OnyxStudios/Cardinal-Components-API/blob/master/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/AutoSyncedComponent.java) interface to your implementation: +If you want your component to be **automatically synchronized with watching clients**, +you can also add the [`AutoSyncedComponent`](https://github.com/OnyxStudios/Cardinal-Components-API/blob/master/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/AutoSyncedComponent.java) +interface to your implementation: ```java class SyncedIntComponent implements IntComponent, AutoSyncedComponent { @@ -125,7 +134,11 @@ The next step is to choose an identifier for your component, and to declare it i ``` Components can be provided by objects of various classes, depending on which modules you installed. -The most common providers are [entities](https://github.com/OnyxStudios/Cardinal-Components-API/wiki/Cardinal-Components-Entity), [item stacks](https://github.com/OnyxStudios/Cardinal-Components-API/wiki/Cardinal-Components-Item), [worlds](https://github.com/OnyxStudios/Cardinal-Components-API/wiki/Cardinal-Components-World) and [chunks](https://github.com/OnyxStudios/Cardinal-Components-API/wiki/Cardinal-Components-Chunk), but more are available. +The most common providers are [entities](https://github.com/OnyxStudios/Cardinal-Components-API/wiki/Cardinal-Components-Entity), +[item stacks](https://github.com/OnyxStudios/Cardinal-Components-API/wiki/Cardinal-Components-Item), +[worlds](https://github.com/OnyxStudios/Cardinal-Components-API/wiki/Cardinal-Components-World) +and [chunks](https://github.com/OnyxStudios/Cardinal-Components-API/wiki/Cardinal-Components-Chunk), +but more are available. To interact with them, you need to **register a component key**, using `ComponentRegistryV3#getOrCreate`; the resulting `ComponentKey` instance has the query methods you need. You will also need to **attach your component** to some providers (here, to players and worlds): @@ -153,10 +166,7 @@ Do not forget to declare your component initializer as an entrypoint in your `fa ```json { "entrypoints": { - "cardinal-components-entity": [ - "a.b.c.MyComponents" - ], - "cardinal-components-world": [ + "cardinal-components": [ "a.b.c.MyComponents" ] }, 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 ec46605d..69644397 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 @@ -67,20 +67,23 @@ public final Class getComponentClass() { */ @Contract(pure = true) public @Nullable C getNullable(V provider) { - return this.getInternal((ComponentProvider) provider); + return this.getInternal(((ComponentProvider) provider).getComponentContainer()); } /** * @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) */ public final C get(V provider) { - C component = this.getInternal((ComponentProvider) provider); + C component = this.getInternal(((ComponentProvider) provider).getComponentContainer()); + assert component == null || this.getComponentClass().isInstance(component); + if (component == null) { try { throw new NoSuchElementException(provider + " provides no component of type " + this.getId()); @@ -101,8 +104,8 @@ public final C get(V provider) { * @see #get(Object) */ public final Optional maybeGet(@Nullable V provider) { - if (provider instanceof ComponentProvider) { - return Optional.ofNullable(this.getInternal((ComponentProvider) provider)); + if (provider instanceof ComponentProvider p) { + return Optional.ofNullable(this.getInternal(p.getComponentContainer())); } return Optional.empty(); } @@ -185,6 +188,17 @@ public void syncWith(ServerPlayerEntity player, ComponentProvider provider) { } } + @ApiStatus.Experimental + public void syncWith(ServerPlayerEntity player, ComponentProvider provider, ComponentPacketWriter writer, PlayerSyncPredicate predicate) { + if (predicate.shouldSyncWith(player)) { + Packet packet = provider.toComponentPacket(this, writer, player); + + if (packet != null) { + player.networkHandler.sendPacket(packet); + } + } + } + @Override public final String toString() { return this.getClass().getSimpleName() + "[\"" + this.id + "\"]"; @@ -220,24 +234,8 @@ protected ComponentKey(Identifier id, Class componentClass) { @ApiStatus.Internal public abstract @Nullable C getInternal(ComponentContainer container); - private @Nullable C getInternal(ComponentProvider provider) { - return this.getInternal(provider.getComponentContainer()); - } - @ApiStatus.Internal public C getFromContainer(ComponentContainer container) { return Objects.requireNonNull(this.getInternal(container)); } - - - @ApiStatus.Internal - public void syncWith(ServerPlayerEntity player, ComponentProvider provider, ComponentPacketWriter writer, PlayerSyncPredicate predicate) { - if (predicate.shouldSyncWith(player)) { - Packet packet = provider.toComponentPacket(this, writer, player); - - if (packet != null) { - player.networkHandler.sendPacket(packet); - } - } - } } diff --git a/cardinal-components-base/src/main/java/dev/onyxstudios/cca/internal/base/asm/StaticComponentPluginBase.java b/cardinal-components-base/src/main/java/dev/onyxstudios/cca/internal/base/asm/StaticComponentPluginBase.java index f2facd61..9c28e02c 100644 --- a/cardinal-components-base/src/main/java/dev/onyxstudios/cca/internal/base/asm/StaticComponentPluginBase.java +++ b/cardinal-components-base/src/main/java/dev/onyxstudios/cca/internal/base/asm/StaticComponentPluginBase.java @@ -55,19 +55,6 @@ protected StaticComponentPluginBase(String likelyInitTrigger, Class providerC this.containerFactoryBuilder = ComponentContainer.Factory.builder(providerClass); } - /** - * Defines an implementation of {@code I} which creates component containers of - * the given implementation type, using an argument of the given {@code factoryArg} type. - * - *

The generated class has a single constructor, taking {@code eventCount} parameters of type {@link Event}. - * @param implNameSuffix a unique suffix for the generated class - * @param containerFactoryType the factory interface that is to be implemented by the returned class - * @param containerImpl the type of containers that is to be instantiated by the generated factory - */ - public static Class spinContainerFactory(String implNameSuffix, Class containerFactoryType, Class containerImpl, Class... actualFactoryParams) throws IOException { - return spinContainerFactory(implNameSuffix, containerFactoryType, containerImpl, List.of(actualFactoryParams)); - } - /** * Defines an implementation of {@code I} which creates component containers of * the given implementation type, using an argument of the given {@code factoryArg} type. diff --git a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinServerPlayerEntity.java b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinServerPlayerEntity.java index 0f020e26..7a1c6140 100644 --- a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinServerPlayerEntity.java +++ b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinServerPlayerEntity.java @@ -23,7 +23,7 @@ package dev.onyxstudios.cca.mixin.block.common; import dev.onyxstudios.cca.api.v3.block.BlockEntitySyncCallback; -import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.CommandBlockBlockEntity; import net.minecraft.server.network.ServerPlayerEntity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -32,8 +32,8 @@ @Mixin(ServerPlayerEntity.class) public abstract class MixinServerPlayerEntity { - @Inject(method = "sendBlockEntityUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/BlockEntity;toUpdatePacket()Lnet/minecraft/network/Packet;")) - private void syncBlockEntity(BlockEntity blockEntity, CallbackInfo ci) { - BlockEntitySyncCallback.EVENT.invoker().onBlockEntitySync((ServerPlayerEntity)(Object) this, blockEntity); + @Inject(method = "openCommandBlockScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/BlockEntityUpdateS2CPacket;create(Lnet/minecraft/block/entity/BlockEntity;Ljava/util/function/Function;)Lnet/minecraft/network/packet/s2c/play/BlockEntityUpdateS2CPacket;")) + private void syncBlockEntity(CommandBlockBlockEntity commandBlock, CallbackInfo ci) { + BlockEntitySyncCallback.EVENT.invoker().onBlockEntitySync((ServerPlayerEntity)(Object) this, commandBlock); } } diff --git a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinChunk.java b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinChunk.java index 33479b26..6814783f 100644 --- a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinChunk.java +++ b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinChunk.java @@ -25,16 +25,14 @@ import dev.onyxstudios.cca.api.v3.component.ComponentContainer; import dev.onyxstudios.cca.api.v3.component.ComponentProvider; import dev.onyxstudios.cca.internal.chunk.StaticChunkComponentPlugin; -import net.minecraft.block.Block; -import net.minecraft.fluid.Fluid; import net.minecraft.util.math.ChunkPos; import net.minecraft.util.registry.Registry; import net.minecraft.world.HeightLimitView; -import net.minecraft.world.TickScheduler; import net.minecraft.world.biome.Biome; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.ChunkSection; import net.minecraft.world.chunk.UpgradeData; +import net.minecraft.world.gen.chunk.Blender; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -47,7 +45,7 @@ public class MixinChunk implements ComponentProvider { private ComponentContainer components; @Inject(method = "", at = @At("RETURN")) - private void initComponents(ChunkPos $$0, UpgradeData $$1, HeightLimitView $$2, Registry $$3, long $$4, ChunkSection[] $$5, TickScheduler $$6, TickScheduler $$7, CallbackInfo ci) { + private void initComponents(ChunkPos pos, UpgradeData upgradeData, HeightLimitView heightLimitView, Registry biome, long inhabitedTime, ChunkSection[] sectionArrayInitializer, Blender blendingData, CallbackInfo ci) { this.components = StaticChunkComponentPlugin.createContainer((Chunk) (Object) this); } 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 1c6f13d8..3750ee72 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 @@ -22,17 +22,13 @@ */ package dev.onyxstudios.cca.mixin.chunk.common; -import dev.onyxstudios.cca.api.v3.component.ComponentContainer; import dev.onyxstudios.cca.api.v3.component.ComponentKey; import dev.onyxstudios.cca.api.v3.component.ComponentProvider; import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent; import dev.onyxstudios.cca.api.v3.component.sync.ComponentPacketWriter; import dev.onyxstudios.cca.internal.chunk.ComponentsChunkNetworking; -import dev.onyxstudios.cca.internal.chunk.StaticChunkComponentPlugin; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.api.networking.v1.PlayerLookup; -import net.minecraft.block.Block; -import net.minecraft.fluid.Fluid; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; @@ -40,7 +36,6 @@ import net.minecraft.util.math.ChunkPos; import net.minecraft.util.registry.Registry; import net.minecraft.world.HeightLimitView; -import net.minecraft.world.TickScheduler; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; import net.minecraft.world.chunk.Chunk; @@ -48,23 +43,22 @@ import net.minecraft.world.chunk.ProtoChunk; import net.minecraft.world.chunk.UpgradeData; import net.minecraft.world.chunk.WorldChunk; +import net.minecraft.world.gen.chunk.Blender; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import javax.annotation.Nonnull; import java.util.Collections; import java.util.Iterator; import java.util.function.Consumer; @Mixin(WorldChunk.class) public abstract class MixinWorldChunk extends Chunk implements ComponentProvider { - public MixinWorldChunk(ChunkPos $$0, UpgradeData $$1, HeightLimitView $$2, Registry $$3, long $$4, @Nullable ChunkSection[] $$5, TickScheduler $$6, TickScheduler $$7) { - super($$0, $$1, $$2, $$3, $$4, $$5, $$6, $$7); + public MixinWorldChunk(ChunkPos pos, UpgradeData upgradeData, HeightLimitView heightLimitView, Registry biome, long inhabitedTime, @Nullable ChunkSection[] sectionArrayInitializer, @Nullable Blender blendingData) { + super(pos, upgradeData, heightLimitView, biome, inhabitedTime, sectionArrayInitializer, blendingData); } @Shadow diff --git a/changelog.md b/changelog.md index 5dd0d039..e3bd47cd 100644 --- a/changelog.md +++ b/changelog.md @@ -1,8 +1,7 @@ ------------------------------------------------------ Version 4.0.0 ------------------------------------------------------ -### Alpha 1 -Updated to 21w37a +Updated to 1.18 **Removed** @@ -10,7 +9,7 @@ Updated to 21w37a - Item components must now save all their data in the stack NBT - Consider switching to API Lookup API where possible - Removed the `cardinal-components-util` module - - According to Github no one ever used it, but if you did and you see no currently available alternative, please open an issue + - According to Github no one ever used it, but if you did, and you see no currently available alternative, please open an issue ------------------------------------------------------ Version 3.1.1 diff --git a/gradle.properties b/gradle.properties index 31fb8bdf..484768cc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,15 +2,15 @@ org.gradle.jvmargs = -Xmx3G #see https://modmuss50.me/fabric.html -minecraft_version=21w37a -yarn_mappings=13 -loader_version=0.11.7 +minecraft_version=1.18-pre1 +yarn_mappings=8 +loader_version=0.12.5 #Fabric api -fabric_api_version=0.40.3+1.18 +fabric_api_version=0.42.2+1.18 #Publishing -mod_version = 4.0.0-alpha.1+21w37a +mod_version = 4.0.0 curseforge_id = 318449 curseforge_versions = 1.18-Snapshot changelog_url = https://github.com/OnyxStudios/Cardinal-Components-API/blob