本篇教程由作者设定未经允许禁止转载。

提前说明,本人的Java水平非常差,我是仿照看C++的方式强硬理解戴森球的源码,如果发现有错误,请一定要在评论区指出。

首先,反编译GalaxySpace-1.7.10-1.1.16p-GTNH.jar

找到如下代码

package galaxyspace.core.tile.machine.multi;

import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti;
import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
import com.gtnewhorizon.structurelib.structure.IStructureElement;
import com.gtnewhorizon.structurelib.structure.StructureDefinition;
import com.gtnewhorizon.structurelib.structure.StructureUtility;
import galaxyspace.GalaxySpace;
import galaxyspace.core.config.GSConfigCore;
import galaxyspace.core.register.GSBlocks;
import galaxyspace.core.register.GSItems;
import gregtech.api.GregTech_API;
import gregtech.api.enums.Materials;
import gregtech.api.enums.Textures;
import gregtech.api.interfaces.IIconContainer;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Dynamo;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase;
import gregtech.api.objects.XSTR;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.GT_StructureUtility;
import gregtech.api.util.GT_Utility;
import gregtech.common.items.GT_MetaGenerated_Tool_01;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.function.Consumer;
import micdoodle8.mods.galacticraft.api.world.IOrbitDimension;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.WorldProvider;


