Skip to content

Commit

Permalink
Update to 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed May 22, 2022
1 parent fc8192d commit 9b0a835
Show file tree
Hide file tree
Showing 49 changed files with 242 additions and 384 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// ...
Expand Down
12 changes: 5 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -292,25 +292,23 @@ 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)
modImplementation fabricApi.module("fabric-events-interaction-v0", fabric_api_version)
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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>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 <C> 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 extends Component> C getComponent(ComponentKey<C> key) {
return key.get(this.asComponentProvider());
}

/**
* Attempts to synchronize the component of the desired type with watching clients.
*
* <p>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 <code>provider</code> 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}.
*
* <p>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 <code>provider</code> 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}.
*
* <p>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 <code>provider</code> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -58,28 +57,32 @@ public final Class<C> 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 <code>provider</code> does not implement {@link ComponentProvider}
* @see #get(Object)
* @see #maybeGet(Object)
*/
@Contract(pure = true)
public <V> @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 <V> 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 <code>provider</code> does not implement {@link ComponentProvider}
* @see #maybeGet(Object)
* @see ComponentAccess#getComponent(ComponentKey)
*/
public final <V> C get(V provider) {
public final C get(Object provider) {
C component = this.getInternal(((ComponentProvider) provider).getComponentContainer());

assert component == null || this.getComponentClass().isInstance(component);
Expand All @@ -99,20 +102,19 @@ public final <V> C get(V provider) {

/**
* @param provider a component provider
* @param <V> 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 <V> Optional<C> maybeGet(@Nullable V provider) {
public final Optional<C> maybeGet(@Nullable Object provider) {
if (provider instanceof ComponentProvider p) {
return Optional.ofNullable(this.getInternal(p.getComponentContainer()));
}
return Optional.empty();
}

@Contract(pure = true)
public <V> boolean isProvidedBy(V provider) {
public boolean isProvidedBy(Object provider) {
return this.getNullable(provider) != null;
}

Expand All @@ -123,11 +125,11 @@ public <V> boolean isProvidedBy(V provider) {
* the associated component does not implement an adequate synchronization interface.
*
* @param provider a component provider
* @param <V> the class of the component provider
* @throws NoSuchElementException if the provider does not provide this type of component
* @throws ClassCastException if <code>provider</code> does not implement {@link ComponentProvider}
* @see ComponentAccess#syncComponent(ComponentKey)
*/
public <V> void sync(V provider) {
public void sync(Object provider) {
if (this.get(provider) instanceof AutoSyncedComponent synced) {
this.sync(provider, synced, synced);
}
Expand All @@ -139,13 +141,13 @@ public <V> void sync(V provider) {
* <p>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 <V> 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 <code>provider</code> does not implement {@link ComponentProvider}
* @see ComponentAccess#syncComponent(ComponentKey, ComponentPacketWriter)
*/
public <V> 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);
}
Expand All @@ -157,17 +159,16 @@ public <V> void sync(V provider, ComponentPacketWriter packetWriter) {
* <p>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 <V> 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 <code>provider</code> does not implement {@link ComponentProvider}
* @see ComponentAccess#syncComponent(ComponentKey, ComponentPacketWriter, PlayerSyncPredicate)
*/
public <V> void sync(V provider, ComponentPacketWriter packetWriter, PlayerSyncPredicate predicate) {
ComponentProvider prov = (ComponentProvider) provider;
for (Iterator<ServerPlayerEntity> 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);
}
}

Expand Down
Loading

0 comments on commit 9b0a835

Please sign in to comment.