feature/d01-component-system #5
@@ -1,16 +1,20 @@
|
||||
package com.tiedup.remake.v2.bondage.component;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.tiedup.remake.items.base.ILockable;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Component: lockable behavior for data-driven items.
|
||||
* Delegates lock checks to ILockable on the item.
|
||||
*
|
||||
* <p>Stores the per-item lock resistance parsed from JSON. The lock check
|
||||
* itself is NOT done here because {@code AbstractV2BondageItem.canUnequip()}
|
||||
* already delegates to {@code ILockable.isLocked()} -- duplicating it in
|
||||
* {@code blocksUnequip()} would be redundant.</p>
|
||||
*
|
||||
* <p>Consumers retrieve the per-item lock resistance via
|
||||
* {@link com.tiedup.remake.v2.bondage.datadriven.DataDrivenBondageItem#getItemLockResistance(net.minecraft.world.item.ItemStack)}.</p>
|
||||
*
|
||||
* JSON config:
|
||||
* {@code "lockable": true} or {@code "lockable": {"lock_resistance": 300}}
|
||||
* {@code "lockable": {}} or {@code "lockable": {"lock_resistance": 300}}
|
||||
*/
|
||||
public class LockableComponent implements IItemComponent {
|
||||
|
||||
@@ -28,15 +32,12 @@ public class LockableComponent implements IItemComponent {
|
||||
return new LockableComponent(resistance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the per-item lock resistance value parsed from JSON.
|
||||
*
|
||||
* @return lock resistance (always >= 0 after RISK-003 clamping)
|
||||
*/
|
||||
public int getLockResistance() {
|
||||
return lockResistance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blocksUnequip(ItemStack stack, LivingEntity entity) {
|
||||
if (stack.getItem() instanceof ILockable lockable) {
|
||||
return lockable.isLocked(stack);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ 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.component.LockableComponent;
|
||||
import com.tiedup.remake.v2.bondage.component.ResistanceComponent;
|
||||
import com.tiedup.remake.v2.bondage.items.AbstractV2BondageItem;
|
||||
import java.util.List;
|
||||
@@ -323,6 +324,30 @@ public class DataDrivenBondageItem extends AbstractV2BondageItem {
|
||||
return holder.get(type, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get per-item lock resistance from the LockableComponent, if present.
|
||||
*
|
||||
* <p>Returns the component's JSON-configured value if the stack has a
|
||||
* LockableComponent, otherwise falls back to the global config value
|
||||
* from {@link com.tiedup.remake.core.SettingsAccessor#getPadlockResistance}.</p>
|
||||
*
|
||||
* @param stack the ItemStack to inspect
|
||||
* @return lock resistance value for this specific item
|
||||
*/
|
||||
public static int getItemLockResistance(ItemStack stack) {
|
||||
LockableComponent comp = getComponent(
|
||||
stack,
|
||||
ComponentType.LOCKABLE,
|
||||
LockableComponent.class
|
||||
);
|
||||
if (comp != null) {
|
||||
return comp.getLockResistance();
|
||||
}
|
||||
return com.tiedup.remake.core.SettingsAccessor.getPadlockResistance(
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
// ===== FACTORY =====
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user