Skip to content
Open
Show file tree
Hide file tree
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 @@ -28,6 +28,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Display;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.animal.Fox;
import net.minecraft.world.entity.animal.MushroomCow;
Expand Down Expand Up @@ -159,6 +160,13 @@ public static List<Generator> enumEntries(final Context context) {
"getSerializedName",
"sponge"
),
new EnumEntriesValidator<>(
"item.inventory.equipment",
"EquipmentConditions",
EquipmentSlotGroup.class,
"getSerializedName",
"sponge"
),
new EnumEntriesValidator<>(
"item.inventory.equipment",
"EquipmentGroups",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import net.minecraft.world.item.component.CustomModelData;
import net.minecraft.world.item.component.DamageResistant;
import net.minecraft.world.item.component.DeathProtection;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.item.component.ItemContainerContents;
import net.minecraft.world.item.component.ItemLore;
import net.minecraft.world.item.component.Unbreakable;
Expand All @@ -56,6 +57,7 @@
import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.type.ItemAction;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.attribute.ItemAttribute;
import org.spongepowered.api.item.ItemRarity;
import org.spongepowered.api.item.ItemType;
import org.spongepowered.api.item.inventory.Inventory;
Expand All @@ -82,7 +84,6 @@ private ItemStackData() {
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
// TODO DataComponents.SUSPICIOUS_STEW_EFFECTS
// TODO maybe DataComponents.ATTRIBUTE_MODIFIERS as keys?
// TODO DataComponents.BUNDLE_CONTENTS also check for Shulker Boxes? - removing the component prevents using the bundle
// TODO DataComponents.CONTAINER_LOOT for containers with loottable data, also for blockentity?
// TODO DataComponents.BLOCK_ENTITY_DATA maybe expose as raw DataContainer? (id MUST have block entity type)
Expand Down Expand Up @@ -367,6 +368,16 @@ public static void register(final DataProviderRegistrator registrator) {
return builder.build();
})
.deleteAndGet(ItemStackData::deleteAndTransactUseCooldown)
.create(Keys.ITEM_ATTRIBUTES)
.get(stack -> {
final var attributes = stack.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY).modifiers();
return attributes.isEmpty() ? null : (List<ItemAttribute>) (Object) List.copyOf(attributes);
})
.set((stack, v) -> {
final var attributes = (List<ItemAttributeModifiers.Entry>) (Object) List.copyOf(v);
stack.update(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY, p -> new ItemAttributeModifiers(attributes, p.showInTooltip()));
})
.resetOnDelete(List.of())
;
}
// @formatter:on
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* 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 org.spongepowered.common.entity.attribute;

import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import org.spongepowered.api.entity.attribute.AttributeModifier;
import org.spongepowered.api.entity.attribute.ItemAttribute;
import org.spongepowered.api.entity.attribute.type.AttributeType;
import org.spongepowered.api.item.inventory.equipment.EquipmentCondition;
import org.spongepowered.common.SpongeCommon;

import java.util.Objects;