public class TileEntityDysonSwarm extends GT_MetaTileEntity_EnhancedMultiBlockBase_EM {
    private static Consumer<TileEntityDysonSwarm> moduleDestroyer;
    private static IIconContainer OVERLAY_FRONT_GLOW;
    private static IIconContainer OVERLAY_FRONT_ACTIVE_GLOW;
    private static ITexture OVERLAY_FRONT;
    private static ITexture OVERLAY_FRONT_ACTIVE;
    private static Map<String, Double> powerFactors;
    private static final String LORE_TOOLTIP;
    private long euPerTick;
    private double powerFactor;
    private int moduleCount;
    private static final Map<Locale, DecimalFormat> DECIMAL_FORMATTERS = new HashMap();
    private static final String STRUCTURE_PIECE_MAIN = "main";
    private static final int CASING_INDEX_RECEIVER = 150;
    private static final int CASING_INDEX_LAUNCH = 152;
    private static final int CASING_INDEX_FLOOR = 153;
    private static final int CASING_INDEX_COMMAND = 151;
    private static final IStructureDefinition<TileEntityDysonSwarm> STRUCTURE_DEFINITION = StructureDefinition.builder().addShape(STRUCTURE_PIECE_MAIN, StructureUtility.transpose((String[][]) new String[]{new String[]{"         ---    ", "        -----   ", "       -------  ", "      --------- ", "     -----------", "     -----------", "     -----------", "      --------- ", "       -------  ", "        -----   ", "         ---    ", "  ttt           ", "  ttt        k  ", "  ttt       k k ", "             k  ", "                "}, new String[]{"         ---    ", "        -----   ", "       -------  ", "      --------- ", "     -----------", "     -----------", "     -----------", "      --------- ", "       -------  ", "        -----   ", "  ttt    ---    ", " ttttt          ", " ttttt       k  ", " ttttt      k k ", "  ttt        k  ", "                "}, new String[]{"         ---    ", "        -----   ", "       -------  ", "      --------- ", "     -----------", "     -----------", "     -----------", "      --------- ", "       -------  ", "        -----   ", "  ttt    ---    ", " ttttt          ", " ttttt       k  ", " ttttt      k k ", "  ttt        k  ", "                "}, new String[]{"         ---    ", "        -----   ", "       -------  ", "      --------- ", "     -----------", "     -----------", "     -----------", "      --------- ", "       -------  ", "        -----   ", "  ttt    ---    ", " ttttt          ", " ttttt       k  ", " ttttt      k k ", "  ttt        k  ", "                "}, new String[]{"         ---    ", "        -----   ", "       -------  ", "      --------- ", "     -----------", "     -----------", "     -----------", "      --------- ", "       -------  ", "        -----   ", "         ---    ", "  ttt           ", "  tst        k  ", "  ttt       k k ", "             k  ", "                "}, new String[]{"         ---    ", "        -----   ", "       -------  ", "      --------- ", "     -----------", "     -----------", "     -----------", "      --------- ", "       -------  ", "        -----   ", "         ---    ", "                ", "   s         k  ", "            k k ", "             k  ", "                "}, new String[]{"         ---    ", "        -----   ", "       -------  ", "      --------- ", "     -----------", "     -----h-----", "     -----------", "      --------- ", "       -------  ", "        -----   ", "  ttt    ---    ", " t g t          ", " tgsgt       k  ", " t g t      k k ", "  ttt        k  ", "                "}, new String[]{"         ---    ", "        -----   ", "       -------  ", "      --------- ", "     -----------", "     -----f-----", "     -----------", "      --------- ", "       -------  ", "        -----   ", "         ---    ", "                ", "   s         k  ", "            k k ", "             k  ", "                "}, new String[]{"         ddd    ", "        d---d   ", "       d-----d  ", "      d-------d ", "     d---------d", "     d----f----d", "     d---------d", "      d-------d ", "       d-----d  ", "        d---d   ", "  ttt    ddd    ", " t g t          ", " tgsgt      kmk ", " t g t      m m ", "  ttt       kmk ", "                "}, new String[]{"                ", "         ddd    ", "        ddddd   ", "       dd---dd  ", "      dd-----dd ", "      dd--f--dd ", "      dd-----dd ", "       dd---dd  ", "        ddddd   ", "         ddd    ", "                ", "                ", "   s        kmk ", "            m m ", "            kmk ", "                "}, new String[]{"                ", "                ", "                ", "         ddd    ", "        ddddd   ", "        ddddd   ", "        ddddd   ", "         ddd    ", "                ", "                ", "  ttt           ", " t g t          ", " tgsgt      kmk ", " t g t      m m ", "  ttt       kmk ", "                "}, new String[]{"                ", "                ", "                ", "                ", "         f f    ", "                ", "         f f    ", "                ", "                ", "                ", "                ", "                ", "   s        kmk ", "            m m ", "            kmk ", "                "}, new String[]{"                ", "                ", "                ", "                ", "         f f    ", "                ", "         f f    ", "                ", "                ", "                ", "  ttt           ", " t g t          ", " tgsgt      kmk ", " t g t      m m ", "  ttt       kmk ", "                "}, new String[]{"                ", "                ", "                ", "                ", "         f f    ", "                ", "         f f    ", "                ", "                ", "                ", "                ", "                ", "   s        kmk ", "            m m ", "            kmk ", "                "}, new String[]{"                ", "                ", "                ", "                ", "         f f    ", "                ", "         f f    ", "                ", "                ", "                ", "                ", "                ", "   s        kmk ", "            m m ", "            kmk ", "                "}, new String[]{"                ", "                ", "                ", "                ", "         f f    ", "                ", "         f f    ", "                ", "                ", "                ", "  ppp           ", " p   p          ", " p s p      kmk ", " p   p      m m ", "  ppp       kmk ", "                "}, new String[]{"                ", "                ", "                ", "        xxxxx   ", "        xxxxx   ", "        xxxxx   ", "        xxxxx   ", "        xxxxx   ", "                ", "yyyyyyy         ", "yyyyyyy         ", "yypppyy    zzzzz", "yypypyy    zzzzz", "yypppyy    zzjzz", "yyyyyyy    zzzzz", "yyyyyyy    zzzzz"}, new String[]{"                ", "                ", "                ", "        xeeex   ", "        eccce   ", "        eccce   ", "        eccce   ", "        xeeex   ", "                ", "ooooooo         ", "oyyyyyo         ", "oyyyyyo    ziiiz", "oyyyyyo    izzzi", "oyyyyyo    izzzi", "oyyyyyo    izzzi", "ooooooo    ziiiz"}, new String[]{"                ", "                ", "                ", "        xx~xx   ", "        xxxxx   ", "        xxxxx   ", "        xxxxx   ", "        xxxxx   ", "                ", "yyyyyyy         ", "yyyyyyy         ", "yyyyyyy    zzzzz", "yyyyyyy    zzzzz", "yyyyyyy    zzzzz", "yyyyyyy    zzzzz", "yyyyyyy    zzzzz"}, new String[]{"bbbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbbb", "bbbbbbbnbbbbbbbb", "bbbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbbb"}})).addElement('b', StructureUtility.ofBlock(GSBlocks.DysonSwarmBlocks, 9)).addElement('c', StructureUtility.ofBlock(GregTech_API.sBlockCasings5, 8)).addElement('d', StructureUtility.ofBlock(GSBlocks.DysonSwarmBlocks, 1)).addElement('e', StructureUtility.ofChain(new IStructureElement[]{GT_StructureUtility.ofHatchAdder((v0, v1, v2) -> {
        return v0.addDynamoToMachineList(v1, v2);
    }, (int) CASING_INDEX_RECEIVER, 1), StructureUtility.ofBlock(GSBlocks.DysonSwarmBlocks, 0)})).addElement('f', GT_StructureUtility.ofFrame(Materials.HSSS)).addElement('g', GT_StructureUtility.ofFrame(Materials.Titanium)).addElement('h', StructureUtility.ofBlock(GregTech_API.sBlockCasings6, 10)).addElement('i', StructureUtility.ofChain(new IStructureElement[]{GT_StructureUtility.ofHatchAdder((v0, v1, v2) -> {
        return v0.addClassicInputToMachineList(v1, v2);
    }, (int) CASING_INDEX_LAUNCH, 2), StructureUtility.ofBlock(GSBlocks.DysonSwarmBlocks, 2)})).addElement('j', StructureUtility.ofBlock(GSBlocks.DysonSwarmBlocks, 3)).addElement('k', GT_StructureUtility.ofFrame(Materials.Longasssuperconductornameforuhvwire)).addElement('m', StructureUtility.ofBlock(GSBlocks.DysonSwarmBlocks, 4)).addElement('n', GT_StructureUtility.ofHatchAdder((v0, v1, v2) -> {
        return v0.addClassicMaintenanceToMachineList(v1, v2);
    }, (int) CASING_INDEX_FLOOR, 3)).addElement('o', StructureUtility.ofChain(new IStructureElement[]{GT_StructureUtility.ofHatchAdder((v0, v1, v2) -> {
        return v0.addDataConnectorToMachineList(v1, v2);
    }, (int) CASING_INDEX_COMMAND, 4), StructureUtility.ofBlock(GSBlocks.DysonSwarmBlocks, 5)})).addElement('p', StructureUtility.ofBlock(GSBlocks.DysonSwarmBlocks, 6)).addElement('s', StructureUtility.ofBlock(GSBlocks.DysonSwarmBlocks, 7)).addElement('t', StructureUtility.ofBlock(GSBlocks.DysonSwarmBlocks, 8)).addElement('x', StructureUtility.ofBlock(GSBlocks.DysonSwarmBlocks, 0)).addElement('y', StructureUtility.ofBlock(GSBlocks.DysonSwarmBlocks, 5)).addElement('z', StructureUtility.ofBlock(GSBlocks.DysonSwarmBlocks, 2)).build();

    
    static {
        String[] possibleLore = {"Wait, this isn't an army of vacuum cleaners?", "Number 9? Not quite.", "Not the game.", "Basically solar panels.", "Invented by a free man."};
        LORE_TOOLTIP = possibleLore[XSTR.XSTR_INSTANCE.nextInt(possibleLore.length)];
    }

