Search in sources :

Example 1 with NuclearExplosion

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;
}
Also used : TileNuclearBomb(net.reikeb.electrona.tileentities.TileNuclearBomb) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) CollisionContext(net.minecraft.world.phys.shapes.CollisionContext) Items(net.minecraft.world.item.Items) Direction(net.minecraft.core.Direction) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) ServerLevel(net.minecraft.server.level.ServerLevel) ElectronaUtils(net.reikeb.electrona.utils.ElectronaUtils) NuclearExplosion(net.reikeb.electrona.world.NuclearExplosion) ServerPlayer(net.minecraft.server.level.ServerPlayer) BlockGetter(net.minecraft.world.level.BlockGetter) LootContext(net.minecraft.world.level.storage.loot.LootContext) Gamerules(net.reikeb.electrona.world.Gamerules) net.minecraft.world.level.block(net.minecraft.world.level.block) BombFallingEntity(net.reikeb.electrona.entity.BombFallingEntity) StateDefinition(net.minecraft.world.level.block.state.StateDefinition) BlockHitResult(net.minecraft.world.phys.BlockHitResult) InteractionResult(net.minecraft.world.InteractionResult) TileNuclearBomb(net.reikeb.electrona.tileentities.TileNuclearBomb) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Explosion(net.minecraft.world.level.Explosion) Material(net.minecraft.world.level.material.Material) Player(net.minecraft.world.entity.player.Player) CustomShapes(net.reikeb.electrona.misc.vm.CustomShapes) List(java.util.List) BlockPos(net.minecraft.core.BlockPos) BlockPlaceContext(net.minecraft.world.item.context.BlockPlaceContext) DirectionProperty(net.minecraft.world.level.block.state.properties.DirectionProperty) MenuProvider(net.minecraft.world.MenuProvider) InteractionHand(net.minecraft.world.InteractionHand) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) Collections(java.util.Collections) NetworkHooks(net.minecraftforge.network.NetworkHooks) NuclearExplosion(net.reikeb.electrona.world.NuclearExplosion) ServerPlayer(net.minecraft.server.level.ServerPlayer) ItemStack(net.minecraft.world.item.ItemStack) MenuProvider(net.minecraft.world.MenuProvider) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 2 with NuclearExplosion

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;
}
Also used : NuclearExplosion(net.reikeb.electrona.world.NuclearExplosion) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent)

Example 3 with NuclearExplosion

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);
            }
        }
    }
}
Also used : NuclearExplosion(net.reikeb.electrona.world.NuclearExplosion) Random(java.util.Random) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos)

Aggregations

NuclearExplosion (net.reikeb.electrona.world.NuclearExplosion)3 Random (java.util.Random)2 BlockPos (net.minecraft.core.BlockPos)2 Level (net.minecraft.world.level.Level)2 Collections (java.util.Collections)1 List (java.util.List)1 Direction (net.minecraft.core.Direction)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 InteractionHand (net.minecraft.world.InteractionHand)1 InteractionResult (net.minecraft.world.InteractionResult)1 MenuProvider (net.minecraft.world.MenuProvider)1 FallingBlockEntity (net.minecraft.world.entity.item.FallingBlockEntity)1 Player (net.minecraft.world.entity.player.Player)1 ItemStack (net.minecraft.world.item.ItemStack)1 Items (net.minecraft.world.item.Items)1 BlockPlaceContext (net.minecraft.world.item.context.BlockPlaceContext)1 BlockGetter (net.minecraft.world.level.BlockGetter)1 Explosion (net.minecraft.world.level.Explosion)1