public final class SpongeItemAttributeFactory implements ItemAttribute.Factory {

@Override
public ItemAttribute of(final AttributeType type, final AttributeModifier modifier, final EquipmentCondition condition) {
Objects.requireNonNull(type, "type");
Objects.requireNonNull(modifier, "modifier");
Objects.requireNonNull(condition, "condition");
return (ItemAttribute) (Object) new ItemAttributeModifiers.Entry(
SpongeCommon.vanillaRegistry(Registries.ATTRIBUTE).wrapAsHolder((Attribute) type),
(net.minecraft.world.entity.ai.attributes.AttributeModifier) (Object) modifier,
(EquipmentSlotGroup) (Object) condition
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.effect.ForwardingViewer;
import org.spongepowered.api.effect.VanishState;
import org.spongepowered.api.entity.attribute.ItemAttribute;
import org.spongepowered.api.event.EventListenerRegistration;
import org.spongepowered.api.event.cause.entity.damage.DamageStepType;
import org.spongepowered.api.event.cause.entity.damage.source.DamageSource;
Expand Down Expand Up @@ -123,6 +124,7 @@
import org.spongepowered.common.data.manipulator.MutableDataManipulatorFactory;
import org.spongepowered.common.data.value.SpongeValueFactory;
import org.spongepowered.common.effect.SpongeCustomForwardingViewer;
import org.spongepowered.common.entity.attribute.SpongeItemAttributeFactory;
import org.spongepowered.common.entity.effect.SpongeVanishState;
import org.spongepowered.common.event.SpongeEventListenerRegistration;
import org.spongepowered.common.event.cause.entity.damage.SpongeDamageStepType;
Expand Down Expand Up @@ -287,6 +289,7 @@ public void registerDefaultFactories() {
.registerFactory(NaturalSpawner.Factory.class, new SpongeNaturalSpawnerFactory())
.registerFactory(ScoreFormat.Factory.class, new SpongeScoreFormatFactory())
.registerFactory(ToolRule.Factory.class, new SpongeToolRuleFactory())
.registerFactory(ItemAttribute.Factory.class, new SpongeItemAttributeFactory())
.registerFactory(ItemAction.Factory.class, new SpongeItemActionFactory())
.registerFactory(PortalLogic.Factory.class, new SpongePortalLogicFactory())
.registerFactory(RecipeInput.Factory.class, new SpongeRecipeInputFactory())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import net.minecraft.world.damagesource.DamageScaling;
import net.minecraft.world.entity.Display;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
Expand Down Expand Up @@ -183,6 +184,7 @@ private void loadEnumRegistries() {
this.automaticName(RegistryTypes.DYE_COLOR, DyeColor.values());
this.automaticName(RegistryTypes.DOOR_HINGE, DoorHingeSide.values());
this.automaticName(RegistryTypes.DRIPSTONE_SEGMENT, DripstoneThickness.values());
this.automaticName(RegistryTypes.EQUIPMENT_CONDITION, EquipmentSlotGroup.values());
this.automaticName(RegistryTypes.EQUIPMENT_GROUP, EquipmentSlot.Type.values());
this.automaticName(RegistryTypes.EQUIPMENT_TYPE, EquipmentSlot.values());
this.automaticName(RegistryTypes.FOX_TYPE, Fox.Variant.values());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* 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 org.spongepowered.common.mixin.api.minecraft.world.item.component;

import net.minecraft.core.Holder;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import org.spongepowered.api.entity.attribute.AttributeModifier;
import org.spongepowered.api.entity.attribute.ItemAttribute;
import org.spongepowered.api.entity.attribute.type.AttributeType;
import org.spongepowered.api.item.inventory.equipment.EquipmentCondition;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(ItemAttributeModifiers.Entry.class)
@Implements(@Interface(iface = ItemAttribute.class, prefix = "attribute$"))
public abstract class ItemAttributeModifiers_EntryMixin_API implements ItemAttribute {

@Shadow @Final private Holder<Attribute> attribute;
@Shadow @Final private net.minecraft.world.entity.ai.attributes.AttributeModifier modifier;
@Shadow @Final private EquipmentSlotGroup slot;

@Override
public AttributeType type() {
return (AttributeType) this.attribute.value();
}

@Intrinsic
public AttributeModifier attribute$modifier() {
return (AttributeModifier) (Object) this.modifier;
}

@Override
public EquipmentCondition condition() {
return (EquipmentCondition) (Object) this.slot;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* 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 org.spongepowered.common.mixin.inventory.api.world.entity;

import net.kyori.adventure.text.Component;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.EquipmentSlotGroup;
import org.spongepowered.api.item.inventory.equipment.EquipmentCondition;
import org.spongepowered.api.item.inventory.equipment.EquipmentType;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Objects;

@Mixin(EquipmentSlotGroup.class)
public abstract class EquipmentSlotGroupMixin_Inventory_API implements EquipmentCondition {

@Shadow public abstract boolean shadow$test(EquipmentSlot slot);

@Shadow @Final private String key;

private Component api$component;

@Inject(method = "<init>(Ljava/lang/String;IILjava/lang/String;Ljava/util/function/Predicate;)V", at = @At("RETURN"))
private void api$setComponent(final CallbackInfo ci) {
this.api$component = Component.translatable("item.modifiers." + this.key);
}

@Override
public Component asComponent() {
return this.api$component;
}

@Override
public boolean test(final EquipmentType type) {
return this.shadow$test((EquipmentSlot) (Object) Objects.requireNonNull(type, "type"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
package org.spongepowered.common.mixin.inventory.api.world.entity;

import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.EquipmentSlotGroup;
import org.spongepowered.api.item.inventory.equipment.EquipmentCondition;
import org.spongepowered.api.item.inventory.equipment.EquipmentGroup;
import org.spongepowered.api.item.inventory.equipment.EquipmentType;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -40,4 +42,9 @@ public abstract class EquipmentSlotMixin_Inventory_API implements EquipmentType
public EquipmentGroup group() {
return (EquipmentGroup) (Object) this.type;
}

@Override
public EquipmentCondition condition() {
return (EquipmentCondition) (Object) EquipmentSlotGroup.bySlot((EquipmentSlot) (Object) this);
}
}
1 change: 1 addition & 0 deletions src/mixins/resources/mixins.sponge.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@
"minecraft.world.item.ToolMaterialMixin_API",
"minecraft.world.item.alchemy.PotionMixin_API",
"minecraft.world.item.component.FireworkExplosionMixin_API",
"minecraft.world.item.component.ItemAttributeModifiers_EntryMixin_API",
"minecraft.world.item.component.Tool_RuleMixin_API",
"minecraft.world.item.consume_effects.ApplyStatusEffectsConsumeEffectMixin_API",
"minecraft.world.item.consume_effects.ClearAllStatusEffectsConsumeEffectMixin_API",
Expand Down
1 change: 1 addition & 0 deletions src/mixins/resources/mixins.sponge.inventory.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"api.world.CompoundContainerMixin_Carrier_Inventory_API",
"api.world.ContainerMixin_Inventory_API",
"api.world.entity.EquipmentSlot_TypeMixin_Inventory_API",
"api.world.entity.EquipmentSlotGroupMixin_Inventory_API",
"api.world.entity.EquipmentSlotMixin_Inventory_API",
"api.world.entity.animal.horse.AbstractHorseMixin_Carrier_Inventory_API",
"api.world.entity.monster.PillagerMixin_Carrier_Inventory_API",
Expand Down
Loading
Loading