Skip to content

Commit

Permalink
Update to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jun 5, 2024
1 parent 39c946b commit bffc5b0
Show file tree
Hide file tree
Showing 33 changed files with 65 additions and 65 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ component** to some providers (here, to players and worlds):
```java
public final class MyComponents implements EntityComponentInitializer, WorldComponentInitializer {
public static final ComponentKey<IntComponent> MAGIK =
ComponentRegistryV3.INSTANCE.getOrCreate(new Identifier("mymod:magik"), IntComponent.class);
ComponentRegistryV3.INSTANCE.getOrCreate(Identifier.of("mymod:magik"), IntComponent.class);

@Override
public void registerEntityComponentFactories(EntityComponentFactoryRegistry registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void fromTag(NbtCompound tag, RegistryWrapper.WrapperLookup registryLooku
NbtList componentList = tag.getList(NBT_KEY, NbtElement.COMPOUND_TYPE);
for (int i = 0; i < componentList.size(); i++) {
NbtCompound nbt = componentList.getCompound(i);
ComponentKey<?> type = ComponentRegistry.get(new Identifier(nbt.getString("componentId")));
ComponentKey<?> type = ComponentRegistry.get(Identifier.of(nbt.getString("componentId")));
if (type != null) {
Component component = type.getInternal(this);
if (component != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package org.ladysnake.cca.internal.base;

import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.network.DisconnectionInfo;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.text.Text;
import org.ladysnake.cca.api.v3.component.Component;
Expand All @@ -41,7 +42,7 @@ public static <T extends ComponentUpdatePayload<?>> void registerComponentSync(C
}
});
} catch (UnknownComponentException e) {
ctx.player().networkHandler.onDisconnected(Text.literal(e.getMessage() + "\n(you are probably missing a mod installed on the server)" + ComponentsInternals.getClientOptionalModAdvice()));
ctx.player().networkHandler.onDisconnected(new DisconnectionInfo(Text.literal(e.getMessage() + "\n(you are probably missing a mod installed on the server)" + ComponentsInternals.getClientOptionalModAdvice())));
} finally {
payload.buf().release();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public record ComponentUpdatePayload<T>(
RegistryByteBuf buf
) implements CustomPayload {
public static <T> CustomPayload.Id<ComponentUpdatePayload<T>> id(String path) {
return CustomPayload.id("cardinal-components:" + path);
return new CustomPayload.Id<>(Identifier.of("cardinal-components", path));
}

public static <T> void register(Id<ComponentUpdatePayload<T>> id, PacketCodec<? super RegistryByteBuf, T> targetDataCodec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected void init() {
if (metadata.containsCustomValue("cardinal-components")) {
try {
for (CustomValue value : metadata.getCustomValue("cardinal-components").getAsArray()) {
staticComponentTypes.add(new Identifier(value.getAsString()));
staticComponentTypes.add(Identifier.of(value.getAsString()));
}
} catch (ClassCastException | InvalidIdentifierException e) {
throw new StaticComponentLoadingException("Failed to load component ids declared by " + metadata.getName() + "(" + metadata.getId() + ")", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.List;

public class CcaTesting {
public static final Identifier TEST_ID_1 = new Identifier("testmod:test");
public static final Identifier TEST_ID_2 = new Identifier("testmod:test_2");
public static final Identifier TEST_ID_3 = new Identifier("testmod:test_3");
public static final Identifier TEST_ID_1 = Identifier.of("testmod:test");
public static final Identifier TEST_ID_2 = Identifier.of("testmod:test_2");
public static final Identifier TEST_ID_3 = Identifier.of("testmod:test_3");
public static final List<Identifier> ALL_TEST_IDS = List.of(TEST_ID_1, TEST_ID_2, TEST_ID_3);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.ladysnake.cca.api.v3.component.load.ServerUnloadAwareComponent;

public class LoadAwareTestComponent implements TransientComponent, ServerLoadAwareComponent, ServerUnloadAwareComponent {
public static final ComponentKey<LoadAwareTestComponent> KEY = ComponentRegistry.getOrCreate(new Identifier("cca-base-test", "loading"), LoadAwareTestComponent.class);
public static final ComponentKey<LoadAwareTestComponent> KEY = ComponentRegistry.getOrCreate(Identifier.of("cca-base-test", "loading"), LoadAwareTestComponent.class);

private int loadCounter = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.ladysnake.cca.api.v3.component.tick.ServerTickingComponent;

public class TickingTestComponent implements ServerTickingComponent, ClientTickingComponent {
public static final ComponentKey<TickingTestComponent> KEY = ComponentRegistry.getOrCreate(new Identifier("cca-base-test", "ticking"), TickingTestComponent.class);
public static final ComponentKey<TickingTestComponent> KEY = ComponentRegistry.getOrCreate(Identifier.of("cca-base-test", "ticking"), TickingTestComponent.class);

private int clientTicks;
private int serverTicks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.ladysnake.cca.api.v3.component.ComponentV3;

public interface Vita extends ComponentV3 {
ComponentKey<Vita> KEY = ComponentRegistryV3.INSTANCE.getOrCreate(new Identifier("cca-base-test", "vita"), Vita.class);
ComponentKey<Vita> KEY = ComponentRegistryV3.INSTANCE.getOrCreate(Identifier.of("cca-base-test", "vita"), Vita.class);

static Vita get(Object provider) {
return KEY.get(provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static <A, T> void exposeApi(ComponentKey<? extends A> key, BlockApiLooku
*
* <pre>{@code
* public interface FluidContainerCompound extends Component {
* ComponentKey<FluidContainerCompound> KEY = ComponentRegistry.register(new Identifier("mymod:fluid_container_compound"), FluidContainerCompound.class);
* ComponentKey<FluidContainerCompound> KEY = ComponentRegistry.register(Identifier.of("mymod:fluid_container_compound"), FluidContainerCompound.class);
*
* FluidContainer get(Direction side);
* }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class CardinalComponentsBlock {
* <p> Components synchronized through this channel will have {@linkplain AutoSyncedComponent#applySyncPacket(net.minecraft.network.RegistryByteBuf)}
* called on the game thread.
*/
public static final CustomPayload.Id<ComponentUpdatePayload<BlockEntityAddress>> PACKET_ID = CustomPayload.id("cardinal-components:block_entity_sync");
public static final CustomPayload.Id<ComponentUpdatePayload<BlockEntityAddress>> PACKET_ID = ComponentUpdatePayload.id("block_entity_sync");

public static void init() {
if (FabricLoader.getInstance().isModLoaded("fabric-networking-api-v1")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

public class CcaBlockTestMod implements ModInitializer, BlockComponentInitializer {
public static final String MOD_ID = "cca-block-test";
public static final BlockApiLookup<Vita, Direction> VITA_API_LOOKUP = BlockApiLookup.get(new Identifier(MOD_ID, "sided_vita"), Vita.class, Direction.class);
public static final BlockApiLookup<Vita, Direction> VITA_API_LOOKUP = BlockApiLookup.get(Identifier.of(MOD_ID, "sided_vita"), Vita.class, Direction.class);

@Override
public void registerBlockComponentFactories(BlockComponentFactoryRegistry registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void beComponentsTick(TestContext ctx) {
BlockPos pos = new BlockPos(1, 1, 1);
ctx.setBlockState(pos, Blocks.END_PORTAL);
ctx.addFinalTaskWithDuration(5, () -> {
int ticks = Objects.requireNonNull(ctx.getBlockEntity(pos)).getComponent(TickingTestComponent.KEY).serverTicks();
int ticks = TickingTestComponent.KEY.get(ctx.getBlockEntity(pos)).serverTicks();
GameTestUtil.assertTrue("Component should tick 5 times", ticks == 5);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import java.util.Map;

public class VitaCompound implements AutoSyncedComponent {
public static final ComponentKey<VitaCompound> KEY = ComponentRegistryV3.INSTANCE.getOrCreate(new Identifier(CcaBlockTestMod.MOD_ID, "vita_compound"), VitaCompound.class);
public static final ComponentKey<VitaCompound> KEY = ComponentRegistryV3.INSTANCE.getOrCreate(Identifier.of(CcaBlockTestMod.MOD_ID, "vita_compound"), VitaCompound.class);

private final Map<Direction, SyncedVita> storage = new EnumMap<>(Direction.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.ladysnake.cca.internal.base.MorePacketCodecs;

public final class CardinalComponentsChunk {
public static final CustomPayload.Id<ComponentUpdatePayload<ChunkPos>> PACKET_ID = CustomPayload.id("cardinal-components:chunk_sync");
public static final CustomPayload.Id<ComponentUpdatePayload<ChunkPos>> PACKET_ID = ComponentUpdatePayload.id("chunk_sync");

public static void init() {
if (FabricLoader.getInstance().isModLoaded("fabric-networking-api-v1")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.minecraft.world.chunk.ProtoChunk;
import net.minecraft.world.chunk.WrapperProtoChunk;
import net.minecraft.world.poi.PointOfInterestStorage;
import net.minecraft.world.storage.StorageKey;
import org.ladysnake.cca.internal.base.AbstractComponentContainer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -40,7 +41,7 @@
@Mixin(ChunkSerializer.class)
public abstract class MixinChunkSerializer {
@Inject(method = "deserialize", at = @At("RETURN"))
private static void deserialize(ServerWorld world, PointOfInterestStorage pointOfInterestStorage, ChunkPos chunkPos, NbtCompound tag, CallbackInfoReturnable<ProtoChunk> cir) {
private static void deserialize(ServerWorld world, PointOfInterestStorage poiStorage, StorageKey key, ChunkPos chunkPos, NbtCompound tag, CallbackInfoReturnable<ProtoChunk> cir) {
ProtoChunk ret = cir.getReturnValue();
Chunk chunk = ret instanceof WrapperProtoChunk ? ((WrapperProtoChunk) ret).getWrappedChunk() : ret;
chunk.asComponentProvider().getComponentContainer().fromTag(tag, world.getRegistryManager());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.minecraft.world.ChunkSerializer;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.WorldChunk;
import net.minecraft.world.storage.StorageKey;
import org.ladysnake.cca.test.base.LoadAwareTestComponent;
import org.ladysnake.cca.test.base.TickingTestComponent;
import org.ladysnake.cca.test.base.Vita;
Expand All @@ -43,7 +44,7 @@ public void chunksSerialize(TestContext ctx) {
Chunk c = new WorldChunk(ctx.getWorld(), pos);
c.getComponent(Vita.KEY).setVitality(42);
NbtCompound nbt = ChunkSerializer.serialize(ctx.getWorld(), c);
Chunk c1 = ChunkSerializer.deserialize(ctx.getWorld(), ctx.getWorld().getPointOfInterestStorage(), pos, nbt);
Chunk c1 = ChunkSerializer.deserialize(ctx.getWorld(), ctx.getWorld().getPointOfInterestStorage(), new StorageKey("", ctx.getWorld().getRegistryKey(), ""), pos, nbt);
GameTestUtil.assertTrue("Chunk component data should survive deserialization", c1.getComponent(Vita.KEY).getVitality() == 42);
ctx.complete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public interface RespawnCopyStrategy<C extends Component> {
* <p>Mods that depend on component data for their own copying logic can {@linkplain net.fabricmc.fabric.api.event.Event#addPhaseOrdering(Identifier, Identifier) add a phase ordering}
* to run after CCA's listeners.
*/
Identifier EVENT_PHASE = new Identifier("cardinal-components", "component-copy");
Identifier EVENT_PHASE = Identifier.of("cardinal-components", "component-copy");

/**
* @param entityClass the class of the source entity being respawned or converted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public final class CardinalComponentsEntity {
* <p> Components synchronized through this channel will have {@linkplain AutoSyncedComponent#applySyncPacket(net.minecraft.network.RegistryByteBuf)}
* called on the game thread.
*/
public static final CustomPayload.Id<ComponentUpdatePayload<Integer>> PACKET_ID = CustomPayload.id("cardinal-components:entity_sync");
public static final CustomPayload.Id<ComponentUpdatePayload<Integer>> PACKET_ID = ComponentUpdatePayload.id("entity_sync");
/**
* {@link net.minecraft.network.packet.c2s.common.CustomPayloadC2SPacket} channel for C2S player component messages.
*
Expand All @@ -70,7 +70,7 @@ public final class CardinalComponentsEntity {
* <p> Components synchronized through this channel will have {@linkplain org.ladysnake.cca.api.v3.entity.C2SSelfMessagingComponent#handleC2SMessage(net.minecraft.network.RegistryByteBuf)}
* called on the game thread.
*/
public static final CustomPayload.Id<ComponentUpdatePayload<Unit>> C2S_SELF_PACKET_ID = CustomPayload.id("cardinal-components:player_message_c2s");
public static final CustomPayload.Id<ComponentUpdatePayload<Unit>> C2S_SELF_PACKET_ID = ComponentUpdatePayload.id("player_message_c2s");
private static final Set<Identifier> unknownC2SPlayerComponents = new HashSet<>();

public static void init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package org.ladysnake.cca.mixin.entity.common;

import net.minecraft.entity.Entity;
import net.minecraft.network.ClientConnection;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ConnectedClientData;
Expand All @@ -39,7 +40,7 @@ public abstract class MixinPlayerManager {
method = "onPlayerConnect",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/network/ServerPlayerEntity;getStatusEffects()Ljava/util/Collection;"
target = "Lnet/minecraft/server/PlayerManager;sendStatusEffects(Lnet/minecraft/server/network/ServerPlayerEntity;)V"
)
)
private void onPlayerLogIn(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) {
Expand All @@ -58,7 +59,7 @@ private void sendPlayerStatus(ServerPlayerEntity player, CallbackInfo info) {
method = "respawnPlayer",
at = @At("RETURN")
)
private void respawnPlayer(ServerPlayerEntity player, boolean end, CallbackInfoReturnable<ServerPlayerEntity> cir) {
private void respawnPlayer(ServerPlayerEntity player, boolean alive, Entity.RemovalReason removalReason, CallbackInfoReturnable<ServerPlayerEntity> cir) {
PlayerSyncCallback.EVENT.invoker().onPlayerSync(cir.getReturnValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public void registerEntityComponentFactories(EntityComponentFactoryRegistry regi

@Override
public void onInitialize() {
Registry.register(Registries.ENTITY_TYPE, new Identifier("cca-entity-test", "test"), TEST_ENTITY);
Registry.register(Registries.ENTITY_TYPE, Identifier.of("cca-entity-test", "test"), TEST_ENTITY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import net.minecraft.entity.EntityType;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.world.World;

public class TestEntity extends Entity {
Expand All @@ -49,9 +47,4 @@ protected void readCustomDataFromNbt(NbtCompound nbt) {
protected void writeCustomDataToNbt(NbtCompound nbt) {

}

@Override
public Packet<ClientPlayPacketListener> createSpawnPacket() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
package org.ladysnake.cca.api.v3.item;

import net.minecraft.component.DataComponentType;
import net.minecraft.component.ComponentType;
import net.minecraft.util.Identifier;
import org.ladysnake.cca.api.v3.component.ComponentKey;

Expand All @@ -31,12 +31,12 @@
*/
public interface ItemComponentMigrationRegistry {
/**
* Registers an item component migration from the specified {@link ComponentKey#getId() CCA Component ID} to an equivalent {@link DataComponentType}.
* Registers an item component migration from the specified {@link ComponentKey#getId() CCA Component ID} to an equivalent {@link ComponentType}.
*
* <p>This hooks into the vanilla datafixing process and may therefore not correctly migrate data for stacks stored in modded containers.
*
* @param oldComponentId the item component ID from CCA days
* @param mcComponentType the new vanilla component type
*/
void registerMigration(Identifier oldComponentId, DataComponentType<?> mcComponentType);
void registerMigration(Identifier oldComponentId, ComponentType<?> mcComponentType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
*/
package org.ladysnake.cca.internal.item;

import com.mojang.serialization.Dynamic;
import net.fabricmc.api.ModInitializer;
import net.minecraft.component.DataComponentType;
import net.minecraft.component.ComponentType;
import net.minecraft.datafixer.fix.ItemStackComponentizationFix;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import org.ladysnake.cca.api.v3.item.ItemComponentMigrationRegistry;
import org.ladysnake.cca.api.v3.item.ItemComponentInitializer;
import org.ladysnake.cca.internal.base.AbstractComponentContainer;
import org.ladysnake.cca.api.v3.item.ItemComponentMigrationRegistry;
import org.ladysnake.cca.internal.base.ComponentsInternals;
import org.ladysnake.cca.internal.base.asm.StaticComponentPluginBase;

Expand All @@ -42,17 +40,17 @@ public final class StaticItemComponentPlugin implements ItemComponentMigrationRe

private StaticItemComponentPlugin() {}

private final Map<Identifier, DataComponentType<?>> migrations = new HashMap<>();
private final Map<Identifier, ComponentType<?>> migrations = new HashMap<>();

@Override
public void registerMigration(Identifier oldComponentId, DataComponentType<?> mcComponentType) {
public void registerMigration(Identifier oldComponentId, ComponentType<?> mcComponentType) {
if (this.migrations.put(oldComponentId, mcComponentType) != null) {
ComponentsInternals.LOGGER.warn("[Cardinal-Components-API] Overwriting component migration for {}", oldComponentId);
}
}

public void migrate(ItemStackComponentizationFix.StackData data) {
for (Map.Entry<Identifier, DataComponentType<?>> entry : migrations.entrySet()) {
for (Map.Entry<Identifier, ComponentType<?>> entry : migrations.entrySet()) {
String oldComponentId = entry.getKey().toString();
String mcComponentId = Registries.DATA_COMPONENT_TYPE.getKey(entry.getValue()).orElseThrow(
() -> new IllegalStateException("Registered migration for component " + oldComponentId + " towards unregistered item component type " + entry.getValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class CardinalComponentsLevel {
* <p> Components synchronized through this channel will have {@linkplain AutoSyncedComponent#applySyncPacket(net.minecraft.network.RegistryByteBuf)}
* called on the game thread.
*/
public static final CustomPayload.Id<ComponentUpdatePayload<Unit>> PACKET_ID = CustomPayload.id("cardinal-components:level_sync");
public static final CustomPayload.Id<ComponentUpdatePayload<Unit>> PACKET_ID = ComponentUpdatePayload.id("level_sync");

public static void init() {
if (FabricLoader.getInstance().isModLoaded("fabric-networking-api-v1")) {
Expand Down
Loading

0 comments on commit bffc5b0

Please sign in to comment.