feat(D-01): delegate DataDrivenBondageItem lifecycle to components

Override onEquipped(), onUnequipped(), and canUnequip() in
DataDrivenBondageItem to delegate to the item's ComponentHolder.
The canUnequip() override preserves the existing lock check from
AbstractV2BondageItem via super.canUnequip().

Add a static getComponent() helper for external code to retrieve
a typed component from any data-driven item stack.
This commit is contained in:
NotEvil
2026-04-14 01:47:19 +02:00
parent a781dad597
commit 3a1f401ccf

View File

@@ -4,6 +4,9 @@ import com.tiedup.remake.v2.BodyRegionV2;
import com.tiedup.remake.v2.bondage.IV2BondageEquipment;
import com.tiedup.remake.v2.bondage.V2BondageItems;
import com.tiedup.remake.v2.bondage.capability.V2EquipmentHelper;
import com.tiedup.remake.v2.bondage.component.ComponentHolder;
import com.tiedup.remake.v2.bondage.component.ComponentType;
import com.tiedup.remake.v2.bondage.component.IItemComponent;
import com.tiedup.remake.v2.bondage.items.AbstractV2BondageItem;
import java.util.List;
import java.util.Map;
@@ -257,6 +260,53 @@ public class DataDrivenBondageItem extends AbstractV2BondageItem {
return Component.literal(def.displayName());
}
// ===== COMPONENT LIFECYCLE DELEGATION =====
@Override
public void onEquipped(ItemStack stack, LivingEntity entity) {
ComponentHolder holder = DataDrivenItemRegistry.getComponents(stack);
if (holder != null) {
holder.onEquipped(stack, entity);
}
}
@Override
public void onUnequipped(ItemStack stack, LivingEntity entity) {
ComponentHolder holder = DataDrivenItemRegistry.getComponents(stack);
if (holder != null) {
holder.onUnequipped(stack, entity);
}
}
@Override
public boolean canUnequip(ItemStack stack, LivingEntity entity) {
ComponentHolder holder = DataDrivenItemRegistry.getComponents(stack);
if (holder != null && holder.blocksUnequip(stack, entity)) {
return false;
}
return super.canUnequip(stack, entity);
}
/**
* Get a specific component from a data-driven item stack.
*
* @param stack the ItemStack to inspect
* @param type the component type to look up
* @param clazz the expected component class
* @param <T> the component type
* @return the component, or null if the item is not data-driven or lacks this component
*/
@Nullable
public static <T extends IItemComponent> T getComponent(
ItemStack stack,
ComponentType type,
Class<T> clazz
) {
ComponentHolder holder = DataDrivenItemRegistry.getComponents(stack);
if (holder == null) return null;
return holder.get(type, clazz);
}
// ===== FACTORY =====
/**