    protected TileEntityDysonSwarm(int aID, String aName, String aNameRegional) {
        super(aID, aName, aNameRegional);
        this.euPerTick = 0L;
        this.powerFactor = 0.0d;
        this.moduleCount = 0;
    }

    protected TileEntityDysonSwarm(String aName) {
        super(aName);
        this.euPerTick = 0L;
        this.powerFactor = 0.0d;
        this.moduleCount = 0;
    }

    public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
        return new TileEntityDysonSwarm(this.mName);
    }

    public void onFirstTick_EM(IGregTechTileEntity aBaseMetaTileEntity) {
        this.powerFactor = getPowerFactor();
    }

    public void construct(ItemStack stackSize, boolean hintsOnly) {
        structureBuild_EM(STRUCTURE_PIECE_MAIN, 10, 18, 3, stackSize, hintsOnly);
    }

    @Override // galaxyspace.core.tile.machine.multi.GT_MetaTileEntity_EnhancedMultiBlockBase_EM
    public IStructureDefinition<? extends GT_MetaTileEntity_MultiblockBase_EM> getStructure_EM() {
        return STRUCTURE_DEFINITION;
    }

    public boolean checkMachine_EM(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
        return structureCheck_EM(STRUCTURE_PIECE_MAIN, 10, 18, 3) && this.mMaintenanceHatches.size() == 1 && this.mInputBusses.size() > 0 && this.mInputHatches.size() > 0 && this.eInputData.size() > 0 && (this.mDynamoHatches.size() > 0 || this.eDynamoMulti.size() > 0);
    }

    public boolean explodesOnComponentBreak(ItemStack aStack) {
        return true;
    }

    public boolean checkRecipe_EM(ItemStack aStack) {
        Iterator it = this.mInputBusses.iterator();
        while (it.hasNext()) {
            GT_MetaTileEntity_Hatch_InputBus bus = (GT_MetaTileEntity_Hatch_InputBus) it.next();
            if (isValidMetaTileEntity(bus)) {
                for (int i = 0; i < bus.getBaseMetaTileEntity().func_70302_i_(); i++) {
                    ItemStack stack = bus.getBaseMetaTileEntity().func_70301_a(i);
                    if (stack != null && stack.func_77973_b() == GSItems.DysonSwarmItems && stack.func_77960_j() == 0) {
                        this.moduleCount += stack.field_77994_a;
                        stack.field_77994_a = 0;
                    }
                }
            }
        }
        this.eRequiredData = (long) Math.ceil(Math.max((GSConfigCore.computationFactor * Math.pow(this.moduleCount, GSConfigCore.computationExponent)) - GSConfigCore.baseComputation, 0.0d));
        this.euPerTick = (long) (this.moduleCount * GSConfigCore.euPerModule * this.powerFactor);
        if (this.moduleCount > 0 && depleteInput(GSConfigCore.coolantFluid)) {
            moduleDestroyer.accept(this);
            this.mEfficiencyIncrease = 10000;
            this.mMaxProgresstime = 20;
            return true;
        }
        this.mEfficiency = 0;
        return false;
    }

    public boolean energyFlowOnRunningTick(ItemStack aStack, boolean allowProduction) {
        if (allowProduction && this.euPerTick > 0) {
            addEnergyOutput_EM(this.euPerTick, 1L);
            return true;
        }
        return true;
    }

    public boolean addEnergyOutput_EM(long EU, long Amperes) {
        return addEnergyOutput_EM(EU, Amperes, true);
    }

    public boolean addEnergyOutput_EM(long EU, long Amperes, boolean allowMixedVoltages) {
        if (EU < 0) {
            EU = -EU;
        }
        if (Amperes < 0) {
            Amperes = -Amperes;
        }
        long euVar = EU * Amperes;
        Iterator it = this.mDynamoHatches.iterator();
        while (it.hasNext()) {
            GT_MetaTileEntity_Hatch_Dynamo tHatch = (GT_MetaTileEntity_Hatch_Dynamo) it.next();
            if (GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(tHatch)) {
                if (tHatch.maxEUOutput() < euVar && !allowMixedVoltages) {
                    explodeMultiblock();
                }
                long diff = tHatch.maxEUStore() - tHatch.getBaseMetaTileEntity().getStoredEU();
                if (diff <= 0) {
                    continue;
                } else if (euVar > diff) {
                    tHatch.setEUVar(tHatch.maxEUStore());
                    euVar -= diff;
                } else if (euVar <= diff) {
                    tHatch.setEUVar(tHatch.getBaseMetaTileEntity().getStoredEU() + euVar);
                    return true;
                }
            }
        }
        Iterator it2 = this.eDynamoMulti.iterator();
        while (it2.hasNext()) {
            GT_MetaTileEntity_Hatch_DynamoMulti tHatch2 = (GT_MetaTileEntity_Hatch_DynamoMulti) it2.next();
            if (GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity(tHatch2)) {
                if (tHatch2.maxEUOutput() < euVar && !allowMixedVoltages) {
                    explodeMultiblock();
                }
                long diff2 = tHatch2.maxEUStore() - tHatch2.getBaseMetaTileEntity().getStoredEU();
                if (diff2 <= 0) {
                    continue;
                } else if (euVar > diff2) {
                    tHatch2.setEUVar(tHatch2.maxEUStore());
                    euVar -= diff2;
                } else if (euVar <= diff2) {
                    tHatch2.setEUVar(tHatch2.getBaseMetaTileEntity().getStoredEU() + euVar);
                    return true;
                }
            }
        }
        explodeMultiblock();
        return false;
    }

    public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) {
        ItemStack heldItem = aPlayer.func_70694_bm();
        if (heldItem == null || heldItem.func_77973_b() != GT_MetaGenerated_Tool_01.INSTANCE || heldItem.func_77960_j() != 44) {
            return super.onRightclick(aBaseMetaTileEntity, aPlayer);
        }
        int prevCount = this.moduleCount;
        int maxReduction = (int) Math.min(this.moduleCount, GT_MetaGenerated_Tool_01.getToolMaxDamage(heldItem) - GT_MetaGenerated_Tool_01.getToolDamage(heldItem));
        ItemStack modules = new ItemStack(GSItems.DysonSwarmItems, maxReduction);
        aPlayer.field_71071_by.func_70441_a(modules);
        if (modules.field_77994_a > 0 && aPlayer.func_70093_af()) {
            aPlayer.field_70170_p.func_72838_d(new EntityItem(aPlayer.field_70170_p, aPlayer.field_70165_t, aPlayer.field_70163_u + 0.5d, aPlayer.field_70161_v, modules));
            this.moduleCount = 0;
            GT_MetaGenerated_Tool_01.INSTANCE.doDamage(heldItem, maxReduction);
            return true;
        }
        this.moduleCount = (prevCount - maxReduction) + modules.field_77994_a;
        GT_MetaGenerated_Tool_01.INSTANCE.doDamage(heldItem, maxReduction - modules.field_77994_a);
        return true;
    }

    public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) {
        return aSide == aFacing ? aActive ? new ITexture[]{Textures.BlockIcons.getCasingTextureForId((int) CASING_INDEX_RECEIVER), TextureFactory.of(new ITexture[]{OVERLAY_FRONT_ACTIVE}), TextureFactory.builder().addIcon(new IIconContainer[]{OVERLAY_FRONT_ACTIVE_GLOW}).glow().build()} : new ITexture[]{Textures.BlockIcons.getCasingTextureForId((int) CASING_INDEX_RECEIVER), TextureFactory.of(new ITexture[]{OVERLAY_FRONT}), TextureFactory.builder().addIcon(new IIconContainer[]{OVERLAY_FRONT_GLOW}).glow().build()} : new ITexture[]{Textures.BlockIcons.getCasingTextureForId((int) CASING_INDEX_RECEIVER)};
    }

    @Override // galaxyspace.core.tile.machine.multi.GT_MetaTileEntity_EnhancedMultiBlockBase_EM
    protected GT_Multiblock_Tooltip_Builder createTooltip() {
        String eu_module = getDecimalFormat().format(GSConfigCore.euPerModule);
        String destroy_chance = getDecimalFormat().format(GSConfigCore.destroyModuleFactor);
        String destroy_exponent = getDecimalFormat().format(GSConfigCore.destroyModuleExponent);
        String fluid_amount = getDecimalFormat().format(GSConfigCore.coolantConsumption);
        String fluid_name = GSConfigCore.coolantFluid.getLocalizedName();
        String a = getDecimalFormat().format(GSConfigCore.computationFactor);
        String b = getDecimalFormat().format(GSConfigCore.computationExponent);
        String c = getDecimalFormat().format(GSConfigCore.baseComputation);
        GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder();
        tt.addMachineType("Dyson Swarm").addInfo(EnumChatFormatting.ITALIC + LORE_TOOLTIP).addInfo("Controller Block for the Dyson Swarm Command Center").addInfo("Put Dyson Swarm Modules in the Input Bus(ses) to send them to the next star.").addInfo("Outputs " + eu_module + "*f EU/t, where f is a dimension-dependent factor.").addInfo("Each second, n of m Dyson Swarm Modules are destroyed according to this formula:").addInfo(" n=X*" + destroy_chance + "*m^" + destroy_exponent + ", where X is a normally distributed random number between 0 and 2 with mean 1.").addInfo("Requires " + fluid_amount + "L/s of " + fluid_name + ".").addInfo("Requires n computation per tick according to this formula:").addInfo(" n=" + a + "*m^" + b + "-" + c + ", where m is the amount of modules.").addInfo(" n is rounded up and never negative.").addInfo("R-Click with a Plunger to extract as many Modules to your inventory as possible.").addInfo("Sneaking will dump the rest on the ground.").addSeparator().beginStructureBlock(16, 20, 16, false).addStructureInfo(EnumChatFormatting.ITALIC + "This structure is too complex to describe, use the Multiblock Structure Hologram Projector!").addDynamoHatch("Can use Single- and/or Multi-Amp Dynamo Hatches and/or Laser Source Hatches (1 - 12)", new int[]{1}).addMaintenanceHatch("1", new int[]{3}).addInputBus("1 - 11", new int[]{2}).addInputHatch("1 - 11", new int[]{2}).addOtherStructurePart("Optical Slave Connector", "1 - 24", new int[]{4}).addStructureInfo("").addStructureInfo(EnumChatFormatting.ITALIC + "Additionally needed:").addStructureInfo("Energy Receiver Base Casing: 53 - 64 (depending on the amount of Dynamo Hatches)").addStructureInfo("Energy Receiver Dish Block: 81").addStructureInfo("Module Deployment Unit Base Casing: 62 - 72 (depending on the amount of Input Busses & Hatches)").addStructureInfo("Module Deployment Unit Core: 1").addStructureInfo("Module Deployment Unit Superconducting Magnet: 32").addStructureInfo("Control Center Base Casing: 115 - 138 (depending on the amount of Optical Slave Connectors)").addStructureInfo("Control Center Primary Windings: 20").addStructureInfo("Control Center Secondary Windings: 12").addStructureInfo("Control Center Toroid Casing: 128").addStructureInfo("Ultra High Strenght Concrete Floor: 255").addStructureInfo("Awakened Draconium Coil Block: 9").addStructureInfo("Hermetic Casing X: 1").addStructureInfo("Titanium Frame Box: 16").addStructureInfo("HSS-S Frame Box: 23").addStructureInfo("Superconductor Base UHV Frame Box: 64").toolTipFinisher(EnumChatFormatting.DARK_PURPLE + "GalaxySpace");
        return tt;
    }

    public String[] getInfoData() {
        String[] strArr = new String[8];
        strArr[0] = EnumChatFormatting.LIGHT_PURPLE + "Operational Data:" + EnumChatFormatting.RESET;
        strArr[1] = "Modules: " + EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(this.moduleCount) + EnumChatFormatting.RESET;
        strArr[2] = "Power Factor: " + (this.powerFactor < 1.0d ? EnumChatFormatting.RED : EnumChatFormatting.GREEN) + GT_Utility.formatNumbers(this.powerFactor * 100.0d) + "%" + EnumChatFormatting.RESET;
        strArr[3] = "Theoretical Output: " + EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(this.moduleCount * GSConfigCore.euPerModule * this.powerFactor) + EnumChatFormatting.RESET + " EU/t";
        strArr[4] = "Current Output: " + EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(this.euPerTick) + EnumChatFormatting.RESET + " EU/t";
        strArr[5] = "Computation required: " + EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(this.eRequiredData) + EnumChatFormatting.RESET + "/t";
        strArr[6] = "Maintenance Status: " + (getRepairStatus() == getIdealStatus() ? EnumChatFormatting.GREEN + "Working perfectly" + EnumChatFormatting.RESET : EnumChatFormatting.RED + "Has problems" + EnumChatFormatting.RESET);
        strArr[7] = "---------------------------------------------";
        return strArr;
    }

    public double getPowerFactor() {
        IOrbitDimension iOrbitDimension = getBaseMetaTileEntity().getWorld().field_73011_w;
        if (iOrbitDimension instanceof IOrbitDimension) {
            return powerFactors.getOrDefault("SS_" + iOrbitDimension.getPlanetToOrbit(), Double.valueOf(GSConfigCore.powerFactorDefault)).doubleValue();
        }
        if (iOrbitDimension.getClass().getName().equals("zarkov.utilityworlds.UW_WorldProviderGarden")) {
            return powerFactors.getOrDefault("UW_Garden", Double.valueOf(GSConfigCore.powerFactorDefault)).doubleValue();
        }
        if (iOrbitDimension.getClass().getName().equals("zarkov.utilityworlds.UW_WorldProviderMining")) {
            return powerFactors.getOrDefault("UW_Mining", Double.valueOf(GSConfigCore.powerFactorDefault)).doubleValue();
        }
        if (iOrbitDimension.getClass().getName().equals("zarkov.utilityworlds.UW_WorldProviderVoid")) {
            return powerFactors.getOrDefault("UW_Void", Double.valueOf(GSConfigCore.powerFactorDefault)).doubleValue();
        }
        return powerFactors.getOrDefault(String.valueOf(((WorldProvider) iOrbitDimension).field_76574_g), Double.valueOf(GSConfigCore.powerFactorDefault)).doubleValue();
    }

    public double calculateOutput() {
        return this.moduleCount * GSConfigCore.euPerModule * this.powerFactor;
    }

    private static DecimalFormat getDecimalFormat() {
        return DECIMAL_FORMATTERS.computeIfAbsent(Locale.getDefault(Locale.Category.FORMAT), locale -> {
            DecimalFormat format = new DecimalFormat();
            format.setGroupingUsed(true);
            format.setMaximumFractionDigits(5);
            format.setRoundingMode(RoundingMode.HALF_UP);
            DecimalFormatSymbols dfs = format.getDecimalFormatSymbols();
            dfs.setGroupingSeparator(',');
            format.setDecimalFormatSymbols(dfs);
            return format;
        });
    }

    public void loadNBTData(NBTTagCompound aNBT) {
        super.loadNBTData(aNBT);
        this.moduleCount = aNBT.func_74762_e("moduleCount");
    }

    public void saveNBTData(NBTTagCompound aNBT) {
        super.saveNBTData(aNBT);
        aNBT.func_74768_a("moduleCount", this.moduleCount);
    }

    public static void initCommon() {
        String[] strArr;
        GSItems.DysonSwarmController = new TileEntityDysonSwarm(14001, "DysonSwarm", "Dyson Swarm Ground Unit").getStackForm(1L);
        powerFactors = new HashMap();
        for (String s : GSConfigCore.powerFactors) {
            String[] parts = s.split(":");
            try {
                powerFactors.put(parts[0], Double.valueOf(Double.parseDouble(parts[1])));
            } catch (Exception e) {
                GalaxySpace.error("Error while trying to parse \"" + s + "\"!");
                e.printStackTrace();
            }
        }
        if (GSConfigCore.destroyModuleFactor > 0.0d) {
            moduleDestroyer = tile -> {
                tile.moduleCount -= (int) ((getRandom() * GSConfigCore.destroyModuleFactor) * Math.pow(tile.moduleCount, GSConfigCore.destroyModuleExponent));
                if (tile.moduleCount < 0) {
                    tile.moduleCount = 0;
                }
            };
        } else {
            moduleDestroyer = tile2 -> {
            };
        }
    }

    private static double getRandom() {
        double d = XSTR.XSTR_INSTANCE.nextGaussian() + 1.0d;
        return (d < 0.0d || d > 2.0d) ? getRandom() : d;
    }

    public static void initClient() {
        initCommon();
        Textures.BlockIcons.setCasingTextureForId((int) CASING_INDEX_RECEIVER, TextureFactory.of(GSBlocks.DysonSwarmBlocks, 0));
        Textures.BlockIcons.setCasingTextureForId((int) CASING_INDEX_LAUNCH, TextureFactory.of(GSBlocks.DysonSwarmBlocks, 2));
        Textures.BlockIcons.setCasingTextureForId((int) CASING_INDEX_COMMAND, TextureFactory.of(GSBlocks.DysonSwarmBlocks, 5));
        Textures.BlockIcons.setCasingTextureForId((int) CASING_INDEX_FLOOR, TextureFactory.of(GSBlocks.DysonSwarmBlocks, 9));
        OVERLAY_FRONT = TextureFactory.of(new Textures.BlockIcons.CustomIcon("iconsets/OVERLAY_FRONT_DYSONSPHERE"));
        OVERLAY_FRONT_ACTIVE = TextureFactory.of(new Textures.BlockIcons.CustomIcon("iconsets/OVERLAY_FRONT_DYSONSPHERE_ACTIVE"));
        OVERLAY_FRONT_GLOW = new Textures.BlockIcons.CustomIcon("iconsets/OVERLAY_FRONT_DYSONSPHERE_GLOW");
        OVERLAY_FRONT_ACTIVE_GLOW = new Textures.BlockIcons.CustomIcon("iconsets/OVERLAY_FRONT_DYSONSPHERE_ACTIVE_GLOW");
    }
}

