Search in sources :

Example 81 with BlockVec3

use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.

the class TileBaseConductor method refresh.

@Override
public void refresh() {
    if (!this.worldObj.isRemote) {
        this.adjacentConnections = null;
        this.getNetwork().refresh();
        BlockVec3 thisVec = new BlockVec3(this);
        for (EnumFacing side : EnumFacing.VALUES) {
            TileEntity tileEntity = thisVec.getTileEntityOnSide(this.worldObj, side);
            if (tileEntity instanceof TileBaseConductor && ((TileBaseConductor) tileEntity).canConnect(side.getOpposite(), NetworkType.POWER)) {
                IGridNetwork otherNet = ((INetworkProvider) tileEntity).getNetwork();
                if (!this.getNetwork().equals(otherNet)) {
                    if (!otherNet.getTransmitters().isEmpty()) {
                        otherNet.merge(this.getNetwork());
                    }
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IGridNetwork(micdoodle8.mods.galacticraft.api.transmission.grid.IGridNetwork) EnumFacing(net.minecraft.util.EnumFacing) INetworkProvider(micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 82 with BlockVec3

use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.

the class EnergyUtil method getAdjacentPowerConnections.

public static TileEntity[] getAdjacentPowerConnections(TileEntity tile) {
    final TileEntity[] adjacentConnections = new TileEntity[6];
    BlockVec3 thisVec = new BlockVec3(tile);
    for (EnumFacing direction : EnumFacing.VALUES) {
        if (tile instanceof IConductor && !((IConductor) tile).canConnect(direction, NetworkType.POWER)) {
            continue;
        }
        TileEntity tileEntity = thisVec.getTileEntityOnSide(tile.getWorld(), direction);
        if (tileEntity == null) {
            continue;
        }
        if (tileEntity instanceof IConnector) {
            if (((IConnector) tileEntity).canConnect(direction.getOpposite(), NetworkType.POWER)) {
                adjacentConnections[direction.ordinal()] = tileEntity;
            }
            continue;
        }
        if (isMekLoaded && (tileEntity instanceof IStrictEnergyAcceptor || tileEntity instanceof ICableOutputter)) {
            // Do not connect GC wires directly to Mek Universal Cables
            try {
                if (clazzMekCable != null && clazzMekCable.isInstance(tileEntity)) {
                    continue;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (tileEntity instanceof IStrictEnergyAcceptor && ((IStrictEnergyAcceptor) tileEntity).canReceiveEnergy(direction.getOpposite())) {
                adjacentConnections[direction.ordinal()] = tileEntity;
            } else if (tileEntity instanceof ICableOutputter && ((ICableOutputter) tileEntity).canOutputTo(direction.getOpposite())) {
                adjacentConnections[direction.ordinal()] = tileEntity;
            }
            continue;
        }
        if (isBCReallyLoaded) {
            // Do not connect GC wires directly to BC pipes of any type
            try {
                if (clazzPipeTile.isInstance(tileEntity)) {
                    continue;
                }
            } catch (Exception e) {
            }
        }
        if (isRFLoaded && tileEntity instanceof IEnergyConnection) {
            if (isRF2Loaded && (tileEntity instanceof IEnergyProvider || tileEntity instanceof IEnergyReceiver) || isRF1Loaded && tileEntity instanceof IEnergyHandler || clazzRailcraftEngine != null && clazzRailcraftEngine.isInstance(tileEntity)) {
                // Do not connect GC wires directly to power conduits
                if (clazzEnderIOCable != null && clazzEnderIOCable.isInstance(tileEntity)) {
                    continue;
                }
                if (clazzMFRRednetEnergyCable != null && clazzMFRRednetEnergyCable.isInstance(tileEntity)) {
                    continue;
                }
                if (((IEnergyConnection) tileEntity).canConnectEnergy(direction.getOpposite())) {
                    adjacentConnections[direction.ordinal()] = tileEntity;
                }
            }
            continue;
        }
        if (isIC2Loaded) {
            if (tileEntity instanceof IEnergyConductor) {
                continue;
            }
            if (!tile.getWorld().isRemote) {
                Object IC2tile = tileEntity;
                BlockPos checkingIC2 = thisVec.toBlockPos().offset(direction);
                try {
                    IC2tile = EnergyNet.instance.getSubTile(tile.getWorld(), checkingIC2);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (IC2tile instanceof IEnergyAcceptor && tile instanceof IEnergyEmitter) {
                    if (((IEnergyAcceptor) IC2tile).acceptsEnergyFrom((IEnergyEmitter) tile, direction.getOpposite())) {
                        adjacentConnections[direction.ordinal()] = tileEntity;
                    }
                    continue;
                }
                if (IC2tile instanceof IEnergyEmitter && tile instanceof IEnergyAcceptor) {
                    if (((IEnergyEmitter) IC2tile).emitsEnergyTo((IEnergyAcceptor) tile, direction.getOpposite())) {
                        adjacentConnections[direction.ordinal()] = tileEntity;
                    }
                    continue;
                }
            } else {
                try {
                    Class clazz = tileEntity.getClass();
                    if (clazz.getName().startsWith("ic2")) {
                        // Special case: IC2's transformers don't seem to setup their sink and source directions in Energy clientside
                        if (clazz.getName().startsWith("ic2.core.block.wiring.TileEntityTransformer")) {
                            adjacentConnections[direction.ordinal()] = tileEntity;
                            continue;
                        }
                        Field energyField = null;
                        fieldLoop: while (energyField == null && clazz != null) {
                            for (Field f : clazz.getDeclaredFields()) {
                                if (f.getName().equals("energy")) {
                                    energyField = f;
                                    break fieldLoop;
                                }
                            }
                            clazz = clazz.getSuperclass();
                        }
                        energyField.setAccessible(true);
                        Object energy = energyField.get(tileEntity);
                        Set<EnumFacing> connections;
                        if (tile instanceof IEnergyEmitter) {
                            connections = (Set<EnumFacing>) energy.getClass().getMethod("getSinkDirs").invoke(energy);
                            if (connections.contains(direction.getOpposite())) {
                                adjacentConnections[direction.ordinal()] = tileEntity;
                                continue;
                            }
                        }
                        if (tile instanceof IEnergyAcceptor) {
                            connections = (Set<EnumFacing>) energy.getClass().getMethod("getSourceDirs").invoke(energy);
                            if (connections.contains(direction.getOpposite())) {
                                adjacentConnections[direction.ordinal()] = tileEntity;
                                continue;
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return adjacentConnections;
}
Also used : IEnergyConnection(cofh.api.energy.IEnergyConnection) EnumFacing(net.minecraft.util.EnumFacing) TileEntity(net.minecraft.tileentity.TileEntity) IConductor(micdoodle8.mods.galacticraft.api.transmission.tile.IConductor) Field(java.lang.reflect.Field) IEnergyProvider(cofh.api.energy.IEnergyProvider) ICableOutputter(mekanism.api.energy.ICableOutputter) IStrictEnergyAcceptor(mekanism.api.energy.IStrictEnergyAcceptor) IEnergyHandler(cofh.api.energy.IEnergyHandler) IConnector(micdoodle8.mods.galacticraft.api.transmission.tile.IConnector) BlockPos(net.minecraft.util.BlockPos) IEnergyReceiver(cofh.api.energy.IEnergyReceiver) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 83 with BlockVec3

use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.

the class NetworkFinder method loopAll.

private void loopAll(int x, int y, int z, int dirIn) {
    BlockVec3 obj = null;
    for (int dir = 0; dir < 6; dir++) {
        if (dir == dirIn) {
            continue;
        }
        switch(dir) {
            case 0:
                obj = new BlockVec3(x, y - 1, z);
                break;
            case 1:
                obj = new BlockVec3(x, y + 1, z);
                break;
            case 2:
                obj = new BlockVec3(x, y, z - 1);
                break;
            case 3:
                obj = new BlockVec3(x, y, z + 1);
                break;
            case 4:
                obj = new BlockVec3(x - 1, y, z);
                break;
            case 5:
                obj = new BlockVec3(x + 1, y, z);
                break;
        }
        if (!iterated.contains(obj)) {
            iterated.add(obj);
            TileEntity tileEntity = worldObj.getTileEntity(new BlockPos(obj.x, obj.y, obj.z));
            if (tileEntity instanceof IConductor) {
                found.add((IConductor) tileEntity);
                loopAll(obj.x, obj.y, obj.z, dir ^ 1);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IConductor(micdoodle8.mods.galacticraft.api.transmission.tile.IConductor) BlockPos(net.minecraft.util.BlockPos) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 84 with BlockVec3

use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.

the class StatsCapability method saveNBTData.

@Override
public void saveNBTData(NBTTagCompound nbt) {
    nbt.setTag("ExtendedInventoryGC", this.extendedInventory.writeToNBT(new NBTTagList()));
    nbt.setInteger("playerAirRemaining", this.airRemaining);
    nbt.setInteger("damageCounter", this.damageCounter);
    nbt.setBoolean("OxygenSetupValid", this.oxygenSetupValid);
    nbt.setBoolean("usingParachute2", this.usingParachute);
    nbt.setBoolean("usingPlanetSelectionGui", this.usingPlanetSelectionGui);
    nbt.setInteger("teleportCooldown", this.teleportCooldown);
    nbt.setDouble("coordsTeleportedFromX", this.coordsTeleportedFromX);
    nbt.setDouble("coordsTeleportedFromZ", this.coordsTeleportedFromZ);
    nbt.setString("startDimension", this.startDimension);
    nbt.setString("spaceStationDimensionInfo", WorldUtil.spaceStationDataToString(this.spaceStationDimensionData));
    nbt.setInteger("thermalLevel", this.thermalLevel);
    Collections.sort(this.unlockedSchematics);
    NBTTagList tagList = new NBTTagList();
    for (ISchematicPage page : this.unlockedSchematics) {
        if (page != null) {
            final NBTTagCompound nbttagcompound = new NBTTagCompound();
            nbttagcompound.setInteger("UnlockedPage", page.getPageID());
            tagList.appendTag(nbttagcompound);
        }
    }
    nbt.setTag("Schematics", tagList);
    nbt.setInteger("rocketStacksLength", this.rocketStacks.length);
    nbt.setInteger("SpaceshipTier", this.spaceshipTier);
    nbt.setInteger("FuelLevel", this.fuelLevel);
    if (this.rocketItem != null) {
        ItemStack returnRocket = new ItemStack(this.rocketItem, 1, this.rocketType);
        nbt.setTag("ReturnRocket", returnRocket.writeToNBT(new NBTTagCompound()));
    }
    final NBTTagList var2 = new NBTTagList();
    for (int var3 = 0; var3 < this.rocketStacks.length; ++var3) {
        if (this.rocketStacks[var3] != null) {
            final NBTTagCompound var4 = new NBTTagCompound();
            var4.setByte("Slot", (byte) var3);
            this.rocketStacks[var3].writeToNBT(var4);
            var2.appendTag(var4);
        }
    }
    nbt.setTag("RocketItems", var2);
    final NBTTagCompound var4 = new NBTTagCompound();
    if (this.launchpadStack != null) {
        nbt.setTag("LaunchpadStack", this.launchpadStack.writeToNBT(var4));
    } else {
        nbt.setTag("LaunchpadStack", var4);
    }
    nbt.setInteger("CryogenicChamberCooldown", this.cryogenicChamberCooldown);
    nbt.setBoolean("ReceivedSoundWarning", this.receivedSoundWarning);
    nbt.setBoolean("ReceivedBedWarning", this.receivedBedWarning);
    nbt.setInteger("BuildFlags", this.buildFlags);
    nbt.setBoolean("ShownSpaceRace", this.openedSpaceRaceManager);
    nbt.setInteger("AstroMinerCount", this.astroMinerCount);
    NBTTagList astroList = new NBTTagList();
    for (BlockVec3 data : this.activeAstroMinerChunks) {
        if (data != null) {
            astroList.appendTag(data.writeToNBT(new NBTTagCompound()));
        }
    }
    nbt.setTag("AstroData", astroList);
    nbt.setInteger("GlassColor1", this.glassColor1);
    nbt.setInteger("GlassColor2", this.glassColor2);
    nbt.setInteger("GlassColor3", this.glassColor3);
    NBTTagList panelList = new NBTTagList();
    for (int i = 0; i < BlockPanelLighting.PANELTYPES_LENGTH; ++i) {
        final NBTTagCompound stateNBT = new NBTTagCompound();
        IBlockState bs = this.panelLightingBases[i];
        if (bs != null) {
            TileEntityPanelLight.writeBlockState(stateNBT, bs);
        }
        panelList.appendTag(stateNBT);
    }
    nbt.setTag("PanLi", panelList);
    nbt.setInteger("PanCo", this.panelLightingColor);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) ISchematicPage(micdoodle8.mods.galacticraft.api.recipe.ISchematicPage) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 85 with BlockVec3

use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.

the class ThreadFindSeal method doLayerNearMapEdge.

/**
 * Again, literally the only difference from doLayer() should be these two lines:
 *        Block id = sideVec.getBlockID_noChunkLoad(world);
 *
 * In this code, there is a map edge check on the x, z coordinates (outside map edge at 30,000,000 blocks?)
 * This check is skipped in the "safe" version of the same code, for higher performance
 * because doing this check 50000 times when looking at blocks around a sealer at spawn is obviously dumb
 */
private void doLayerNearMapEdge() {
    // Local variables are fractionally faster than statics
    Block breatheableAirID = GCBlocks.breatheableAir;
    Block airID = Blocks.air;
    Block breatheableAirIDBright = GCBlocks.brightBreatheableAir;
    Block airIDBright = GCBlocks.brightAir;
    Block oxygenSealerID = GCBlocks.oxygenSealer;
    LinkedList<BlockVec3> nextLayer = new LinkedList<>();
    World world = this.world;
    int side, bits;
    while (this.sealed && this.currentLayer.size() > 0) {
        for (BlockVec3 vec : this.currentLayer) {
            // This is for side = 0 to 5 - but using do...while() is fractionally quicker
            side = 0;
            bits = vec.sideDoneBits;
            do {
                // This is also used to skip looking on the solid sides of partially sealable blocks
                if ((bits & (1 << side)) == 0) {
                    if (!checkedContains(vec, side)) {
                        BlockVec3 sideVec = vec.newVecSide(side);
                        if (this.checkCount > 0) {
                            this.checkCount--;
                            Block id = sideVec.getBlockID_noChunkLoad(world);
                            // The most likely case
                            if (id == breatheableAirID) {
                                checkedAdd(sideVec);
                                nextLayer.add(sideVec);
                                this.ambientThermalTracked.add(sideVec);
                            } else if (id == airID) {
                                checkedAdd(sideVec);
                                nextLayer.add(sideVec);
                                this.airToReplace.add(sideVec);
                            } else if (id == breatheableAirIDBright) {
                                checkedAdd(sideVec);
                                nextLayer.add(sideVec);
                                this.ambientThermalTrackedBright.add(sideVec);
                            } else if (id == airIDBright) {
                                checkedAdd(sideVec);
                                nextLayer.add(sideVec);
                                this.airToReplaceBright.add(sideVec);
                            } else if (id == null) {
                                // Broken through to the void or the
                                // stratosphere (above y==255) - set
                                // unsealed and abort
                                this.checkCount = 0;
                                this.sealed = false;
                                return;
                            } else if (id == oxygenSealerID) {
                                TileEntityOxygenSealer sealer = this.sealersAround.get(sideVec);
                                if (sealer != null && !this.sealers.contains(sealer)) {
                                    if (side == 0) {
                                        checkedAdd(sideVec);
                                        this.sealers.add(sealer);
                                        if (sealer.thermalControlEnabled()) {
                                            foundAmbientThermal = true;
                                        }
                                        this.checkCount += sealer.getFindSealChecks();
                                    }
                                // if side != 0, no checkedAdd() - allows this sealer to be checked again from other sides
                                }
                            } else if (this.canBlockPassAirCheck(id, sideVec, side)) {
                                nextLayer.add(sideVec);
                            }
                        // If the chunk was unloaded, BlockVec3.getBlockID returns Blocks.bedrock
                        // which is a solid block, so the loop will treat that as a sealed edge
                        // and not iterate any further in that direction
                        } else // the if (this.isSealed) check here is unnecessary because of the returns
                        {
                            Block id = sideVec.getBlockID_noChunkLoad(this.world);
                            // of which are unsealed obviously
                            if (id == null || id == airID || id == breatheableAirID || id == airIDBright || id == breatheableAirIDBright || this.canBlockPassAirCheck(id, sideVec, side)) {
                                this.sealed = false;
                                if (this.sealers.size() > 0) {
                                    vec.sideDoneBits = side << 6;
                                    traceLeak(vec);
                                }
                                return;
                            }
                        }
                    }
                }
                side++;
            } while (side < 6);
        }
        // Is there a further layer of air/permeable blocks to test?
        this.currentLayer = nextLayer;
        nextLayer = new LinkedList<BlockVec3>();
    }
}
Also used : TileEntityOxygenSealer(micdoodle8.mods.galacticraft.core.tile.TileEntityOxygenSealer) IPartialSealableBlock(micdoodle8.mods.galacticraft.api.block.IPartialSealableBlock) World(net.minecraft.world.World) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Aggregations

BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)104 TileEntity (net.minecraft.tileentity.TileEntity)44 EnumFacing (net.minecraft.util.EnumFacing)20 IBlockState (net.minecraft.block.state.IBlockState)14 BlockPos (net.minecraft.util.BlockPos)13 World (net.minecraft.world.World)10 IPartialSealableBlock (micdoodle8.mods.galacticraft.api.block.IPartialSealableBlock)9 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)9 Block (net.minecraft.block.Block)9 ArrayList (java.util.ArrayList)7 FluidNetwork (micdoodle8.mods.galacticraft.core.fluid.FluidNetwork)7 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)7 NBTTagList (net.minecraft.nbt.NBTTagList)7 IConductor (micdoodle8.mods.galacticraft.api.transmission.tile.IConductor)6 TileEntityOxygenSealer (micdoodle8.mods.galacticraft.core.tile.TileEntityOxygenSealer)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 Entity (net.minecraft.entity.Entity)5 LinkedList (java.util.LinkedList)4 INetworkProvider (micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider)4 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)4