Search in sources :

Example 1 with TileEntityTurbineRotor

use of mekanism.generators.common.tile.turbine.TileEntityTurbineRotor in project Mekanism by mekanism.

the class TurbineValidator method postcheck.

@Override
public FormationResult postcheck(TurbineMultiblockData structure, Set<BlockPos> innerNodes, Long2ObjectMap<IChunk> chunkMap) {
    if (structure.length() % 2 != 1 || structure.width() % 2 != 1) {
        return FormationResult.fail(GeneratorsLang.TURBINE_INVALID_EVEN_LENGTH);
    }
    int centerX = structure.getMinPos().getX() + (structure.length() - 1) / 2;
    int centerZ = structure.getMinPos().getZ() + (structure.width() - 1) / 2;
    BlockPos complex = null;
    Set<BlockPos> turbines = new ObjectOpenHashSet<>();
    Set<BlockPos> dispersers = new ObjectOpenHashSet<>();
    Set<BlockPos> coils = new ObjectOpenHashSet<>();
    Set<BlockPos> condensers = new ObjectOpenHashSet<>();
    // Scan for complex
    for (BlockPos pos : innerNodes) {
        TileEntity tile = WorldUtils.getTileEntity(world, chunkMap, pos);
        if (tile instanceof TileEntityRotationalComplex) {
            if (complex != null || pos.getX() != centerX || pos.getZ() != centerZ) {
                return FormationResult.fail(GeneratorsLang.TURBINE_INVALID_BAD_COMPLEX, pos);
            }
            structure.internalLocations.add(pos);
            complex = pos;
        } else if (tile instanceof TileEntityTurbineRotor) {
            if (pos.getX() != centerX || pos.getZ() != centerZ) {
                return FormationResult.fail(GeneratorsLang.TURBINE_INVALID_BAD_ROTOR, pos);
            }
            turbines.add(pos);
        } else if (tile instanceof TileEntityPressureDisperser) {
            dispersers.add(pos);
        } else if (tile instanceof TileEntityElectromagneticCoil) {
            coils.add(pos);
        } else if (tile instanceof TileEntitySaturatingCondenser) {
            condensers.add(pos);
        }
    }
    // Terminate if complex doesn't exist
    if (complex == null) {
        return FormationResult.fail(GeneratorsLang.TURBINE_INVALID_MISSING_COMPLEX);
    }
    int rotors = complex.getY() - structure.getMinPos().getY() + 1;
    int innerRadius = (Math.min(structure.length(), structure.width()) - 3) / 2;
    if (innerRadius < rotors / 4) {
        return FormationResult.fail(GeneratorsLang.TURBINE_INVALID_TOO_NARROW);
    }
    // Terminate if coils don't exist
    if (coils.isEmpty()) {
        return FormationResult.fail(GeneratorsLang.TURBINE_INVALID_MISSING_COILS);
    }
    BlockPos.Mutable mutablePos = new BlockPos.Mutable();
    // Make sure a flat, horizontal plane of dispersers exists within the multiblock around the complex
    for (int x = complex.getX() - innerRadius; x <= complex.getX() + innerRadius; x++) {
        for (int z = complex.getZ() - innerRadius; z <= complex.getZ() + innerRadius; z++) {
            if (x != centerX || z != centerZ) {
                mutablePos.set(x, complex.getY(), z);
                TileEntityPressureDisperser tile = WorldUtils.getTileEntity(TileEntityPressureDisperser.class, world, chunkMap, mutablePos);
                if (tile == null) {
                    return FormationResult.fail(GeneratorsLang.TURBINE_INVALID_MISSING_DISPERSER, mutablePos);
                }
                dispersers.remove(mutablePos);
            }
        }
    }
    // If any dispersers were not processed, they're in the wrong place
    if (!dispersers.isEmpty()) {
        return FormationResult.fail(GeneratorsLang.TURBINE_INVALID_MALFORMED_DISPERSERS);
    }
    // Make sure all condensers are in proper locations
    for (BlockPos coord : condensers) {
        if (coord.getY() <= complex.getY()) {
            return FormationResult.fail(GeneratorsLang.TURBINE_INVALID_CONDENSER_BELOW_COMPLEX, coord);
        }
    }
    structure.condensers = condensers.size();
    int turbineHeight = 0;
    int blades = 0;
    // Starting from the complex, walk down and count the number of rotors/blades in the structure
    for (int y = complex.getY() - 1; y > structure.getMinPos().getY(); y--) {
        mutablePos.set(centerX, y, centerZ);
        TileEntityTurbineRotor rotor = WorldUtils.getTileEntity(TileEntityTurbineRotor.class, world, chunkMap, mutablePos);
        if (rotor == null) {
            // Not a contiguous set of rotors
            return FormationResult.fail(GeneratorsLang.TURBINE_INVALID_ROTORS_NOT_CONTIGUOUS);
        }
        turbineHeight++;
        blades += rotor.getHousedBlades();
        structure.internalLocations.add(rotor.getBlockPos());
        turbines.remove(mutablePos);
    }
    // If there are any rotors left over, they are in the wrong place in the structure
    if (!turbines.isEmpty()) {
        return FormationResult.fail(GeneratorsLang.TURBINE_INVALID_BAD_ROTORS);
    }
    // Update the structure with number of blades found on rotors
    structure.blades = blades;
    BlockPos startCoord = complex.relative(Direction.UP);
    if (WorldUtils.getTileEntity(TileEntityElectromagneticCoil.class, world, chunkMap, startCoord) != null) {
        structure.coils = FormationProtocol.explore(startCoord, coord -> WorldUtils.getTileEntity(TileEntityElectromagneticCoil.class, world, chunkMap, coord) != null);
    }
    if (coils.size() > structure.coils) {
        return FormationResult.fail(GeneratorsLang.TURBINE_INVALID_MALFORMED_COILS);
    }
    for (BlockPos coord : structure.locations) {
        if (WorldUtils.getTileEntity(TileEntityTurbineVent.class, world, chunkMap, coord) != null) {
            if (coord.getY() < complex.getY()) {
                return FormationResult.fail(GeneratorsLang.TURBINE_INVALID_VENT_BELOW_COMPLEX, coord);
            }
            structure.vents++;
        }
    }
    structure.lowerVolume = structure.length() * structure.width() * turbineHeight;
    structure.complex = complex;
    return FormationResult.SUCCESS;
}
Also used : VoxelCuboid(mekanism.common.lib.math.voxel.VoxelCuboid) TileEntityTurbineRotor(mekanism.generators.common.tile.turbine.TileEntityTurbineRotor) TileEntitySaturatingCondenser(mekanism.generators.common.tile.turbine.TileEntitySaturatingCondenser) Direction(net.minecraft.util.Direction) CasingType(mekanism.common.lib.multiblock.FormationProtocol.CasingType) MekanismBlockTypes(mekanism.common.registries.MekanismBlockTypes) Block(net.minecraft.block.Block) BlockType(mekanism.common.content.blocktype.BlockType) FormationResult(mekanism.common.lib.multiblock.FormationProtocol.FormationResult) BlockState(net.minecraft.block.BlockState) TileEntityElectromagneticCoil(mekanism.generators.common.tile.turbine.TileEntityElectromagneticCoil) TileEntityRotationalComplex(mekanism.generators.common.tile.turbine.TileEntityRotationalComplex) TileEntityTurbineVent(mekanism.generators.common.tile.turbine.TileEntityTurbineVent) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) FormationProtocol(mekanism.common.lib.multiblock.FormationProtocol) CuboidStructureValidator(mekanism.common.lib.multiblock.CuboidStructureValidator) ObjectOpenHashSet(it.unimi.dsi.fastutil.objects.ObjectOpenHashSet) GeneratorsLang(mekanism.generators.common.GeneratorsLang) TileEntityPressureDisperser(mekanism.common.tile.TileEntityPressureDisperser) WorldUtils(mekanism.common.util.WorldUtils) IChunk(net.minecraft.world.chunk.IChunk) TileEntity(net.minecraft.tileentity.TileEntity) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) GeneratorsBlockTypes(mekanism.generators.common.registries.GeneratorsBlockTypes) TileEntityPressureDisperser(mekanism.common.tile.TileEntityPressureDisperser) ObjectOpenHashSet(it.unimi.dsi.fastutil.objects.ObjectOpenHashSet) TileEntityTurbineVent(mekanism.generators.common.tile.turbine.TileEntityTurbineVent) TileEntityElectromagneticCoil(mekanism.generators.common.tile.turbine.TileEntityElectromagneticCoil) TileEntity(net.minecraft.tileentity.TileEntity) TileEntitySaturatingCondenser(mekanism.generators.common.tile.turbine.TileEntitySaturatingCondenser) TileEntityRotationalComplex(mekanism.generators.common.tile.turbine.TileEntityRotationalComplex) BlockPos(net.minecraft.util.math.BlockPos) TileEntityTurbineRotor(mekanism.generators.common.tile.turbine.TileEntityTurbineRotor)

