From a3a90d4751a0c58bd6d5e03fcb34e5a2bf3e56f4 Mon Sep 17 00:00:00 2001 From: forgetmenot <149003152+forgetmenot13579@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:04:49 -0700 Subject: [PATCH 1/4] - Initial draft commit --- fabric-components-api-v1/build.gradle | 7 + .../api/components/v1/api/Component.java | 29 ++++ .../components/v1/api/ComponentEvents.java | 45 ++++++ .../api/components/v1/api/ComponentType.java | 50 ++++++ .../api/components/v1/api/TargetedEvent.java | 37 +++++ .../components/v1/impl/ComponentTypeImpl.java | 146 ++++++++++++++++++ .../components/v1/impl/TargetedEventImpl.java | 70 +++++++++ .../assets/fabric-components-api-v1/icon.png | Bin 0 -> 1579 bytes .../fabric-components-api-v1.mixins.json | 10 ++ .../src/main/resources/fabric.mod.json | 30 ++++ .../test/components/ComponentTestMod.java | 45 ++++++ .../fabric/test/components/CreeperColor.java | 36 +++++ .../src/testmod/resources/fabric.mod.json | 18 +++ gradle.properties | 1 + settings.gradle | 1 + 15 files changed, 525 insertions(+) create mode 100644 fabric-components-api-v1/build.gradle create mode 100644 fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/Component.java create mode 100644 fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentEvents.java create mode 100644 fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentType.java create mode 100644 fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/TargetedEvent.java create mode 100644 fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/ComponentTypeImpl.java create mode 100644 fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/TargetedEventImpl.java create mode 100644 fabric-components-api-v1/src/main/resources/assets/fabric-components-api-v1/icon.png create mode 100644 fabric-components-api-v1/src/main/resources/fabric-components-api-v1.mixins.json create mode 100644 fabric-components-api-v1/src/main/resources/fabric.mod.json create mode 100644 fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/ComponentTestMod.java create mode 100644 fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/CreeperColor.java create mode 100644 fabric-components-api-v1/src/testmod/resources/fabric.mod.json diff --git a/fabric-components-api-v1/build.gradle b/fabric-components-api-v1/build.gradle new file mode 100644 index 0000000000..7d2ad2384b --- /dev/null +++ b/fabric-components-api-v1/build.gradle @@ -0,0 +1,7 @@ +version = getSubprojectVersion(project) + +moduleDependencies(project, [ + 'fabric-api-base', + 'fabric-data-attachment-api-v1', + 'fabric-lifecycle-events-v1' +]) diff --git a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/Component.java b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/Component.java new file mode 100644 index 0000000000..5775eec135 --- /dev/null +++ b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/Component.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.api.components.v1.api; + +import net.fabricmc.fabric.api.attachment.v1.AttachmentTarget; + +public interface Component { + interface EventHandler, A extends AttachmentTarget, E> { + void handle(C component, A target, E eventPayload); + } + + interface EventListener, A extends AttachmentTarget> { + void handle(C component, A target); + } +} diff --git a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentEvents.java b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentEvents.java new file mode 100644 index 0000000000..93d37105ff --- /dev/null +++ b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentEvents.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.api.components.v1.api; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.server.world.ServerWorld; + +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents; + +public final class ComponentEvents { + public static final TargetedEvent ENTITY_LOAD = TargetedEvent.create(ServerEntityEvents.ENTITY_LOAD, + event -> event::accept); + + public static final TargetedEvent ENTITY_UNLOAD = TargetedEvent.create(ServerEntityEvents.ENTITY_UNLOAD, + event -> event::accept); + + public static final TargetedEvent EQUIPMENT_CHANGE = TargetedEvent.create(ServerEntityEvents.EQUIPMENT_CHANGE, + event -> (livingEntity, equipmentSlot, previousStack, currentStack) -> + event.accept(livingEntity, new EquipmentChangeEvent(equipmentSlot, previousStack, currentStack))); + + private ComponentEvents() { + + } + + public record EquipmentChangeEvent(EquipmentSlot equipmentSlot, ItemStack previousStack, ItemStack currentStack) { + + } +} diff --git a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentType.java b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentType.java new file mode 100644 index 0000000000..3b0daa10e3 --- /dev/null +++ b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentType.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.api.components.v1.api; + +import java.util.List; +import java.util.function.Consumer; + +import net.minecraft.util.Identifier; + +import net.fabricmc.fabric.api.attachment.v1.AttachmentRegistry; +import net.fabricmc.fabric.api.attachment.v1.AttachmentTarget; +import net.fabricmc.fabric.api.attachment.v1.AttachmentType; +import net.fabricmc.fabric.api.components.v1.impl.ComponentTypeImpl; + +public interface ComponentType> extends AttachmentType { + static > ComponentType create(Identifier identifier) { + return create(identifier, builder -> { }); + } + + static > ComponentType create(Identifier identifier, Consumer> consumer) { + var builder = new ComponentTypeImpl.BuilderImpl(); + + consumer.accept(builder); + + return builder.buildAndRegister(identifier); + } + + List> getEventHandlers(TargetedEvent event); + + interface Builder> extends AttachmentRegistry.Builder { + Builder listen(TargetedEvent event, Class targetClass, Component.EventHandler handler); + Builder listen(TargetedEvent event, Class targetClass, Component.EventListener handler); + Builder listen(TargetedEvent event, Component.EventHandler handler); + Builder listen(TargetedEvent event, Component.EventListener handler); + } +} diff --git a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/TargetedEvent.java b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/TargetedEvent.java new file mode 100644 index 0000000000..99b7c9953e --- /dev/null +++ b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/TargetedEvent.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.api.components.v1.api; + +import java.util.function.BiConsumer; +import java.util.function.Function; + +import net.fabricmc.fabric.api.attachment.v1.AttachmentTarget; +import net.fabricmc.fabric.api.components.v1.impl.TargetedEventImpl; +import net.fabricmc.fabric.api.event.Event; + +public interface TargetedEvent { + static TargetedEvent create(Event event, Function, T> invokerFactory) { + TargetedEventImpl targetedEvent = TargetedEventImpl.create(event); + T invoker = invokerFactory.apply(targetedEvent::invoke); + + event.register(invoker); + + return targetedEvent; + } + + void invoke(A attachmentTarget, E eventContext); +} diff --git a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/ComponentTypeImpl.java b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/ComponentTypeImpl.java new file mode 100644 index 0000000000..a8cbb1a758 --- /dev/null +++ b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/ComponentTypeImpl.java @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.api.components.v1.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Supplier; + +import com.mojang.serialization.Codec; +import org.jetbrains.annotations.Nullable; + +import net.minecraft.util.Identifier; + +import net.fabricmc.fabric.api.attachment.v1.AttachmentRegistry; +import net.fabricmc.fabric.api.attachment.v1.AttachmentTarget; +import net.fabricmc.fabric.api.attachment.v1.AttachmentType; +import net.fabricmc.fabric.api.components.v1.api.Component; +import net.fabricmc.fabric.api.components.v1.api.ComponentType; +import net.fabricmc.fabric.api.components.v1.api.TargetedEvent; + +public final class ComponentTypeImpl> implements ComponentType { + private final AttachmentType attachmentType; + private final Map, List>> eventHandlers = new IdentityHashMap<>(); + + public ComponentTypeImpl(AttachmentType attachmentType) { + this.attachmentType = attachmentType; + } + + @Override + public List> getEventHandlers(TargetedEvent event) { + //noinspection unchecked + return (List>) (Object) this.eventHandlers.getOrDefault(event, Collections.emptyList()); + } + + @Override + public Identifier identifier() { + return this.attachmentType.identifier(); + } + + @Override + public @Nullable Codec persistenceCodec() { + return this.attachmentType.persistenceCodec(); + } + + @Override + public boolean isPersistent() { + return this.attachmentType.isPersistent(); + } + + @Override + public @Nullable Supplier initializer() { + return this.attachmentType.initializer(); + } + + @Override + public boolean copyOnDeath() { + return this.attachmentType.copyOnDeath(); + } + + public static final class BuilderImpl> implements Builder, AttachmentRegistry.Builder { + private final AttachmentRegistry.Builder attachmentBuilder = AttachmentRegistry.builder(); + private final Map, List>> eventHandlers = new IdentityHashMap<>(); + + @Override + public Builder listen(TargetedEvent event, Class targetClass, Component.EventHandler handler) { + List> handlers = this.eventHandlers.computeIfAbsent(event, e -> new ArrayList<>()); + + handlers.add(new Component.EventHandler() { + @Override + public void handle(C component, AttachmentTarget target, E eventPayload) { + if (targetClass.isAssignableFrom(target.getClass())) { + //noinspection unchecked + handler.handle(component, (A) target, eventPayload); + } + } + }); + + return this; + } + + @Override + public Builder listen(TargetedEvent event, Class targetClass, Component.EventListener handler) { + return this.listen(event, targetClass, (component, attachmentTarget, eventPayload) -> + handler.handle(component, attachmentTarget) + ); + } + + @Override + public Builder listen(TargetedEvent event, Component.EventHandler handler) { + this.eventHandlers.computeIfAbsent(event, e -> new ArrayList<>()).add(handler); + + return this; + } + + @Override + public Builder listen(TargetedEvent event, Component.EventListener handler) { + return this.listen(event, (component, attachmentTarget, eventPayload) -> + handler.handle(component, attachmentTarget) + ); + } + + public ComponentTypeImpl buildAndRegister(Identifier id) { + var attachmentType = this.attachmentBuilder.buildAndRegister(id); + var type = new ComponentTypeImpl<>(attachmentType); + + this.eventHandlers.forEach((event, list) -> { + type.eventHandlers.put(event, List.copyOf(list)); + ((TargetedEventImpl) event).addListener(type); + }); + + return type; + } + + @Override + public AttachmentRegistry.Builder persistent(Codec codec) { + return attachmentBuilder.persistent(codec); + } + + @Override + public AttachmentRegistry.Builder copyOnDeath() { + return attachmentBuilder.copyOnDeath(); + } + + @Override + public AttachmentRegistry.Builder initializer(Supplier initializer) { + return attachmentBuilder.initializer(initializer); + } + } +} diff --git a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/TargetedEventImpl.java b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/TargetedEventImpl.java new file mode 100644 index 0000000000..ceed3e4c13 --- /dev/null +++ b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/TargetedEventImpl.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.api.components.v1.impl; + +import java.util.ArrayList; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; + +import net.fabricmc.fabric.api.attachment.v1.AttachmentTarget; +import net.fabricmc.fabric.api.components.v1.api.Component; +import net.fabricmc.fabric.api.components.v1.api.ComponentType; +import net.fabricmc.fabric.api.components.v1.api.TargetedEvent; +import net.fabricmc.fabric.api.event.Event; + +public class TargetedEventImpl implements TargetedEvent { + private static final Map, TargetedEvent> INSTANCES = new IdentityHashMap<>(); + + private final List> componentTypes = new ArrayList<>(); + + private TargetedEventImpl() { + + } + + public void addListener(ComponentType componentType) { + this.componentTypes.add(componentType); + } + + public static TargetedEventImpl create(Event event) { + //noinspection unchecked + return (TargetedEventImpl) INSTANCES.computeIfAbsent(event, e -> new TargetedEventImpl<>()); + } + + + private > void invokeListenersForComponentType(ComponentType componentType, AttachmentTarget attachmentTarget, E eventPayload) { + var component = attachmentTarget.getAttached(componentType); + + if (component == null && componentType.initializer() != null) { + component = attachmentTarget.getAttachedOrCreate(componentType); + } + + if (component != null) { + for (var handler : componentType.getEventHandlers(this)) { + //noinspection unchecked,rawtypes + ((Component.EventHandler) handler).handle(component, attachmentTarget, eventPayload); + } + } + } + + @Override + public void invoke(A attachmentTarget, E eventContext) { + for (var componentType : this.componentTypes) { + this.invokeListenersForComponentType(componentType, attachmentTarget, eventContext); + } + } +} diff --git a/fabric-components-api-v1/src/main/resources/assets/fabric-components-api-v1/icon.png b/fabric-components-api-v1/src/main/resources/assets/fabric-components-api-v1/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..2931efbf610873c0084debb8690902b0103d27fe GIT binary patch literal 1579 zcmbVMTWB0r7@iGm)TAXsYw<=rnU=;v=W=GRbL=!tc4Brl6GO7t2vVJ$IlDV#XU;e? z+r2ymsZdMQqAyaFLLUo;RumtE8Z@?uf_*4nP^4;o6fOFoSkN+o1$K?f2nE9_*b5G-l)AV)k5Qhb^- zU{V4ZnTKgnmXdpcB*Kg!W(1hvM2N&RO30x1u~eI9meGQGe@_?PDQq%q1CiV$8~M7 z?MQ_mOdqCh^a65Sv|ntwSXjV5se1;VK1|Kr8G7TQoQL&*ctt{L{fClG}xPK5k^yK3%T69N6J=>3jBqc zDNvZsrJ-yOXI^^mWf1cmY^XST)CVzIGjvEPENowmy}ax zvJ8_(Cf#+H-dBlH53`_u-~6BVAMz|(g?jCVdBWNZ(+A}(pFV7>S3QgPiQcMaflkIC z-3Ti|VT~{au*vq0ts9O&m$p&Gl=L6+q6_m$IcVq}o~+Pl{g>1esQp4%wp~|*zk1n` zZ7T6Toc4`y88s}riCP|ZXrJ?FLz@^KTcyqLjey zu95Yz%F&S{<0~f)Iomek?+hQ%MhCu%T^zsg>C_L`1`Br`xNY&))k9yTQb$JC>)w_f zpU(^tu^Q)y%W~lVz`jz;_ jF?g&s@Y=Qe&c#kW|JbvqK0Y=Rw)4XDoVqsk_>;c_`@;F@ literal 0 HcmV?d00001 diff --git a/fabric-components-api-v1/src/main/resources/fabric-components-api-v1.mixins.json b/fabric-components-api-v1/src/main/resources/fabric-components-api-v1.mixins.json new file mode 100644 index 0000000000..920ebb2ce4 --- /dev/null +++ b/fabric-components-api-v1/src/main/resources/fabric-components-api-v1.mixins.json @@ -0,0 +1,10 @@ +{ + "required": true, + "package": "net.fabricmc.fabric.mixin.components", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/fabric-components-api-v1/src/main/resources/fabric.mod.json b/fabric-components-api-v1/src/main/resources/fabric.mod.json new file mode 100644 index 0000000000..2eb7f81fa9 --- /dev/null +++ b/fabric-components-api-v1/src/main/resources/fabric.mod.json @@ -0,0 +1,30 @@ +{ + "schemaVersion": 1, + "id": "fabric-components-api-v1", + "name": "Fabric Components API (v1)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/fabric-components-api-v1/icon.png", + "contact": { + "homepage": "https://fabricmc.net", + "irc": "irc://irc.esper.net:6667/fabric", + "issues": "https://github.com/FabricMC/fabric/issues", + "sources": "https://github.com/FabricMC/fabric" + }, + "authors": [ + "FabricMC" + ], + "depends": { + "fabricloader": ">=0.15.11" + }, + "entrypoints": { + }, + "description": "Hooks for components", + "mixins": [ + "fabric-components-api-v1.mixins.json" + ], + "custom": { + "fabric-api:module-lifecycle": "experimental" + } +} diff --git a/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/ComponentTestMod.java b/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/ComponentTestMod.java new file mode 100644 index 0000000000..e252ceed6a --- /dev/null +++ b/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/ComponentTestMod.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.test.components; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.minecraft.entity.mob.CreeperEntity; +import net.minecraft.util.Identifier; + +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.components.v1.api.ComponentEvents; +import net.fabricmc.fabric.api.components.v1.api.ComponentType; + +public class ComponentTestMod implements ModInitializer { + public static final String MOD_ID = "fabric-components-api-v1-testmod"; + public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + + public static ComponentType CREEPER_COLOR = ComponentType.create(Identifier.of(ComponentTestMod.MOD_ID, "creeper_color"), builder -> { + // Using the context object + builder.listen(ComponentEvents.ENTITY_LOAD, CreeperEntity.class, CreeperColor::onLoad); + // Not using the context object + builder.listen(ComponentEvents.ENTITY_UNLOAD, CreeperEntity.class, CreeperColor::onUnload); + builder.initializer(CreeperColor::new); + }); + + @Override + public void onInitialize() { + LOGGER.info("Started components API test mod"); + } +} diff --git a/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/CreeperColor.java b/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/CreeperColor.java new file mode 100644 index 0000000000..c7194be05c --- /dev/null +++ b/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/CreeperColor.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.test.components; + +import net.minecraft.entity.mob.CreeperEntity; +import net.minecraft.server.world.ServerWorld; + +import net.fabricmc.fabric.api.components.v1.api.Component; + +public record CreeperColor(int r, int g, int b) implements Component { + public CreeperColor() { + this(9, 166, 3); + } + + void onLoad(CreeperEntity creeper, ServerWorld world) { + ComponentTestMod.LOGGER.info("Creeper with color {} loaded at {}", this, creeper.getBlockPos()); + } + + void onUnload(CreeperEntity creeper) { + ComponentTestMod.LOGGER.info("Creeper with color {} unloaded at {}", this, creeper.getBlockPos()); + } +} diff --git a/fabric-components-api-v1/src/testmod/resources/fabric.mod.json b/fabric-components-api-v1/src/testmod/resources/fabric.mod.json new file mode 100644 index 0000000000..62c02c63a3 --- /dev/null +++ b/fabric-components-api-v1/src/testmod/resources/fabric.mod.json @@ -0,0 +1,18 @@ +{ + "schemaVersion": 1, + "id": "fabric-components-api-v1-testmod", + "name": "Fabric Components API (v1) Test Mod", + "version": "1.0.0", + "environment": "*", + "license": "Apache-2.0", + "depends": { + "fabric-data-attachment-api-v1": "*", + "fabric-components-api-v1": "*", + "fabric-lifecycle-events-v1": "*" + }, + "entrypoints": { + "main": [ + "net.fabricmc.fabric.test.components.ComponentTestMod" + ] + } +} diff --git a/gradle.properties b/gradle.properties index 51e867c005..7377fb0af2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,6 +21,7 @@ fabric-blockrenderlayer-v1-version=1.1.52 fabric-command-api-v1-version=1.2.49 fabric-command-api-v2-version=2.2.28 fabric-commands-v0-version=0.2.66 +fabric-components-api-v1-version=0.1.0 fabric-content-registries-v0-version=8.0.16 fabric-crash-report-info-v1-version=0.2.29 fabric-data-attachment-api-v1-version=1.1.28 diff --git a/settings.gradle b/settings.gradle index 540cbccdbf..88cf329c0a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,6 +22,7 @@ include 'fabric-block-view-api-v2' include 'fabric-blockrenderlayer-v1' include 'fabric-client-tags-api-v1' include 'fabric-command-api-v2' +include 'fabric-components-api-v1' include 'fabric-content-registries-v0' include 'fabric-convention-tags-v2' include 'fabric-crash-report-info-v1' From 0653b0ba9cfa6151debe9d05bd3fbc3f57bb6c0f Mon Sep 17 00:00:00 2001 From: forgetmenot <149003152+forgetmenot13579@users.noreply.github.com> Date: Mon, 23 Sep 2024 15:58:09 -0700 Subject: [PATCH 2/4] - Add additional listerner method that takes no arguments. --- .../api/components/v1/api/Component.java | 4 ---- .../api/components/v1/api/ComponentType.java | 9 +++++-- .../components/v1/impl/ComponentTypeImpl.java | 24 +++++++++++++++---- .../test/components/ComponentTestMod.java | 2 ++ .../fabric/test/components/CreeperColor.java | 5 ++++ 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/Component.java b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/Component.java index 5775eec135..7cf52da831 100644 --- a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/Component.java +++ b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/Component.java @@ -22,8 +22,4 @@ public interface Component { interface EventHandler, A extends AttachmentTarget, E> { void handle(C component, A target, E eventPayload); } - - interface EventListener, A extends AttachmentTarget> { - void handle(C component, A target); - } } diff --git a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentType.java b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentType.java index 3b0daa10e3..80527a2531 100644 --- a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentType.java +++ b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentType.java @@ -17,6 +17,7 @@ package net.fabricmc.fabric.api.components.v1.api; import java.util.List; +import java.util.function.BiConsumer; import java.util.function.Consumer; import net.minecraft.util.Identifier; @@ -42,9 +43,13 @@ static > ComponentType List> getEventHandlers(TargetedEvent event); interface Builder> extends AttachmentRegistry.Builder { + // We probably don't absolutely need all three of Builder listen(TargetedEvent event, Class targetClass, Component.EventHandler handler); - Builder listen(TargetedEvent event, Class targetClass, Component.EventListener handler); + Builder listen(TargetedEvent event, Class targetClass, BiConsumer handler); + Builder listen(TargetedEvent event, Class targetClass, Consumer handler); + Builder listen(TargetedEvent event, Component.EventHandler handler); - Builder listen(TargetedEvent event, Component.EventListener handler); + Builder listen(TargetedEvent event, BiConsumer handler); + Builder listen(TargetedEvent event, Consumer handler); } } diff --git a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/ComponentTypeImpl.java b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/ComponentTypeImpl.java index a8cbb1a758..c5c0ff766a 100644 --- a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/ComponentTypeImpl.java +++ b/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/ComponentTypeImpl.java @@ -21,6 +21,8 @@ import java.util.IdentityHashMap; import java.util.List; import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Consumer; import java.util.function.Supplier; import com.mojang.serialization.Codec; @@ -96,9 +98,16 @@ public void handle(C component, AttachmentTarget target, E eventPayload) { } @Override - public Builder listen(TargetedEvent event, Class targetClass, Component.EventListener handler) { + public Builder listen(TargetedEvent event, Class targetClass, BiConsumer handler) { return this.listen(event, targetClass, (component, attachmentTarget, eventPayload) -> - handler.handle(component, attachmentTarget) + handler.accept(component, attachmentTarget) + ); + } + + @Override + public Builder listen(TargetedEvent event, Class targetClass, Consumer handler) { + return this.listen(event, targetClass, (component, attachmentTarget, eventPayload) -> + handler.accept(component) ); } @@ -110,9 +119,16 @@ public Builder listen(TargetedEvent event, Component.EventHandle } @Override - public Builder listen(TargetedEvent event, Component.EventListener handler) { + public Builder listen(TargetedEvent event, BiConsumer handler) { + return this.listen(event, (component, attachmentTarget, eventPayload) -> + handler.accept(component, attachmentTarget) + ); + } + + @Override + public Builder listen(TargetedEvent event, Consumer handler) { return this.listen(event, (component, attachmentTarget, eventPayload) -> - handler.handle(component, attachmentTarget) + handler.accept(component) ); } diff --git a/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/ComponentTestMod.java b/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/ComponentTestMod.java index e252ceed6a..3670702620 100644 --- a/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/ComponentTestMod.java +++ b/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/ComponentTestMod.java @@ -35,6 +35,8 @@ public class ComponentTestMod implements ModInitializer { builder.listen(ComponentEvents.ENTITY_LOAD, CreeperEntity.class, CreeperColor::onLoad); // Not using the context object builder.listen(ComponentEvents.ENTITY_UNLOAD, CreeperEntity.class, CreeperColor::onUnload); + // Not using the context object or the attachment target + builder.listen(ComponentEvents.ENTITY_UNLOAD, CreeperEntity.class, CreeperColor::onLoad2); builder.initializer(CreeperColor::new); }); diff --git a/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/CreeperColor.java b/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/CreeperColor.java index c7194be05c..b89c3ddcb5 100644 --- a/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/CreeperColor.java +++ b/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/CreeperColor.java @@ -30,7 +30,12 @@ void onLoad(CreeperEntity creeper, ServerWorld world) { ComponentTestMod.LOGGER.info("Creeper with color {} loaded at {}", this, creeper.getBlockPos()); } + void onUnload(CreeperEntity creeper) { ComponentTestMod.LOGGER.info("Creeper with color {} unloaded at {}", this, creeper.getBlockPos()); } + + void onLoad2() { + ComponentTestMod.LOGGER.info("Creeper with color {} loaded", this); + } } From d2e0ee9120f6bdc3c58a328740f287ff36fcff7e Mon Sep 17 00:00:00 2001 From: forgetmenot <149003152+forgetmenot13579@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:33:57 -0700 Subject: [PATCH 3/4] - Fix checkstyle --- .../build.gradle | 0 .../fabric/api/component}/v1/api/Component.java | 2 +- .../api/component}/v1/api/ComponentEvents.java | 4 +--- .../api/component}/v1/api/ComponentType.java | 4 ++-- .../api/component}/v1/api/TargetedEvent.java | 4 ++-- .../component}/v1/impl/ComponentTypeImpl.java | 14 +++++++------- .../component}/v1/impl/TargetedEventImpl.java | 16 +++++++--------- .../assets/fabric-components-api-v1/icon.png | Bin .../fabric-components-api-v1.mixins.json | 0 .../src/main/resources/fabric.mod.json | 0 .../test/component}/ComponentTestMod.java | 6 +++--- .../fabric/test/component}/CreeperColor.java | 5 ++--- .../src/testmod/resources/fabric.mod.json | 6 +++--- gradle.properties | 2 +- settings.gradle | 2 +- 15 files changed, 30 insertions(+), 35 deletions(-) rename {fabric-components-api-v1 => fabric-component-api-v1}/build.gradle (100%) rename {fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components => fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component}/v1/api/Component.java (94%) rename {fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components => fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component}/v1/api/ComponentEvents.java (97%) rename {fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components => fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component}/v1/api/ComponentType.java (95%) rename {fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components => fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component}/v1/api/TargetedEvent.java (91%) rename {fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components => fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component}/v1/impl/ComponentTypeImpl.java (92%) rename {fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components => fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component}/v1/impl/TargetedEventImpl.java (82%) rename {fabric-components-api-v1 => fabric-component-api-v1}/src/main/resources/assets/fabric-components-api-v1/icon.png (100%) rename {fabric-components-api-v1 => fabric-component-api-v1}/src/main/resources/fabric-components-api-v1.mixins.json (100%) rename {fabric-components-api-v1 => fabric-component-api-v1}/src/main/resources/fabric.mod.json (100%) rename {fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components => fabric-component-api-v1/src/testmod/java/net/fabricmc/fabric/test/component}/ComponentTestMod.java (90%) rename {fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components => fabric-component-api-v1/src/testmod/java/net/fabricmc/fabric/test/component}/CreeperColor.java (92%) rename {fabric-components-api-v1 => fabric-component-api-v1}/src/testmod/resources/fabric.mod.json (67%) diff --git a/fabric-components-api-v1/build.gradle b/fabric-component-api-v1/build.gradle similarity index 100% rename from fabric-components-api-v1/build.gradle rename to fabric-component-api-v1/build.gradle diff --git a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/Component.java b/fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/api/Component.java similarity index 94% rename from fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/Component.java rename to fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/api/Component.java index 7cf52da831..f3ca450bc0 100644 --- a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/Component.java +++ b/fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/api/Component.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.api.components.v1.api; +package net.fabricmc.fabric.api.component.v1.api; import net.fabricmc.fabric.api.attachment.v1.AttachmentTarget; diff --git a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentEvents.java b/fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/api/ComponentEvents.java similarity index 97% rename from fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentEvents.java rename to fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/api/ComponentEvents.java index 93d37105ff..5604c080fa 100644 --- a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentEvents.java +++ b/fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/api/ComponentEvents.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.api.components.v1.api; +package net.fabricmc.fabric.api.component.v1.api; import net.minecraft.entity.Entity; import net.minecraft.entity.EquipmentSlot; @@ -36,10 +36,8 @@ public final class ComponentEvents { event.accept(livingEntity, new EquipmentChangeEvent(equipmentSlot, previousStack, currentStack))); private ComponentEvents() { - } public record EquipmentChangeEvent(EquipmentSlot equipmentSlot, ItemStack previousStack, ItemStack currentStack) { - } } diff --git a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentType.java b/fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/api/ComponentType.java similarity index 95% rename from fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentType.java rename to fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/api/ComponentType.java index 80527a2531..b1033c6a4e 100644 --- a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/ComponentType.java +++ b/fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/api/ComponentType.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.api.components.v1.api; +package net.fabricmc.fabric.api.component.v1.api; import java.util.List; import java.util.function.BiConsumer; @@ -25,7 +25,7 @@ import net.fabricmc.fabric.api.attachment.v1.AttachmentRegistry; import net.fabricmc.fabric.api.attachment.v1.AttachmentTarget; import net.fabricmc.fabric.api.attachment.v1.AttachmentType; -import net.fabricmc.fabric.api.components.v1.impl.ComponentTypeImpl; +import net.fabricmc.fabric.api.component.v1.impl.ComponentTypeImpl; public interface ComponentType> extends AttachmentType { static > ComponentType create(Identifier identifier) { diff --git a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/TargetedEvent.java b/fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/api/TargetedEvent.java similarity index 91% rename from fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/TargetedEvent.java rename to fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/api/TargetedEvent.java index 99b7c9953e..379c7aab4c 100644 --- a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/api/TargetedEvent.java +++ b/fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/api/TargetedEvent.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package net.fabricmc.fabric.api.components.v1.api; +package net.fabricmc.fabric.api.component.v1.api; import java.util.function.BiConsumer; import java.util.function.Function; import net.fabricmc.fabric.api.attachment.v1.AttachmentTarget; -import net.fabricmc.fabric.api.components.v1.impl.TargetedEventImpl; +import net.fabricmc.fabric.api.component.v1.impl.TargetedEventImpl; import net.fabricmc.fabric.api.event.Event; public interface TargetedEvent { diff --git a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/ComponentTypeImpl.java b/fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/impl/ComponentTypeImpl.java similarity index 92% rename from fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/ComponentTypeImpl.java rename to fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/impl/ComponentTypeImpl.java index c5c0ff766a..eca787c87f 100644 --- a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/ComponentTypeImpl.java +++ b/fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/impl/ComponentTypeImpl.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.api.components.v1.impl; +package net.fabricmc.fabric.api.component.v1.impl; import java.util.ArrayList; import java.util.Collections; @@ -33,11 +33,11 @@ import net.fabricmc.fabric.api.attachment.v1.AttachmentRegistry; import net.fabricmc.fabric.api.attachment.v1.AttachmentTarget; import net.fabricmc.fabric.api.attachment.v1.AttachmentType; -import net.fabricmc.fabric.api.components.v1.api.Component; -import net.fabricmc.fabric.api.components.v1.api.ComponentType; -import net.fabricmc.fabric.api.components.v1.api.TargetedEvent; +import net.fabricmc.fabric.api.component.v1.api.Component; +import net.fabricmc.fabric.api.component.v1.api.ComponentType; +import net.fabricmc.fabric.api.component.v1.api.TargetedEvent; -public final class ComponentTypeImpl> implements ComponentType { +public final class ComponentTypeImpl> implements ComponentType { private final AttachmentType attachmentType; private final Map, List>> eventHandlers = new IdentityHashMap<>(); @@ -133,8 +133,8 @@ public Builder listen(TargetedEvent event, Consumer handler) } public ComponentTypeImpl buildAndRegister(Identifier id) { - var attachmentType = this.attachmentBuilder.buildAndRegister(id); - var type = new ComponentTypeImpl<>(attachmentType); + AttachmentType attachmentType = this.attachmentBuilder.buildAndRegister(id); + ComponentTypeImpl type = new ComponentTypeImpl<>(attachmentType); this.eventHandlers.forEach((event, list) -> { type.eventHandlers.put(event, List.copyOf(list)); diff --git a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/TargetedEventImpl.java b/fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/impl/TargetedEventImpl.java similarity index 82% rename from fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/TargetedEventImpl.java rename to fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/impl/TargetedEventImpl.java index ceed3e4c13..fa0adc3260 100644 --- a/fabric-components-api-v1/src/main/java/net/fabricmc/fabric/api/components/v1/impl/TargetedEventImpl.java +++ b/fabric-component-api-v1/src/main/java/net/fabricmc/fabric/api/component/v1/impl/TargetedEventImpl.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.api.components.v1.impl; +package net.fabricmc.fabric.api.component.v1.impl; import java.util.ArrayList; import java.util.IdentityHashMap; @@ -22,9 +22,9 @@ import java.util.Map; import net.fabricmc.fabric.api.attachment.v1.AttachmentTarget; -import net.fabricmc.fabric.api.components.v1.api.Component; -import net.fabricmc.fabric.api.components.v1.api.ComponentType; -import net.fabricmc.fabric.api.components.v1.api.TargetedEvent; +import net.fabricmc.fabric.api.component.v1.api.Component; +import net.fabricmc.fabric.api.component.v1.api.ComponentType; +import net.fabricmc.fabric.api.component.v1.api.TargetedEvent; import net.fabricmc.fabric.api.event.Event; public class TargetedEventImpl implements TargetedEvent { @@ -33,7 +33,6 @@ public class TargetedEventImpl implements Targete private final List> componentTypes = new ArrayList<>(); private TargetedEventImpl() { - } public void addListener(ComponentType componentType) { @@ -45,16 +44,15 @@ public static TargetedEventImpl create(Eve return (TargetedEventImpl) INSTANCES.computeIfAbsent(event, e -> new TargetedEventImpl<>()); } - private > void invokeListenersForComponentType(ComponentType componentType, AttachmentTarget attachmentTarget, E eventPayload) { - var component = attachmentTarget.getAttached(componentType); + C component = attachmentTarget.getAttached(componentType); if (component == null && componentType.initializer() != null) { component = attachmentTarget.getAttachedOrCreate(componentType); } if (component != null) { - for (var handler : componentType.getEventHandlers(this)) { + for (Component.EventHandler handler : componentType.getEventHandlers(this)) { //noinspection unchecked,rawtypes ((Component.EventHandler) handler).handle(component, attachmentTarget, eventPayload); } @@ -63,7 +61,7 @@ private > void invokeListenersForComponent @Override public void invoke(A attachmentTarget, E eventContext) { - for (var componentType : this.componentTypes) { + for (ComponentType componentType : this.componentTypes) { this.invokeListenersForComponentType(componentType, attachmentTarget, eventContext); } } diff --git a/fabric-components-api-v1/src/main/resources/assets/fabric-components-api-v1/icon.png b/fabric-component-api-v1/src/main/resources/assets/fabric-components-api-v1/icon.png similarity index 100% rename from fabric-components-api-v1/src/main/resources/assets/fabric-components-api-v1/icon.png rename to fabric-component-api-v1/src/main/resources/assets/fabric-components-api-v1/icon.png diff --git a/fabric-components-api-v1/src/main/resources/fabric-components-api-v1.mixins.json b/fabric-component-api-v1/src/main/resources/fabric-components-api-v1.mixins.json similarity index 100% rename from fabric-components-api-v1/src/main/resources/fabric-components-api-v1.mixins.json rename to fabric-component-api-v1/src/main/resources/fabric-components-api-v1.mixins.json diff --git a/fabric-components-api-v1/src/main/resources/fabric.mod.json b/fabric-component-api-v1/src/main/resources/fabric.mod.json similarity index 100% rename from fabric-components-api-v1/src/main/resources/fabric.mod.json rename to fabric-component-api-v1/src/main/resources/fabric.mod.json diff --git a/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/ComponentTestMod.java b/fabric-component-api-v1/src/testmod/java/net/fabricmc/fabric/test/component/ComponentTestMod.java similarity index 90% rename from fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/ComponentTestMod.java rename to fabric-component-api-v1/src/testmod/java/net/fabricmc/fabric/test/component/ComponentTestMod.java index 3670702620..b8f814ffc1 100644 --- a/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/ComponentTestMod.java +++ b/fabric-component-api-v1/src/testmod/java/net/fabricmc/fabric/test/component/ComponentTestMod.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.test.components; +package net.fabricmc.fabric.test.component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,8 +23,8 @@ import net.minecraft.util.Identifier; import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.components.v1.api.ComponentEvents; -import net.fabricmc.fabric.api.components.v1.api.ComponentType; +import net.fabricmc.fabric.api.component.v1.api.ComponentEvents; +import net.fabricmc.fabric.api.component.v1.api.ComponentType; public class ComponentTestMod implements ModInitializer { public static final String MOD_ID = "fabric-components-api-v1-testmod"; diff --git a/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/CreeperColor.java b/fabric-component-api-v1/src/testmod/java/net/fabricmc/fabric/test/component/CreeperColor.java similarity index 92% rename from fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/CreeperColor.java rename to fabric-component-api-v1/src/testmod/java/net/fabricmc/fabric/test/component/CreeperColor.java index b89c3ddcb5..dddc1d592c 100644 --- a/fabric-components-api-v1/src/testmod/java/net/fabricmc/fabric/test/components/CreeperColor.java +++ b/fabric-component-api-v1/src/testmod/java/net/fabricmc/fabric/test/component/CreeperColor.java @@ -14,12 +14,12 @@ * limitations under the License. */ -package net.fabricmc.fabric.test.components; +package net.fabricmc.fabric.test.component; import net.minecraft.entity.mob.CreeperEntity; import net.minecraft.server.world.ServerWorld; -import net.fabricmc.fabric.api.components.v1.api.Component; +import net.fabricmc.fabric.api.component.v1.api.Component; public record CreeperColor(int r, int g, int b) implements Component { public CreeperColor() { @@ -30,7 +30,6 @@ void onLoad(CreeperEntity creeper, ServerWorld world) { ComponentTestMod.LOGGER.info("Creeper with color {} loaded at {}", this, creeper.getBlockPos()); } - void onUnload(CreeperEntity creeper) { ComponentTestMod.LOGGER.info("Creeper with color {} unloaded at {}", this, creeper.getBlockPos()); } diff --git a/fabric-components-api-v1/src/testmod/resources/fabric.mod.json b/fabric-component-api-v1/src/testmod/resources/fabric.mod.json similarity index 67% rename from fabric-components-api-v1/src/testmod/resources/fabric.mod.json rename to fabric-component-api-v1/src/testmod/resources/fabric.mod.json index 62c02c63a3..3b05f5e217 100644 --- a/fabric-components-api-v1/src/testmod/resources/fabric.mod.json +++ b/fabric-component-api-v1/src/testmod/resources/fabric.mod.json @@ -1,18 +1,18 @@ { "schemaVersion": 1, - "id": "fabric-components-api-v1-testmod", + "id": "fabric-component-api-v1-testmod", "name": "Fabric Components API (v1) Test Mod", "version": "1.0.0", "environment": "*", "license": "Apache-2.0", "depends": { "fabric-data-attachment-api-v1": "*", - "fabric-components-api-v1": "*", + "fabric-component-api-v1": "*", "fabric-lifecycle-events-v1": "*" }, "entrypoints": { "main": [ - "net.fabricmc.fabric.test.components.ComponentTestMod" + "net.fabricmc.fabric.test.component.ComponentTestMod" ] } } diff --git a/gradle.properties b/gradle.properties index 7377fb0af2..8e1dfb7fbe 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,7 @@ fabric-blockrenderlayer-v1-version=1.1.52 fabric-command-api-v1-version=1.2.49 fabric-command-api-v2-version=2.2.28 fabric-commands-v0-version=0.2.66 -fabric-components-api-v1-version=0.1.0 +fabric-component-api-v1-version=0.1.0 fabric-content-registries-v0-version=8.0.16 fabric-crash-report-info-v1-version=0.2.29 fabric-data-attachment-api-v1-version=1.1.28 diff --git a/settings.gradle b/settings.gradle index 88cf329c0a..ba288ab7fc 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,7 +22,7 @@ include 'fabric-block-view-api-v2' include 'fabric-blockrenderlayer-v1' include 'fabric-client-tags-api-v1' include 'fabric-command-api-v2' -include 'fabric-components-api-v1' +include 'fabric-component-api-v1' include 'fabric-content-registries-v0' include 'fabric-convention-tags-v2' include 'fabric-crash-report-info-v1' From f76f1f282e64e1e2c701a14a7c1880f417881778 Mon Sep 17 00:00:00 2001 From: forgetmenot <149003152+forgetmenot13579@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:07:56 -0700 Subject: [PATCH 4/4] - Fix checkstyle --- .../icon.png | Bin .../resources/fabric-components-api-v1.mixins.json | 10 ---------- 2 files changed, 10 deletions(-) rename fabric-component-api-v1/src/main/resources/assets/{fabric-components-api-v1 => fabric-component-api-v1}/icon.png (100%) delete mode 100644 fabric-component-api-v1/src/main/resources/fabric-components-api-v1.mixins.json diff --git a/fabric-component-api-v1/src/main/resources/assets/fabric-components-api-v1/icon.png b/fabric-component-api-v1/src/main/resources/assets/fabric-component-api-v1/icon.png similarity index 100% rename from fabric-component-api-v1/src/main/resources/assets/fabric-components-api-v1/icon.png rename to fabric-component-api-v1/src/main/resources/assets/fabric-component-api-v1/icon.png diff --git a/fabric-component-api-v1/src/main/resources/fabric-components-api-v1.mixins.json b/fabric-component-api-v1/src/main/resources/fabric-components-api-v1.mixins.json deleted file mode 100644 index 920ebb2ce4..0000000000 --- a/fabric-component-api-v1/src/main/resources/fabric-components-api-v1.mixins.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "required": true, - "package": "net.fabricmc.fabric.mixin.components", - "compatibilityLevel": "JAVA_17", - "mixins": [ - ], - "injectors": { - "defaultRequire": 1 - } -}