这是戴森球工作的源码,位于core\tile\machine\multi\TileEntityDysonSwarm中。

真正有用的部分,我查询了一下forge中给的方法,稍微简化了下需要用到分析的部分:

   public boolean checkRecipe_EM(ItemStack aStack) {
        Iterator it = this.mInputBusses.iterator();
        while (it.hasNext()) {
            GT_MetaTileEntity_Hatch_InputBus bus = (GT_MetaTileEntity_Hatch_InputBus) it.next();
            if (isValidMetaTileEntity(bus)) {
                for (int i = 0; i < bus.getBaseMetaTileEntity().getSizeInventory(); i++) {
                    ItemStack stack = bus.getBaseMetaTileEntity().getStackInSlot(i);
                    if (stack != null &&    getItem() == GSItems.DysonSwarmItems && getItemDamage() == 0) {
                        this.moduleCount += stack.stacksize;
                        stack.stacksize = 0;
                    }
                }
            }
        }//此方法的作用为对输入总线里的所有物品进行遍历,如果是戴森球模块,而且损坏值为0的时候,戴森球内部的戴森球模块数目增加遍历到的戴森球模块数目,并且清空输入总线中的戴森球模块
        this.eRequiredData(算力需求) = (long) Math.ceil(Math.max((GSConfigCore.computationFactor * Math.pow(this.moduleCount, GSConfigCore.computationExponent)) - GSConfigCore.baseComputation, 0.0d));
        this.euPerTick = (long) (this.moduleCount * GSConfigCore.euPerModule * this.powerFactor);
        if (this.moduleCount > 0 && depleteInput(GSConfigCore.coolantFluid)) {
            moduleDestroyer.accept(this);
            this.mEfficiencyIncrease = 10000;
            this.mMaxProgresstime = 20;
            return true;
        }
        this.mEfficiency = 0;
        return false;
    }

    public static void initCommon() {
        String[] strArr;
        GSItems.DysonSwarmController = new TileEntityDysonSwarm(14001, "DysonSwarm", "Dyson Swarm Ground Unit").getStackForm(1L);
        powerFactors = new HashMap();
        for (String s : GSConfigCore.powerFactors) {
            String[] parts = s.split(":");
            try {
                powerFactors.put(parts[0], Double.valueOf(Double.parseDouble(parts[1])));
            } catch (Exception e) {
                GalaxySpace.error("Error while trying to parse \"" + s + "\"!");
                e.printStackTrace();
            }
        }//前面的都是废话,可以不看,直接看下边
        if (GSConfigCore.destroyModuleFactor > 0.0d) {
            moduleDestroyer = tile -> {
                tile.moduleCount -= (int) ((getRandom() * GSConfigCore.destroyModuleFactor) * Math.pow(tile.moduleCount, GSConfigCore.destroyModuleExponent));
                if (tile.moduleCount < 0) {
                    tile.moduleCount = 0;
                }
            };
        } else {
            moduleDestroyer = tile2 -> {
            };
        }
    }
    private static double getRandom() {
        double d = XSTR.XSTR_INSTANCE.nextGaussian() + 1.0d;
        return (d < 0.0d || d > 2.0d) ? getRandom() : d;
    }


    public double getPowerFactor() {
        IOrbitDimension iOrbitDimension = getBaseMetaTileEntity().getWorld().field_73011_w;
        if (iOrbitDimension instanceof IOrbitDimension) {
            return powerFactors.getOrDefault("SS_" + iOrbitDimension.getPlanetToOrbit(), Double.valueOf(GSConfigCore.powerFactorDefault)).doubleValue();
        }
        if (iOrbitDimension.getClass().getName().equals("zarkov.utilityworlds.UW_WorldProviderGarden")) {
            return powerFactors.getOrDefault("UW_Garden", Double.valueOf(GSConfigCore.powerFactorDefault)).doubleValue();
        }
        if (iOrbitDimension.getClass().getName().equals("zarkov.utilityworlds.UW_WorldProviderMining")) {
            return powerFactors.getOrDefault("UW_Mining", Double.valueOf(GSConfigCore.powerFactorDefault)).doubleValue();
        }
        if (iOrbitDimension.getClass().getName().equals("zarkov.utilityworlds.UW_WorldProviderVoid")) {
            return powerFactors.getOrDefault("UW_Void", Double.valueOf(GSConfigCore.powerFactorDefault)).doubleValue();
        }
        return powerFactors.getOrDefault(String.valueOf(((WorldProvider) iOrbitDimension).dimensionId), Double.valueOf(GSConfigCore.powerFactorDefault)).doubleValue();
    }

    public double calculateOutput() {
        return this.moduleCount * GSConfigCore.euPerModule * this.powerFactor;
    }