Example 2 with TileEntityTurbineRotor

use of mekanism.generators.common.tile.turbine.TileEntityTurbineRotor in project Mekanism by mekanism.

the class RenderIndustrialTurbine method render.

@Override
protected void render(TileEntityTurbineCasing tile, float partialTick, MatrixStack matrix, IRenderTypeBuffer renderer, int light, int overlayLight, IProfiler profiler) {
    if (tile.isMaster()) {
        TurbineMultiblockData multiblock = tile.getMultiblock();
        if (multiblock.isFormed() && multiblock.complex != null && multiblock.renderLocation != null) {
            BlockPos pos = tile.getBlockPos();
            BlockPos complexPos = multiblock.complex;
            IVertexBuilder buffer = RenderTurbineRotor.INSTANCE.model.getBuffer(renderer);
            profiler.push(GeneratorsProfilerConstants.TURBINE_ROTOR);
            while (true) {
                complexPos = complexPos.below();
                TileEntityTurbineRotor rotor = WorldUtils.getTileEntity(TileEntityTurbineRotor.class, tile.getLevel(), complexPos);
                if (rotor == null) {
                    break;
                }
                matrix.pushPose();
                matrix.translate(complexPos.getX() - pos.getX(), complexPos.getY() - pos.getY(), complexPos.getZ() - pos.getZ());
                RenderTurbineRotor.INSTANCE.render(rotor, matrix, buffer, MekanismRenderer.FULL_SKY_LIGHT, overlayLight);
                matrix.popPose();
            }
            profiler.pop();
            if (!multiblock.gasTank.isEmpty() && multiblock.length() > 0) {
                int height = multiblock.lowerVolume / (multiblock.length() * multiblock.width());
                if (height >= 1) {
                    GasRenderData data = new GasRenderData(multiblock.gasTank.getStack());
                    data.location = multiblock.renderLocation;
                    data.height = height;
                    data.length = multiblock.length();
                    data.width = multiblock.width();
                    int glow = data.calculateGlowLight(MekanismRenderer.FULL_SKY_LIGHT);
                    matrix.pushPose();
                    matrix.translate(data.location.getX() - pos.getX(), data.location.getY() - pos.getY(), data.location.getZ() - pos.getZ());
                    Model3D gasModel = ModelRenderer.getModel(data, 1);
                    MekanismRenderer.renderObject(gasModel, matrix, renderer.getBuffer(Atlases.translucentCullBlockSheet()), data.getColorARGB(multiblock.prevSteamScale), glow, overlayLight, getFaceDisplay(data, gasModel));
                    matrix.popPose();
                }
            }
        }
    }
}
Also used : GasRenderData(mekanism.client.render.data.ChemicalRenderData.GasRenderData) Model3D(mekanism.client.render.MekanismRenderer.Model3D) TurbineMultiblockData(mekanism.generators.common.content.turbine.TurbineMultiblockData) BlockPos(net.minecraft.util.math.BlockPos) TileEntityTurbineRotor(mekanism.generators.common.tile.turbine.TileEntityTurbineRotor) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder)

