mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
Add ClientLifecycleEvent.CLIENT_SETUP and allow deferring in ColorHandlers
This commit is contained in:
@@ -58,6 +58,12 @@ public final class EventFactory {
|
||||
return new EventImpl<>(function);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> Event<T> createLoop(T... typeGetter) {
|
||||
if (typeGetter.length != 0) throw new IllegalStateException("array must be empty!");
|
||||
return createLoop((Class<T>) typeGetter.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public static <T> Event<T> createLoop(Class<T> clazz) {
|
||||
return of(listeners -> (T) Proxy.newProxyInstance(EventFactory.class.getClassLoader(), new Class[]{clazz}, new AbstractInvocationHandler() {
|
||||
@@ -71,6 +77,12 @@ public final class EventFactory {
|
||||
}));
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> Event<T> createInteractionResult(T... typeGetter) {
|
||||
if (typeGetter.length != 0) throw new IllegalStateException("array must be empty!");
|
||||
return createInteractionResult((Class<T>) typeGetter.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public static <T> Event<T> createInteractionResult(Class<T> clazz) {
|
||||
return of(listeners -> (T) Proxy.newProxyInstance(EventFactory.class.getClassLoader(), new Class[]{clazz}, new AbstractInvocationHandler() {
|
||||
@@ -87,6 +99,12 @@ public final class EventFactory {
|
||||
}));
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> Event<T> createInteractionResultHolder(T... typeGetter) {
|
||||
if (typeGetter.length != 0) throw new IllegalStateException("array must be empty!");
|
||||
return createInteractionResultHolder((Class<T>) typeGetter.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public static <T> Event<T> createInteractionResultHolder(Class<T> clazz) {
|
||||
return of(listeners -> (T) Proxy.newProxyInstance(EventFactory.class.getClassLoader(), new Class[]{clazz}, new AbstractInvocationHandler() {
|
||||
@@ -103,6 +121,12 @@ public final class EventFactory {
|
||||
}));
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> Event<Consumer<T>> createConsumerLoop(T... typeGetter) {
|
||||
if (typeGetter.length != 0) throw new IllegalStateException("array must be empty!");
|
||||
return createConsumerLoop((Class<T>) typeGetter.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public static <T> Event<Consumer<T>> createConsumerLoop(Class<T> clazz) {
|
||||
Event<Consumer<T>> event = of(listeners -> (Consumer<T>) Proxy.newProxyInstance(EventFactory.class.getClassLoader(), new Class[]{Consumer.class}, new AbstractInvocationHandler() {
|
||||
@@ -124,6 +148,12 @@ public final class EventFactory {
|
||||
return event;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> Event<Actor<T>> createActorLoop(T... typeGetter) {
|
||||
if (typeGetter.length != 0) throw new IllegalStateException("array must be empty!");
|
||||
return createActorLoop((Class<T>) typeGetter.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public static <T> Event<Actor<T>> createActorLoop(Class<T> clazz) {
|
||||
Event<Actor<T>> event = of(listeners -> (Actor<T>) Proxy.newProxyInstance(EventFactory.class.getClassLoader(), new Class[]{Actor.class}, new AbstractInvocationHandler() {
|
||||
|
||||
@@ -41,6 +41,7 @@ public interface ClientLifecycleEvent {
|
||||
* Invoked after a world is loaded only on client, equivalent to forge's {@code WorldEvent.Load}.
|
||||
*/
|
||||
Event<ClientWorldState> CLIENT_WORLD_LOAD = EventFactory.createLoop(ClientWorldState.class);
|
||||
Event<ClientState> CLIENT_SETUP = EventFactory.createLoop();
|
||||
|
||||
@Deprecated
|
||||
@Environment(EnvType.CLIENT)
|
||||
|
||||
@@ -27,17 +27,34 @@ import net.minecraft.client.color.item.ItemColor;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public final class ColorHandlers {
|
||||
private ColorHandlers() {}
|
||||
|
||||
@ExpectPlatform
|
||||
public static void registerItemColors(ItemColor color, ItemLike... items) {
|
||||
registerItemColors(color, Arrays.stream(items)
|
||||
.map(item -> (Supplier<ItemLike>) () -> item)
|
||||
.toArray(Supplier[]::new));
|
||||
}
|
||||
|
||||
public static void registerBlockColors(BlockColor color, Block... blocks) {
|
||||
registerBlockColors(color, Arrays.stream(blocks)
|
||||
.map(block -> (Supplier<Block>) () -> block)
|
||||
.toArray(Supplier[]::new));
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
@ExpectPlatform
|
||||
public static void registerItemColors(ItemColor color, Supplier<ItemLike>... items) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
@ExpectPlatform
|
||||
public static void registerBlockColors(BlockColor color, Block... blocks) {
|
||||
public static void registerBlockColors(BlockColor color, Supplier<Block>... blocks) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,5 @@ public final class RenderTypes {
|
||||
public static void register(RenderType type, Fluid... fluids) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user