Update energy api
This commit is contained in:
parent
7e05b0da12
commit
a4a578917d
6 changed files with 21 additions and 11 deletions
|
@ -63,11 +63,13 @@ public class ItemCloakingDevice extends ItemTRArmour implements EnergyHolder {
|
|||
PlayerEntity player = (PlayerEntity) entityIn;
|
||||
|
||||
if (Energy.valid(stack)) {
|
||||
Energy.of(stack).use(usage, () -> player.setInvisible(true), () -> {
|
||||
if(Energy.of(stack).use(usage)){
|
||||
player.setInvisible(true);
|
||||
} else {
|
||||
if (!player.hasStatusEffect(StatusEffects.INVISIBILITY)) {
|
||||
player.setInvisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ public class ItemIndustrialChainsaw extends ItemChainsaw {
|
|||
return;
|
||||
}
|
||||
|
||||
Energy.of(stack).use(cost, () -> {
|
||||
if(Energy.of(stack).use(cost)){
|
||||
BlockState blockState = world.getBlockState(pos);
|
||||
if (blockState.getHardness(world, pos) == -1.0F) {
|
||||
return;
|
||||
|
@ -192,7 +192,7 @@ public class ItemIndustrialChainsaw extends ItemChainsaw {
|
|||
blockState.getBlock().afterBreak(world, (PlayerEntity) entityLiving, pos, blockState, world.getBlockEntity(pos), stack);
|
||||
world.setBlockState(pos, Blocks.AIR.getDefaultState());
|
||||
world.removeBlockEntity(pos);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,14 +121,14 @@ public class ItemIndustrialDrill extends ItemDrill {
|
|||
private void breakBlock(BlockPos pos, World world, PlayerEntity playerIn, ItemStack drill) {
|
||||
BlockState blockState = world.getBlockState(pos);
|
||||
|
||||
Energy.of(drill).use(cost, () -> {
|
||||
if(Energy.of(drill).use(cost)){
|
||||
ExternalPowerSystems.requestEnergyFromArmor(drill, playerIn);
|
||||
|
||||
blockState.getBlock().onBlockRemoved(blockState, world, pos, blockState, true);
|
||||
blockState.getBlock().afterBreak(world, playerIn, pos, blockState, world.getBlockEntity(pos), drill);
|
||||
world.setBlockState(pos, Blocks.AIR.getDefaultState());
|
||||
world.removeBlockEntity(pos);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldBreak(PlayerEntity playerIn, World worldIn, BlockPos originalPos, BlockPos pos) {
|
||||
|
|
|
@ -107,7 +107,9 @@ public class ItemOmniTool extends PickaxeItem implements EnergyHolder, ItemDurab
|
|||
|
||||
@Override
|
||||
public boolean postHit(ItemStack stack, LivingEntity entityliving, LivingEntity attacker) {
|
||||
Energy.of(stack).use(hitCost, () -> entityliving.damage(DamageSource.player((PlayerEntity) attacker), 8F));
|
||||
if(Energy.of(stack).use(hitCost)) {
|
||||
entityliving.damage(DamageSource.player((PlayerEntity) attacker), 8F);
|
||||
}
|
||||
ExternalPowerSystems.requestEnergyFromArmor(stack, entityliving);
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue