Skip to content

Commit

Permalink
Prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jun 15, 2021
1 parent 0002950 commit cf1795d
Show file tree
Hide file tree
Showing 32 changed files with 96 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ interface Factory<T> {
*
* @return a new container factory builder
*/
@ApiStatus.Experimental
@Contract(value = "-> new", pure = true)
static Builder<@Nullable Void> builder() {
return new Builder<>(Void.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
import dev.onyxstudios.cca.api.v3.component.sync.ComponentPacketWriter;
import dev.onyxstudios.cca.api.v3.component.sync.PlayerSyncPredicate;
import dev.onyxstudios.cca.internal.base.asm.CcaBootstrap;
import io.netty.buffer.Unpooled;
import net.minecraft.network.Packet;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.ApiStatus;
Expand Down Expand Up @@ -126,9 +124,7 @@ public <V> boolean isProvidedBy(V provider) {
* @throws ClassCastException if <code>provider</code> does not implement {@link ComponentProvider}
*/
public <V> void sync(V provider) {
C c = this.get(provider);
if (c instanceof AutoSyncedComponent) {
AutoSyncedComponent synced = (AutoSyncedComponent) c;
if (this.get(provider) instanceof AutoSyncedComponent synced) {
this.sync(provider, synced, synced);
}
}
Expand Down Expand Up @@ -185,9 +181,7 @@ public <V> void sync(V provider, ComponentPacketWriter packetWriter, PlayerSyncP
*/
@ApiStatus.Experimental
public void syncWith(ServerPlayerEntity player, ComponentProvider provider) {
C c = this.get(provider);
if (c instanceof AutoSyncedComponent) {
AutoSyncedComponent synced = (AutoSyncedComponent) c;
if (this.get(provider) instanceof AutoSyncedComponent synced) {
this.syncWith(player, provider, synced, synced);
}
}
Expand Down Expand Up @@ -240,8 +234,7 @@ public C getFromContainer(ComponentContainer container) {
@ApiStatus.Internal
public void syncWith(ServerPlayerEntity player, ComponentProvider provider, ComponentPacketWriter writer, PlayerSyncPredicate predicate) {
if (predicate.shouldSyncWith(player)) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
Packet<?> packet = provider.toComponentPacket(buf, this, writer, player);
Packet<?> packet = provider.toComponentPacket(this, writer, player);

if (packet != null) {
player.networkHandler.sendPacket(packet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

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;
Expand All @@ -37,7 +39,6 @@
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;
Expand Down Expand Up @@ -116,15 +117,44 @@ static ComponentProvider fromWorld(World world) {
/**
* @return a runtime-generated component container storing statically declared components.
*/
@ApiStatus.Experimental
ComponentContainer getComponentContainer();

/**
* Retrieves an iterator describing the list of players who may receive
* component sync packets from this provider.
*
* <p>Individual components can {@linkplain PlayerSyncPredicate#shouldSyncWith(ServerPlayerEntity) filter
* which players among the returned list should receive their packets};
* this method does <em>not</em> take current components into account, so callers should perform
* additional checks as needed.
*
* @return a list of player candidates for receiving component sync packets
*/
default Iterator<ServerPlayerEntity> getRecipientsForComponentSync() {
// TODO 4.0.0 replace with Iterable
return Collections.emptyIterator();
}

/**
* Produces a sync packet using the given information.
*
* @param key the key describing the component being synchronized
* @param writer a {@link ComponentPacketWriter} writing the component's data to the packet
* @param recipient the player receiving the packet
* @return a {@link net.minecraft.network.Packet} that has all the information required to perform the component sync
* @since 3.0.0
*/
@Nullable
default <C extends AutoSyncedComponent> CustomPayloadS2CPacket toComponentPacket(ComponentKey<? super C> 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
@ApiStatus.Experimental
default <C extends AutoSyncedComponent> CustomPayloadS2CPacket toComponentPacket(PacketByteBuf buf, ComponentKey<? super C> key, ComponentPacketWriter writer, ServerPlayerEntity recipient) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@ public interface NbtSerializable {
NbtCompound toTag(NbtCompound tag);

@Contract(mutates = "this")
@ApiStatus.Experimental
default void fromDynamic(Dynamic<?> dynamic) {
this.fromTag((NbtCompound) dynamic.convert(NbtOps.INSTANCE).getValue());
}

@Contract(pure = true)
@ApiStatus.Experimental
default <T> Dynamic<T> toDynamic(Dynamic<T> dynamic) {
return dynamic.convert(NbtOps.INSTANCE).map(tag -> this.toTag((NbtCompound)tag)).convert(dynamic.getOps());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@
import dev.onyxstudios.cca.api.v3.component.ComponentFactory;
import dev.onyxstudios.cca.api.v3.component.ComponentKey;
import net.minecraft.block.entity.BlockEntity;
import org.jetbrains.annotations.ApiStatus;

import java.util.function.Predicate;

/**
* @since 2.5.0
*/
@ApiStatus.Experimental
public interface BlockComponentFactoryRegistry {

/**
Expand All @@ -59,13 +57,11 @@ public interface BlockComponentFactoryRegistry {
* @param key the key of components to attach
* @throws NullPointerException if any of the arguments is {@code null}
*/
@ApiStatus.Experimental
<C extends Component, B extends BlockEntity> Registration<C, B> beginRegistration(Class<B> target, ComponentKey<C> key);

@ApiStatus.Experimental
interface Registration<C extends Component, BE extends BlockEntity> {
/**
* Registers a {@link BlockEntityComponentFactory} for all instances of classes that pass the {@code test}.
* Registers a {@link ComponentFactory} for all instances of classes that pass the {@code test}.
*
* @param test a predicate testing whether the class can have the component attached to its instances
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import dev.onyxstudios.cca.internal.base.ComponentRegistrationInitializer;
import net.minecraft.block.entity.BlockEntity;
import org.jetbrains.annotations.ApiStatus;

/**
* Entrypoint getting invoked to register <em>static</em> block component factories.
Expand All @@ -34,7 +33,6 @@
*
* @since 2.5.0
*/
@ApiStatus.Experimental
public interface BlockComponentInitializer extends ComponentRegistrationInitializer {
/**
* Called to register component factories for statically declared component types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.ApiStatus;

import java.util.NoSuchElementException;
import java.util.function.BiFunction;

/**
* This class consists exclusively of static methods that return a {@link Component} by querying some block context.
*/
@ApiStatus.Experimental
public final class BlockComponents {
/**
* Retrieves a context-less {@link BlockApiLookup} for the given {@link ComponentKey}.
Expand All @@ -52,7 +50,6 @@ public final class BlockComponents {
* @see #exposeApi(ComponentKey, BlockApiLookup, BiFunction)
* @since 2.8.0
*/
@ApiStatus.Experimental
public static <C extends Component> BlockApiLookup<C, Void> getApiLookup(ComponentKey<C> key) {
return BlockApiLookup.get(key.getId(), key.getComponentClass(), Void.class);
}
Expand All @@ -63,7 +60,6 @@ public static <C extends Component> BlockApiLookup<C, Void> getApiLookup(Compone
* @see #exposeApi(ComponentKey, BlockApiLookup, BiFunction)
* @since 2.8.0
*/
@ApiStatus.Experimental
public static <A, T> void exposeApi(ComponentKey<? extends A> key, BlockApiLookup<A, T> apiLookup) {
apiLookup.registerFallback((world, pos, state, blockEntity, context) -> {
if (blockEntity != null) {
Expand Down Expand Up @@ -102,7 +98,6 @@ public static <A, T> void exposeApi(ComponentKey<? extends A> key, BlockApiLooku
*
* @since 2.8.0
*/
@ApiStatus.Experimental
public static <A, T, C extends Component> void exposeApi(ComponentKey<C> key, BlockApiLookup<A, T> apiLookup, BiFunction<? super C, ? super T, ? extends A> mapper) {
apiLookup.registerFallback((world, pos, state, blockEntity, context) -> {
if (blockEntity != null) {
Expand All @@ -124,7 +119,6 @@ public static <A, T, C extends Component> void exposeApi(ComponentKey<C> key, Bl
* @see #exposeApi(ComponentKey, BlockApiLookup, BiFunction)
* @since 2.8.0
*/
@ApiStatus.Experimental
public static <A, T, C extends Component> void exposeApi(ComponentKey<C> key, BlockApiLookup<A, T> apiLookup, BiFunction<? super C, ? super T, ? extends A> mapper, BlockEntityType<?>... types) {
apiLookup.registerForBlockEntities((blockEntity, context) -> mapper.apply(key.get(blockEntity), context), types);
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import dev.onyxstudios.cca.api.v3.component.sync.ComponentPacketWriter;
import dev.onyxstudios.cca.internal.CardinalComponentsBlock;
import dev.onyxstudios.cca.internal.block.CardinalBlockInternals;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
Expand Down Expand Up @@ -101,7 +102,8 @@ public Iterator<ServerPlayerEntity> getRecipientsForComponentSync() {

@Nullable
@Override
public <C extends AutoSyncedComponent> CustomPayloadS2CPacket toComponentPacket(PacketByteBuf buf, ComponentKey<? super C> key, ComponentPacketWriter writer, ServerPlayerEntity recipient) {
public <C extends AutoSyncedComponent> CustomPayloadS2CPacket toComponentPacket(ComponentKey<? super C> key, ComponentPacketWriter writer, ServerPlayerEntity recipient) {
PacketByteBuf buf = PacketByteBufs.create();
buf.writeIdentifier(BlockEntityType.getId(this.getType()));
buf.writeBlockPos(this.getPos());
buf.writeIdentifier(key.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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.network.PacketByteBuf;
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
Expand Down Expand Up @@ -82,7 +83,8 @@ public Iterator<ServerPlayerEntity> getRecipientsForComponentSync() {
}

@Override
public <C extends AutoSyncedComponent> CustomPayloadS2CPacket toComponentPacket(PacketByteBuf buf, ComponentKey<? super C> key, ComponentPacketWriter writer, ServerPlayerEntity recipient) {
public <C extends AutoSyncedComponent> CustomPayloadS2CPacket toComponentPacket(ComponentKey<? super C> key, ComponentPacketWriter writer, ServerPlayerEntity recipient) {
PacketByteBuf buf = PacketByteBufs.create();
ChunkPos pos = this.getPos();
buf.writeInt(pos.x);
buf.writeInt(pos.z);
Expand Down
Loading

0 comments on commit cf1795d

Please sign in to comment.