mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Pegasus amulet now defaults to a half charge rather than needing to fully recharge it after crafting
This commit is contained in:
parent
97496239b4
commit
b728416c17
2 changed files with 15 additions and 2 deletions
|
@ -22,6 +22,10 @@ public interface ChargeableItem {
|
|||
return setEnergy(stack, getMaxCharge());
|
||||
}
|
||||
|
||||
default ItemStack recharge(ItemStack stack, float amount) {
|
||||
return setEnergy(stack, getEnergy(stack) + amount);
|
||||
}
|
||||
|
||||
default boolean canCharge(ItemStack stack) {
|
||||
return isChargable() && getEnergy(stack) < getMaxCharge();
|
||||
}
|
||||
|
@ -41,12 +45,16 @@ public interface ChargeableItem {
|
|||
}
|
||||
}
|
||||
|
||||
static int getDefaultCharge(ItemStack stack) {
|
||||
return stack.getItem() instanceof ChargeableItem c ? c.getDefaultCharge() : 0;
|
||||
}
|
||||
|
||||
static float getEnergy(ItemStack stack) {
|
||||
return stack.hasNbt() && stack.getNbt().contains("energy") ? stack.getNbt().getFloat("energy") : (stack.getItem() instanceof ChargeableItem c) ? c.getDefaultCharge() : 0;
|
||||
return stack.hasNbt() && stack.getNbt().contains("energy") ? stack.getNbt().getFloat("energy") : getDefaultCharge(stack);
|
||||
}
|
||||
|
||||
static ItemStack setEnergy(ItemStack stack, float energy) {
|
||||
if (energy <= 0) {
|
||||
if (energy <= 0 && getDefaultCharge(stack) <= 0) {
|
||||
stack.removeSubNbt("energy");
|
||||
} else {
|
||||
stack.getOrCreateNbt().putFloat("energy", energy);
|
||||
|
|
|
@ -25,6 +25,11 @@ public class PegasusAmuletItem extends AmuletItem implements ItemTracker.Trackab
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultCharge() {
|
||||
return getMaxCharge() / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
|
||||
if (entity.world.getTime() % 6 == 0 && entity instanceof LivingEntity living && isApplicable(living)) {
|
||||
|
|
Loading…
Reference in a new issue