feat(D-01): implement LockableComponent with configurable lock resistance
This commit is contained in:
@@ -1,12 +1,42 @@
|
||||
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.
|
||||
*
|
||||
* JSON config:
|
||||
* {@code "lockable": true} or {@code "lockable": {"lock_resistance": 300}}
|
||||
*/
|
||||
public class LockableComponent implements IItemComponent {
|
||||
|
||||
private LockableComponent() {}
|
||||
private final int lockResistance;
|
||||
|
||||
private LockableComponent(int lockResistance) {
|
||||
this.lockResistance = lockResistance;
|
||||
}
|
||||
|
||||
public static IItemComponent fromJson(JsonObject config) {
|
||||
return new LockableComponent();
|
||||
int resistance = 250; // default
|
||||
if (config != null && config.has("lock_resistance")) {
|
||||
resistance = config.get("lock_resistance").getAsInt();
|
||||
}
|
||||
return new LockableComponent(resistance);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user