diff --git a/patches/net/minecraft/core/component/DataComponentMap.java.patch b/patches/net/minecraft/core/component/DataComponentMap.java.patch new file mode 100644 index 0000000000..dfa82944a8 --- /dev/null +++ b/patches/net/minecraft/core/component/DataComponentMap.java.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/core/component/DataComponentMap.java ++++ b/net/minecraft/core/component/DataComponentMap.java +@@ -126,7 +_,7 @@ + }; + } + +- public static class Builder { ++ public static class Builder implements net.neoforged.neoforge.common.extensions.IDataComponentMapBuilderExtensions { + private final Reference2ObjectMap, Object> map = new Reference2ObjectArrayMap<>(); + + Builder() { diff --git a/patches/net/minecraft/world/item/Item.java.patch b/patches/net/minecraft/world/item/Item.java.patch index d8d60d264e..f590b6c697 100644 --- a/patches/net/minecraft/world/item/Item.java.patch +++ b/patches/net/minecraft/world/item/Item.java.patch @@ -125,10 +125,11 @@ } public ItemStack getDefaultInstance() { -@@ -335,6 +_,32 @@ +@@ -335,13 +_,40 @@ return this.requiredFeatures; } +- public static class Properties { + // NEO START + private Object renderProperties; + @@ -155,10 +156,10 @@ + } + // END NEO + - public static class Properties { ++ public static class Properties implements net.neoforged.neoforge.common.extensions.IItemPropertiesExtensions { private static final Interner COMPONENT_INTERNER = Interners.newStrongInterner(); @Nullable -@@ -342,6 +_,7 @@ + private DataComponentMap.Builder components; @Nullable Item craftingRemainingItem; FeatureFlagSet requiredFeatures = FeatureFlags.VANILLA_SET; diff --git a/patches/net/minecraft/world/level/block/entity/BlockEntity.java.patch b/patches/net/minecraft/world/level/block/entity/BlockEntity.java.patch index 24ce191966..bd6dfcb556 100644 --- a/patches/net/minecraft/world/level/block/entity/BlockEntity.java.patch +++ b/patches/net/minecraft/world/level/block/entity/BlockEntity.java.patch @@ -52,12 +52,10 @@ } public boolean triggerEvent(int p_58889_, int p_58890_) { -@@ -228,6 +_,27 @@ - - public BlockEntityType getType() { +@@ -230,6 +_,27 @@ return this.type; -+ } -+ + } + + @Override + public CompoundTag getPersistentData() { + if (this.customPersistentData == null) @@ -77,6 +75,24 @@ + public final T removeData(net.neoforged.neoforge.attachment.AttachmentType type) { + setChanged(); + return super.removeData(type); - } - ++ } ++ @Deprecated + public void setBlockState(BlockState p_155251_) { + this.blockState = p_155251_; +@@ -298,5 +_,15 @@ + T get(DataComponentType p_338658_); + + T getOrDefault(DataComponentType p_338573_, T p_338734_); ++ ++ // Neo: Utility for modded component types, to remove the need to invoke '.value()' ++ @Nullable ++ default T get(java.util.function.Supplier> componentType) { ++ return get(componentType.get()); ++ } ++ ++ default T getOrDefault(java.util.function.Supplier> componentType, T value) { ++ return getOrDefault(componentType.get(), value); ++ } + } + } diff --git a/src/main/java/net/neoforged/neoforge/common/MutableDataComponentHolder.java b/src/main/java/net/neoforged/neoforge/common/MutableDataComponentHolder.java index 7ed3a9553c..154d811606 100644 --- a/src/main/java/net/neoforged/neoforge/common/MutableDataComponentHolder.java +++ b/src/main/java/net/neoforged/neoforge/common/MutableDataComponentHolder.java @@ -9,6 +9,8 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; import net.minecraft.core.component.DataComponentHolder; +import net.minecraft.core.component.DataComponentMap; +import net.minecraft.core.component.DataComponentPatch; import net.minecraft.core.component.DataComponentType; import org.jetbrains.annotations.Nullable; @@ -74,16 +76,38 @@ default T remove(Supplier> componen } /** - * Copes a data component from {@code src} into {@code target} + * Copies all data components from {@code src} + * + * @implNote This will clear any components if the requested {@code src} holder does not contain a matching value. */ - static void copyFrom(DataComponentHolder src, MutableDataComponentHolder target, DataComponentType componentType) { - target.set(componentType, src.get(componentType)); + default void copyFrom(DataComponentHolder src, DataComponentType... componentTypes) { + for (var componentType : componentTypes) { + copyFrom(componentType, src); + } } /** - * Copes a data component from {@code src} into {@code target} + * Copies all data components from {@code src} + * + * @implNote This will clear any components if the requested {@code src} holder does not contain a matching value. */ - static void copyFrom(DataComponentHolder src, MutableDataComponentHolder target, Supplier> componentType) { - copyFrom(src, target, componentType.get()); + default void copyFrom(DataComponentHolder src, Supplier>... componentTypes) { + for (var componentType : componentTypes) { + copyFrom(componentType.get(), src); + } + } + + /** + * Applies a set of component changes to this stack. + */ + void applyComponents(DataComponentPatch patch); + + /** + * Applies a set of component changes to this stack. + */ + void applyComponents(DataComponentMap components); + + private void copyFrom(DataComponentType componentType, DataComponentHolder src) { + set(componentType, src.get(componentType)); } } diff --git a/src/main/java/net/neoforged/neoforge/common/crafting/DataComponentIngredient.java b/src/main/java/net/neoforged/neoforge/common/crafting/DataComponentIngredient.java index a4a727bb8d..3c0e59fa2c 100644 --- a/src/main/java/net/neoforged/neoforge/common/crafting/DataComponentIngredient.java +++ b/src/main/java/net/neoforged/neoforge/common/crafting/DataComponentIngredient.java @@ -9,6 +9,7 @@ import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import java.util.Arrays; +import java.util.function.Supplier; import net.minecraft.core.Holder; import net.minecraft.core.HolderSet; import net.minecraft.core.component.DataComponentMap; @@ -110,6 +111,13 @@ public static DataComponentIngredient of(boolean strict, DataComponentType DataComponentIngredient of(boolean strict, Supplier> type, T value, ItemLike... items) { + return of(strict, type.get(), value, items); + } + /** * Creates a new ingredient matching any item from the list, containing the given components */ diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IDataComponentHolderExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/IDataComponentHolderExtension.java index 0fd93eecff..930f6a5490 100644 --- a/src/main/java/net/neoforged/neoforge/common/extensions/IDataComponentHolderExtension.java +++ b/src/main/java/net/neoforged/neoforge/common/extensions/IDataComponentHolderExtension.java @@ -8,7 +8,6 @@ import java.util.function.Supplier; import net.minecraft.core.component.DataComponentHolder; import net.minecraft.core.component.DataComponentType; -import net.neoforged.neoforge.common.MutableDataComponentHolder; import org.jetbrains.annotations.Nullable; public interface IDataComponentHolderExtension { @@ -29,18 +28,4 @@ default T getOrDefault(Supplier> ty default boolean has(Supplier> type) { return self().has(type.get()); } - - /** - * Copies a data component from {@code this} component holder into the {@code target} component holder. - */ - default void copyFrom(MutableDataComponentHolder target, DataComponentType componentType) { - MutableDataComponentHolder.copyFrom(self(), target, componentType); - } - - /** - * Copies a data component from {@code this} component holder into the {@code target} component holder. - */ - default void copyFrom(MutableDataComponentHolder target, Supplier> componentType) { - MutableDataComponentHolder.copyFrom(self(), target, componentType); - } } diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IDataComponentMapBuilderExtensions.java b/src/main/java/net/neoforged/neoforge/common/extensions/IDataComponentMapBuilderExtensions.java new file mode 100644 index 0000000000..7fbbfab31d --- /dev/null +++ b/src/main/java/net/neoforged/neoforge/common/extensions/IDataComponentMapBuilderExtensions.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) NeoForged and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package net.neoforged.neoforge.common.extensions; + +import java.util.function.Supplier; +import net.minecraft.core.component.DataComponentMap; +import net.minecraft.core.component.DataComponentType; +import org.jetbrains.annotations.Nullable; + +public interface IDataComponentMapBuilderExtensions { + private DataComponentMap.Builder self() { + return (DataComponentMap.Builder) this; + } + + default DataComponentMap.Builder set(Supplier> componentType, @Nullable T value) { + return self().set(componentType.get(), value); + } +} diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IItemPropertiesExtensions.java b/src/main/java/net/neoforged/neoforge/common/extensions/IItemPropertiesExtensions.java new file mode 100644 index 0000000000..1cf6003397 --- /dev/null +++ b/src/main/java/net/neoforged/neoforge/common/extensions/IItemPropertiesExtensions.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) NeoForged and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package net.neoforged.neoforge.common.extensions; + +import java.util.function.Supplier; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.world.item.Item; + +public interface IItemPropertiesExtensions { + private Item.Properties self() { + return (Item.Properties) this; + } + + default Item.Properties component(Supplier> componentType, T value) { + return self().component(componentType.get(), value); + } +} diff --git a/src/main/java/net/neoforged/neoforge/fluids/FluidStack.java b/src/main/java/net/neoforged/neoforge/fluids/FluidStack.java index 16d0cac55f..6209b22e03 100644 --- a/src/main/java/net/neoforged/neoforge/fluids/FluidStack.java +++ b/src/main/java/net/neoforged/neoforge/fluids/FluidStack.java @@ -386,6 +386,7 @@ public String toString() { * Sets a data component. */ @Nullable + @Override public T set(DataComponentType type, @Nullable T component) { return this.components.set(type, component); } @@ -394,6 +395,7 @@ public T set(DataComponentType type, @Nullable T component) { * Removes a data component. */ @Nullable + @Override public T remove(DataComponentType type) { return this.components.remove(type); } @@ -401,6 +403,7 @@ public T remove(DataComponentType type) { /** * Applies a set of component changes to this stack. */ + @Override public void applyComponents(DataComponentPatch patch) { this.components.applyPatch(patch); } @@ -408,6 +411,7 @@ public void applyComponents(DataComponentPatch patch) { /** * Applies a set of component changes to this stack. */ + @Override public void applyComponents(DataComponentMap components) { this.components.setAll(components); }