经过分析:

每秒主要设计下列两个方法:

CheckRecipe_EM方法

检查所有输入总线里面的戴森球模块,并且把它们加入发射模块中

设α1=0.1*发射模块数量^1.075

α2=max(α1-128,0(双精度浮点数))

算力需求=(向下取整后转成long型)(α2)

设σ为发电系数修正,它与维度ID(或者说是维度的字符串)有关,

对应关系如下,举例:主世界下工作,σ取1.0

0:1.0

25:0.15

28:1.0

29:0.81

30:0.61

31:2.28

32:2.31

33:0.16

35:0.44

36:0.44

37:1.61

38:0.81

39:1.76

40:0.81

41:0.32

42:0.6

43:0.44

44:0.32

45:0.32

46:0.23

47:0.23

48:0.18

49:0.16

63:1.12

64:1.12

81:1.41

82:1.26

83:0.15

84:1.98

85:1.34

86:0.23

SS_Overworld:1.1

SS_planet.mars:0.89

SS_planet.venus:1.94

SS_planet.jupiter:0.48

SS_planet.saturn:0.36

SS_planet.uranus:0.25

SS_planet.neptune:0.2

UW_Garden:0.01

UW_Mining:0.01

UW_Void:0.01

这里注意:SS是代表空间站,UW是utilityworlds的维度。

