Update energy api

This commit is contained in:
modmuss50 2019-09-16 23:11:56 +01:00
parent 7e05b0da12
commit a4a578917d
6 changed files with 21 additions and 11 deletions

View file

@ -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);
}
});
}
}
}
}

View file

@ -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);
});
}
}
}

View file

@ -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) {

View file

@ -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;
}