Example 3 with TileEntityTurbineRotor

use of mekanism.generators.common.tile.turbine.TileEntityTurbineRotor in project Mekanism by mekanism.

the class BlockTurbineRotor method use.

@Nonnull
@Override
@Deprecated
public ActionResultType use(@Nonnull BlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull PlayerEntity player, @Nonnull Hand hand, @Nonnull BlockRayTraceResult hit) {
    TileEntityTurbineRotor tile = WorldUtils.getTileEntity(TileEntityTurbineRotor.class, world, pos);
    if (tile == null) {
        return ActionResultType.PASS;
    } else if (world.isClientSide) {
        return genericClientActivated(player, hand);
    } else if (tile.tryWrench(state, player, hand, hit) != WrenchResult.PASS) {
        return ActionResultType.SUCCESS;
    }
    ItemStack stack = player.getItemInHand(hand);
    if (!player.isShiftKeyDown()) {
        if (!stack.isEmpty() && stack.getItem() instanceof ItemTurbineBlade) {
            if (tile.addBlade(true)) {
                if (!player.isCreative()) {
                    stack.shrink(1);
                }
            }
        }
    } else if (stack.isEmpty()) {
        if (tile.removeBlade()) {
            if (!player.isCreative()) {
                player.setItemInHand(hand, GeneratorsItems.TURBINE_BLADE.getItemStack());
                player.inventory.setChanged();
            }
        }
    } else if (stack.getItem() instanceof ItemTurbineBlade) {
        if (stack.getCount() < stack.getMaxStackSize()) {
            if (tile.removeBlade()) {
                if (!player.isCreative()) {
                    stack.grow(1);
                    player.inventory.setChanged();
                }
            }
        }
    }
    return ActionResultType.PASS;
}
Also used : ItemTurbineBlade(mekanism.generators.common.item.ItemTurbineBlade) ItemStack(net.minecraft.item.ItemStack) TileEntityTurbineRotor(mekanism.generators.common.tile.turbine.TileEntityTurbineRotor) Nonnull(javax.annotation.Nonnull)

