Search in sources :

Example 1 with TileEntityFissionFuelAssembly

use of mekanism.generators.common.tile.fission.TileEntityFissionFuelAssembly in project Mekanism by mekanism.

the class FissionReactorValidator method postcheck.

@Override
public FormationResult postcheck(FissionReactorMultiblockData structure, Set<BlockPos> innerNodes, Long2ObjectMap<IChunk> chunkMap) {
    Map<AssemblyPos, FuelAssembly> map = new HashMap<>();
    Set<BlockPos> fuelAssemblyCoords = new HashSet<>();
    int assemblyCount = 0, surfaceArea = 0;
    for (BlockPos coord : innerNodes) {
        TileEntity tile = WorldUtils.getTileEntity(world, chunkMap, coord);
        AssemblyPos pos = new AssemblyPos(coord.getX(), coord.getZ());
        FuelAssembly assembly = map.get(pos);
        if (tile instanceof TileEntityFissionFuelAssembly) {
            if (assembly == null) {
                map.put(pos, new FuelAssembly(coord, false));
            } else {
                assembly.fuelAssemblies.add(coord);
            }
            assemblyCount++;
            // compute surface area
            surfaceArea += 6;
            for (Direction side : EnumUtils.DIRECTIONS) {
                if (fuelAssemblyCoords.contains(coord.relative(side))) {
                    surfaceArea -= 2;
                }
            }
            fuelAssemblyCoords.add(coord);
            structure.internalLocations.add(coord);
        } else if (tile instanceof TileEntityControlRodAssembly) {
            if (assembly == null) {
                map.put(pos, new FuelAssembly(coord, true));
            } else if (assembly.controlRodAssembly != null) {
                // only one control rod per assembly
                return FormationResult.fail(GeneratorsLang.FISSION_INVALID_EXTRA_CONTROL_ROD, coord);
            } else {
                assembly.controlRodAssembly = coord;
            }
        }
    }
    // require at least one fuel assembly
    if (map.isEmpty()) {
        return FormationResult.fail(GeneratorsLang.FISSION_INVALID_MISSING_FUEL_ASSEMBLY);
    }
    for (Entry<AssemblyPos, FuelAssembly> entry : map.entrySet()) {
        FuelAssembly assembly = entry.getValue();
        FormationResult result = assembly.validate(entry.getKey());
        if (!result.isFormed()) {
            return result;
        }
        structure.assemblies.add(assembly.build());
    }
    structure.fuelAssemblies = assemblyCount;
    structure.surfaceArea = surfaceArea;
    return FormationResult.SUCCESS;
}
Also used : TileEntityControlRodAssembly(mekanism.generators.common.tile.fission.TileEntityControlRodAssembly) HashMap(java.util.HashMap) TileEntityFissionFuelAssembly(mekanism.generators.common.tile.fission.TileEntityFissionFuelAssembly) FormationResult(mekanism.common.lib.multiblock.FormationProtocol.FormationResult) Direction(net.minecraft.util.Direction) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFissionFuelAssembly(mekanism.generators.common.tile.fission.TileEntityFissionFuelAssembly) BlockPos(net.minecraft.util.math.BlockPos) HashSet(java.util.HashSet)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 FormationResult (mekanism.common.lib.multiblock.FormationProtocol.FormationResult)1 TileEntityControlRodAssembly (mekanism.generators.common.tile.fission.TileEntityControlRodAssembly)1 TileEntityFissionFuelAssembly (mekanism.generators.common.tile.fission.TileEntityFissionFuelAssembly)1 TileEntity (net.minecraft.tileentity.TileEntity)1 Direction (net.minecraft.util.Direction)1 BlockPos (net.minecraft.util.math.BlockPos)1