fix(D-01): wire LockableComponent.lockResistance via getItemLockResistance() (BUG-003)
- Remove redundant blocksUnequip() from LockableComponent since AbstractV2BondageItem.canUnequip() already checks ILockable.isLocked() - Add DataDrivenBondageItem.getItemLockResistance(ItemStack) that reads the per-item lock resistance from the LockableComponent, falling back to the global config value when absent
This commit is contained in:
@@ -1,16 +1,20 @@
|
|||||||
package com.tiedup.remake.v2.bondage.component;
|
package com.tiedup.remake.v2.bondage.component;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
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.
|
* 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:
|
* JSON config:
|
||||||
* {@code "lockable": true} or {@code "lockable": {"lock_resistance": 300}}
|
* {@code "lockable": {}} or {@code "lockable": {"lock_resistance": 300}}
|
||||||
*/
|
*/
|
||||||
public class LockableComponent implements IItemComponent {
|
public class LockableComponent implements IItemComponent {
|
||||||
|
|
||||||
@@ -28,15 +32,12 @@ public class LockableComponent implements IItemComponent {
|
|||||||
return new LockableComponent(resistance);
|
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() {
|
public int getLockResistance() {
|
||||||
return lockResistance;
|
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.ComponentHolder;
|
||||||
import com.tiedup.remake.v2.bondage.component.ComponentType;
|
import com.tiedup.remake.v2.bondage.component.ComponentType;
|
||||||
import com.tiedup.remake.v2.bondage.component.IItemComponent;
|
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.component.ResistanceComponent;
|
||||||
import com.tiedup.remake.v2.bondage.items.AbstractV2BondageItem;
|
import com.tiedup.remake.v2.bondage.items.AbstractV2BondageItem;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -323,6 +324,30 @@ public class DataDrivenBondageItem extends AbstractV2BondageItem {
|
|||||||
return holder.get(type, clazz);
|
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 =====
|
// ===== FACTORY =====
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user