每秒输出的电能(单位:EU)= (转long型) (发射模块数量 * 262144 * σ);

注意:一定要有冷却剂(极寒之凛冰),才可以100%效率工作1秒,否则接下来的一秒不会输出任何电能!

对于initCommon方法

涉及发射模块的销毁

设随机数φ,φ是以μ=1,σ^2=1的正态分布N(1,1)上的取值,如果取值|φ-μ|>σ,则重新取值

β1=(转为int型) (φ * 5*10^-5 * 模块数量^1.001);

每秒销毁的模块为β1。

销毁后,发射模块数量=销毁前数量-β1,如果销毁后发射模块数量<0,那么设定发射模块数量为0。

基于此函数和量子计算机的算力最大输出,即可利用迭代法编程求出戴森球净发电量的公式。

注意:此分析只适用于GTNH2.2.3版本

下面给出根据放入的模块数,和所在维度发电系数,计算发电量和算力消耗的C++代码:

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<ctime>
#include<limits>
#include<windows.h> 
using namespace std;
class DysonSwarm{
private:
int InputModule;
double ComputationNeed;
double OutPutEnergy;
double DIM;
int moduleCount;
public:
void SetDataAndInitialization(int ModuleInput,double InputDIM){
this->InputModule=ModuleInput;
this->DIM=InputDIM;
this->moduleCount=0;
this->OutPutEnergy=0;
this->ComputationNeed=0;
}
void GenerateModule(){
this->moduleCount=this->moduleCount+this->InputModule;
//cout<<this->moduleCount<<endl; 
}
void DestroyModule(){
double a=1;

this->moduleCount=this->moduleCount-(int)((5e-5)*a*pow((double)this->moduleCount,1.001));
if(this->moduleCount<0){
this->moduleCount=0;
}
//cout<<this->moduleCount<<endl;
}
void CalculateComputation(){
this->ComputationNeed=(double)ceil(max(0.1*pow((double)this->moduleCount,1.075)-128,(double)0));
}
void CalculateOutPutEnergy(){
this->OutPutEnergy=(double)((double)this->moduleCount*(double)262144*(double)DIM);
//printf("%lf\n",this->OutPutEnergy);
}
double GetOutPutEnergy(){
return this->OutPutEnergy;
}
double GetNeedComputation(){
return this->ComputationNeed;
}
}; 
int main(){
DysonSwarm Dyson;
cout<<"请输入放入的模块数,和戴森球所在维度的发电系数修正:"<<endl;
int num1;
double num2;
scanf("%d %lf",&num1,&num2);
Dyson.SetDataAndInitialization(num1,num2);
double temp=-114514;
while(true){
Dyson.GenerateModule();
Dyson.CalculateComputation();
Dyson.CalculateOutPutEnergy();
Dyson.DestroyModule();
if(fabs(temp-Dyson.GetOutPutEnergy())<1){
break;
}else{
temp=Dyson.GetOutPutEnergy();
}
}
cout<<"发电量:"<<endl; 
printf("%lf\n",Dyson.GetOutPutEnergy()); 
cout<<"所需算力:"<<endl; 
printf("%lf\n",Dyson.GetNeedComputation());
cout<<"最少需要机箱:"<<endl;
int temp1=ceil(Dyson.GetNeedComputation()/(double)1154);
printf("%d\n",temp1);
cout<<"这些机箱的耗电量为:"<<endl; 
printf("%lf\n",temp1*0.8*524288);
cout<<"净输出为:"<<endl;
printf("%lf\n",Dyson.GetOutPutEnergy()-temp1*-0.8*524288); 
return 0;
}