Aggregations

TileEntityTurbineRotor (mekanism.generators.common.tile.turbine.TileEntityTurbineRotor)3 BlockPos (net.minecraft.util.math.BlockPos)2 IVertexBuilder (com.mojang.blaze3d.vertex.IVertexBuilder)1 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)1 ObjectOpenHashSet (it.unimi.dsi.fastutil.objects.ObjectOpenHashSet)1 Set (java.util.Set)1 Nonnull (javax.annotation.Nonnull)1 Model3D (mekanism.client.render.MekanismRenderer.Model3D)1 GasRenderData (mekanism.client.render.data.ChemicalRenderData.GasRenderData)1 BlockType (mekanism.common.content.blocktype.BlockType)1 VoxelCuboid (mekanism.common.lib.math.voxel.VoxelCuboid)1 CuboidStructureValidator (mekanism.common.lib.multiblock.CuboidStructureValidator)1 FormationProtocol (mekanism.common.lib.multiblock.FormationProtocol)1 CasingType (mekanism.common.lib.multiblock.FormationProtocol.CasingType)1 FormationResult (mekanism.common.lib.multiblock.FormationProtocol.FormationResult)1 MekanismBlockTypes (mekanism.common.registries.MekanismBlockTypes)1 TileEntityPressureDisperser (mekanism.common.tile.TileEntityPressureDisperser)1 WorldUtils (mekanism.common.util.WorldUtils)1 GeneratorsLang (mekanism.generators.common.GeneratorsLang)1 TurbineMultiblockData (mekanism.generators.common.content.turbine.TurbineMultiblockData)1