Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Exceptions and unexpected behavior related to HIDE_CAN_PLACE key #4137

Open
wants to merge 2 commits into
base: api-11
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
package org.spongepowered.common.data.provider.item.stack;

import net.minecraft.advancements.critereon.BlockPredicate;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.core.component.DataComponents;
import net.minecraft.util.Unit;
import net.minecraft.world.item.AdventureModePredicate;
Expand All @@ -34,12 +34,10 @@
import net.minecraft.world.item.enchantment.ItemEnchantments;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.api.data.Keys;
import org.spongepowered.common.accessor.world.item.AdventureModePredicateAccessor;
import org.spongepowered.common.accessor.world.item.enchantment.ItemEnchantmentsAccessor;
import org.spongepowered.common.data.provider.DataProviderRegistrator;

import java.util.Collections;
import java.util.List;

public final class HideFlagsItemStackData {

Expand All @@ -55,10 +53,10 @@ public static void register(final DataProviderRegistrator registrator) {
.set((h, v) -> h.update(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY, p -> new ItemAttributeModifiers(p.modifiers(), !v)))
.create(Keys.HIDE_CAN_DESTROY)
.get(h -> h.has(DataComponents.CAN_BREAK) && !h.get(DataComponents.CAN_BREAK).showInTooltip())
.set((h, v) -> h.set(DataComponents.CAN_BREAK, HideFlagsItemStackData.newAdventureModePredicate(h, !v)))
.set((h, v) -> h.set(DataComponents.CAN_BREAK, HideFlagsItemStackData.newAdventureModePredicate(h, DataComponents.CAN_BREAK, !v)))
.create(Keys.HIDE_CAN_PLACE)
.get(h -> h.has(DataComponents.CAN_PLACE_ON) && !h.get(DataComponents.CAN_BREAK).showInTooltip())
.set((h, v) -> h.set(DataComponents.CAN_PLACE_ON, HideFlagsItemStackData.newAdventureModePredicate(h, !v)))
.get(h -> h.has(DataComponents.CAN_PLACE_ON) && !h.get(DataComponents.CAN_PLACE_ON).showInTooltip())
.set((h, v) -> h.set(DataComponents.CAN_PLACE_ON, HideFlagsItemStackData.newAdventureModePredicate(h, DataComponents.CAN_PLACE_ON, !v)))
.create(Keys.HIDE_ENCHANTMENTS)
.get(h -> ((ItemEnchantmentsAccessor)h.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY)).accessor$showInTooltip())
.set((h, v) -> h.set(DataComponents.ENCHANTMENTS, HideFlagsItemStackData.newItemEnchantments(h, !v)))
Expand Down Expand Up @@ -86,10 +84,9 @@ public static void register(final DataProviderRegistrator registrator) {
// @formatter:on

@NotNull
private static AdventureModePredicate newAdventureModePredicate(final ItemStack h, final boolean showInTooltip) {
if (h.has(DataComponents.CAN_BREAK)) {
final List<BlockPredicate> $$0 = ((AdventureModePredicateAccessor) h.get(DataComponents.CAN_BREAK)).accessor$predicates();
return new AdventureModePredicate($$0, showInTooltip);
private static AdventureModePredicate newAdventureModePredicate(final ItemStack h, final DataComponentType<AdventureModePredicate> type, final boolean showInTooltip) {
if (h.has(type)) {
return h.get(type).withTooltip(showInTooltip);
}
return new AdventureModePredicate(Collections.emptyList(), showInTooltip);
}
Expand Down