use of net.reikeb.electrona.world.NuclearExplosion in project Electrona-Project by Max094Reikeb.
the class NuclearBomb method use.
@Override
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
if (!worldIn.isClientSide) {
BlockEntity tile = worldIn.getBlockEntity(pos);
if (player.isCrouching() && player.getItemInHand(handIn).isEmpty()) {
player.setItemInHand(handIn, new ItemStack(this, 1));
worldIn.removeBlock(pos, true);
return InteractionResult.SUCCESS;
} else if (player.getItemInHand(handIn).getItem() == Items.FLINT_AND_STEEL) {
if (tile instanceof TileNuclearBomb) {
if (((TileNuclearBomb) tile).isCharged() && worldIn.getLevelData().getGameRules().getBoolean(Gamerules.DO_NUCLEAR_BOMBS_EXPLODE)) {
if (!player.isCreative()) {
player.getItemInHand(handIn).hurtAndBreak(1, player, (p_220287_1_) -> {
p_220287_1_.broadcastBreakEvent(handIn);
});
}
new NuclearExplosion(worldIn, pos.getX(), pos.getY(), pos.getZ(), ((TileNuclearBomb) tile).getNuclearCharge());
return InteractionResult.SUCCESS;
}
}
} else {
if (tile instanceof TileNuclearBomb) {
NetworkHooks.openGui((ServerPlayer) player, (MenuProvider) tile, pos);
return InteractionResult.SUCCESS;
}
}
}
return InteractionResult.SUCCESS;
}
use of net.reikeb.electrona.world.NuclearExplosion in project Electrona-Project by Max094Reikeb.
the class ExplodeCommand method nuclearExplode.
private static int nuclearExplode(CommandSourceStack source, ServerPlayer user, int power) throws CommandSyntaxException {
if (power <= 0) {
throw ERROR_NEGATIVE.create(power);
} else {
new NuclearExplosion(user.level, (int) user.getX(), (int) user.getY(), (int) user.getZ(), power);
source.sendSuccess(new TranslatableComponent("command.electrona.nuclear_explosion_success"), true);
}
return power;
}
use of net.reikeb.electrona.world.NuclearExplosion in project Electrona-Project by Max094Reikeb.
the class NuclearFunction method nuclearGeneration.
/**
* Functionment of the Nuclear Generator
*
* @param tileEntity The Tile Entity of the Nuclear Generator Controller
* @param tileCooler The Tile Entity of the Cooler below the Nuclear Generator Controller
* @param slotCooler The slot of the Cooler
* @param slotGenerator The slot of the Nuclear Generator Controller
* @param electronicPower The energy inside the Nuclear Generator Controller
* @param temperature The temperature of the Nuclear Generator
* @param waterLevel The water level of the tank inside the Cooler
*/
public static void nuclearGeneration(TileNuclearGeneratorController tileEntity, BlockEntity tileCooler, ItemStack slotCooler, ItemStack slotGenerator, double electronicPower, int temperature, int waterLevel) {
if ((slotCooler.getItem() == ItemInit.URANIUM_BAR.get()) || (slotCooler.getItem() == ItemInit.URANIUM_DUAL_BAR.get()) || (slotCooler.getItem() == ItemInit.URANIUM_QUAD_BAR.get())) {
if ((tileEntity.getTileData().getBoolean("powered")) && (tileEntity.getTileData().getBoolean("UBIn"))) {
if (slotCooler.hurt(1, new Random(), null)) {
slotCooler.shrink(1);
slotCooler.setDamageValue(0);
}
if (slotGenerator.hurt(1, new Random(), null)) {
slotGenerator.shrink(1);
slotGenerator.setDamageValue(0);
}
if (temperature <= 500) {
tileEntity.getTileData().putInt("temperature", (temperature + 1));
if (electronicPower <= 9950) {
tileEntity.getTileData().putDouble("ElectronicPower", (electronicPower + 2.5));
} else if ((electronicPower > 9950) && (electronicPower < 10000)) {
tileEntity.getTileData().putDouble("ElectronicPower", (electronicPower + 0.05));
}
if (waterLevel >= 500) {
FluidFunction.drainWater(tileCooler, 40);
}
} else if (temperature <= 1500) {
tileEntity.getTileData().putInt("temperature", (temperature + 5));
if (electronicPower <= 9900) {
tileEntity.getTileData().putDouble("ElectronicPower", (electronicPower + 5));
} else if ((electronicPower > 9900) && (electronicPower <= 9950)) {
tileEntity.getTileData().putDouble("ElectronicPower", (electronicPower + 2.5));
} else if ((electronicPower > 9950) && (electronicPower < 10000)) {
tileEntity.getTileData().putDouble("ElectronicPower", (electronicPower + 0.05));
}
if (waterLevel >= 800) {
FluidFunction.drainWater(tileCooler, 50);
}
} else if (temperature <= 2400) {
tileEntity.getTileData().putInt("temperature", (temperature + 8));
if (electronicPower <= 9500) {
tileEntity.getTileData().putDouble("ElectronicPower", (electronicPower + 25));
} else if ((electronicPower > 9500) && (electronicPower <= 9900)) {
tileEntity.getTileData().putDouble("ElectronicPower", (electronicPower + 5));
} else if ((electronicPower > 9900) && (electronicPower <= 9950)) {
tileEntity.getTileData().putDouble("ElectronicPower", (electronicPower + 2.5));
} else if ((electronicPower > 9950) && (electronicPower < 10000)) {
tileEntity.getTileData().putDouble("ElectronicPower", (electronicPower + 0.05));
}
if (waterLevel >= 1000) {
FluidFunction.drainWater(tileCooler, 80);
}
} else {
if (waterLevel >= 1000) {
FluidFunction.drainWater(tileCooler, 80);
} else {
tileEntity.getTileData().putInt("temperature", (temperature + 5));
}
if (electronicPower <= 9500) {
tileEntity.getTileData().putDouble("ElectronicPower", (electronicPower + 25));
} else if ((electronicPower > 9500) && (electronicPower <= 9900)) {
tileEntity.getTileData().putDouble("ElectronicPower", (electronicPower + 5));
} else if ((electronicPower > 9900) && (electronicPower <= 9950)) {
tileEntity.getTileData().putDouble("ElectronicPower", (electronicPower + 2.5));
} else if ((electronicPower > 9950) && (electronicPower < 10000)) {
tileEntity.getTileData().putDouble("ElectronicPower", (electronicPower + 0.05));
}
}
if ((waterLevel < 800) && (temperature >= 2000)) {
tileEntity.getTileData().putBoolean("alert", true);
}
if ((waterLevel < 800) && (temperature >= 2800)) {
if (tileEntity.getLevel() == null)
return;
Level world = tileEntity.getLevel();
BlockPos pos = tileEntity.getBlockPos();
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
world.setBlock(tileCooler.getBlockPos(), Blocks.AIR.defaultBlockState(), 3);
new NuclearExplosion(world, pos.getX(), pos.getY(), pos.getZ(), 20);
if ((Math.random() < 0.45) && world.getLevelData().getGameRules().getBoolean(Gamerules.DO_BLACK_HOLES_EXIST)) {
world.setBlock(pos, BlockInit.SINGULARITY.get().defaultBlockState(), 3);
advancementInevitableFunction(world, pos);
}
}
if ((waterLevel > 400) && (temperature >= 2000)) {
FluidFunction.drainWater(tileCooler, 40);
tileEntity.getTileData().putInt("temperature", (temperature - 10));
} else if ((waterLevel > 300) && (temperature >= 1000)) {
FluidFunction.drainWater(tileCooler, 30);
tileEntity.getTileData().putInt("temperature", (temperature - 5));
} else if ((waterLevel > 200) && (temperature >= 50)) {
FluidFunction.drainWater(tileCooler, 20);
tileEntity.getTileData().putInt("temperature", (int) (temperature - 2.5));
} else if ((waterLevel >= 1) && (temperature >= 1)) {
FluidFunction.drainWater(tileCooler, 1);
tileEntity.getTileData().putInt("temperature", temperature - 1);
}
}
}
}
Aggregations