Search in sources :

Example 1 with BlockSpinThruster

use of micdoodle8.mods.galacticraft.core.blocks.BlockSpinThruster in project Galacticraft by micdoodle8.

the class GCBlocks method initBlocks.

public static void initBlocks() {
    GCBlocks.breatheableAir = new BlockBreathableAir("breatheable_air");
    GCBlocks.brightAir = new BlockBrightAir("bright_air");
    GCBlocks.brightBreatheableAir = new BlockBrightBreathableAir("bright_breathable_air");
    GCBlocks.brightLamp = new BlockBrightLamp("arclamp");
    GCBlocks.treasureChestTier1 = new BlockTier1TreasureChest("treasure_chest");
    GCBlocks.landingPad = new BlockLandingPad("landing_pad");
    GCBlocks.landingPadFull = new BlockLandingPadFull("landing_pad_full");
    GCBlocks.unlitTorch = new BlockUnlitTorch(false, "unlit_torch");
    GCBlocks.unlitTorchLit = new BlockUnlitTorch(true, "unlit_torch_lit");
    GCBlocks.oxygenDistributor = new BlockOxygenDistributor("distributor");
    GCBlocks.oxygenPipe = new BlockFluidPipe("fluid_pipe", BlockFluidPipe.EnumPipeMode.NORMAL);
    GCBlocks.oxygenPipePull = new BlockFluidPipe("fluid_pipe_pull", BlockFluidPipe.EnumPipeMode.PULL);
    GCBlocks.oxygenCollector = new BlockOxygenCollector("collector");
    GCBlocks.nasaWorkbench = new BlockNasaWorkbench("rocket_workbench");
    GCBlocks.fallenMeteor = new BlockFallenMeteor("fallen_meteor");
    GCBlocks.basicBlock = new BlockBasic("basic_block_core");
    GCBlocks.airLockFrame = new BlockAirLockFrame("air_lock_frame");
    GCBlocks.airLockSeal = new BlockAirLockWall("air_lock_seal");
    // These glass types have to be registered as 6 separate blocks, (a) to allow different coloring of each one and (b) because the Forge MultiLayer custom model does not allow for different textures to be set for different variants
    GCBlocks.spaceGlassVanilla = (BlockSpaceGlass) new BlockSpaceGlass("space_glass_vanilla", GlassType.VANILLA, GlassFrame.PLAIN, null).setHardness(0.3F).setResistance(3F);
    GCBlocks.spaceGlassClear = (BlockSpaceGlass) new BlockSpaceGlass("space_glass_clear", GlassType.CLEAR, GlassFrame.PLAIN, null).setHardness(0.3F).setResistance(3F);
    GCBlocks.spaceGlassStrong = (BlockSpaceGlass) new BlockSpaceGlass("space_glass_strong", GlassType.STRONG, GlassFrame.PLAIN, null).setHardness(4F).setResistance(35F);
    GCBlocks.spaceGlassTinVanilla = (BlockSpaceGlass) new BlockSpaceGlass("space_glass_vanilla_tin", GlassType.VANILLA, GlassFrame.TIN_DECO, GCBlocks.spaceGlassVanilla).setHardness(0.3F).setResistance(4F);
    GCBlocks.spaceGlassTinClear = (BlockSpaceGlass) new BlockSpaceGlass("space_glass_clear_tin", GlassType.CLEAR, GlassFrame.TIN_DECO, GCBlocks.spaceGlassClear).setHardness(0.3F).setResistance(4F);
    GCBlocks.spaceGlassTinStrong = (BlockSpaceGlass) new BlockSpaceGlass("space_glass_strong_tin", GlassType.STRONG, GlassFrame.TIN_DECO, GCBlocks.spaceGlassStrong).setHardness(4F).setResistance(35F);
    GCBlocks.crafting = new BlockCrafting("magnetic_table");
    GCBlocks.refinery = new BlockRefinery("refinery");
    GCBlocks.oxygenCompressor = new BlockOxygenCompressor(false, "oxygen_compressor");
    GCBlocks.fuelLoader = new BlockFuelLoader("fuel_loader");
    GCBlocks.spaceStationBase = new BlockSpaceStationBase("space_station_base");
    GCBlocks.fakeBlock = new BlockMulti("block_multi");
    GCBlocks.oxygenSealer = new BlockOxygenSealer("sealer");
    GCBlocks.sealableBlock = new BlockEnclosed("enclosed");
    GCBlocks.oxygenDetector = new BlockOxygenDetector("oxygen_detector");
    GCBlocks.cargoLoader = new BlockCargoLoader("cargo");
    GCBlocks.parachest = new BlockParaChest("parachest");
    GCBlocks.solarPanel = new BlockSolar("solar");
    GCBlocks.radioTelescope = new BlockDish("dishbase");
    GCBlocks.machineBase = new BlockMachine("machine");
    GCBlocks.machineBase2 = new BlockMachine2("machine2");
    GCBlocks.machineBase3 = new BlockMachine3("machine3");
    GCBlocks.machineTiered = new BlockMachineTiered("machine_tiered");
    GCBlocks.aluminumWire = new BlockAluminumWire("aluminum_wire");
    GCBlocks.panelLighting = new BlockPanelLighting("panel_lighting");
    GCBlocks.glowstoneTorch = new BlockGlowstoneTorch("glowstone_torch");
    GCBlocks.blockMoon = new BlockBasicMoon("basic_block_moon");
    GCBlocks.cheeseBlock = new BlockCheese("cheese");
    GCBlocks.spinThruster = new BlockSpinThruster("spin_thruster");
    GCBlocks.screen = new BlockScreen("view_screen");
    GCBlocks.telemetry = new BlockTelemetry("telemetry");
    GCBlocks.fluidTank = new BlockFluidTank("fluid_tank");
    GCBlocks.bossSpawner = new BlockBossSpawner("boss_spawner");
    GCBlocks.slabGCHalf = new BlockSlabGC("slab_gc_half", Material.rock);
    GCBlocks.slabGCDouble = new BlockDoubleSlabGC("slab_gc_double", Material.rock);
    GCBlocks.tinStairs1 = new BlockStairsGC("tin_stairs_1", basicBlock.getDefaultState().withProperty(BlockBasic.BASIC_TYPE, BlockBasic.EnumBlockBasic.ALUMINUM_DECORATION_BLOCK_0)).setHardness(2.0F);
    GCBlocks.tinStairs2 = new BlockStairsGC("tin_stairs_2", basicBlock.getDefaultState().withProperty(BlockBasic.BASIC_TYPE, BlockBasic.EnumBlockBasic.ALUMINUM_DECORATION_BLOCK_1)).setHardness(2.0F);
    GCBlocks.moonStoneStairs = new BlockStairsGC("moon_stairs_stone", blockMoon.getDefaultState().withProperty(BlockBasicMoon.BASIC_TYPE_MOON, BlockBasicMoon.EnumBlockBasicMoon.MOON_STONE)).setHardness(1.5F);
    GCBlocks.moonBricksStairs = new BlockStairsGC("moon_stairs_brick", blockMoon.getDefaultState().withProperty(BlockBasicMoon.BASIC_TYPE_MOON, BlockBasicMoon.EnumBlockBasicMoon.MOON_DUNGEON_BRICK)).setHardness(4.0F);
    GCBlocks.wallGC = new BlockWallGC("wall_gc");
    GCBlocks.concealedRedstone = new BlockConcealedRedstone("concealed_redstone");
    GCBlocks.concealedRepeater_Powered = new BlockConcealedRepeater("concealed_repeater_pow", true);
    GCBlocks.concealedRepeater_Unpowered = new BlockConcealedRepeater("concealed_repeater", false);
    GCBlocks.concealedDetector = new BlockConcealedDetector("concealed_detector");
    GCBlocks.platform = new BlockPlatform("platform");
    GCBlocks.emergencyBox = new BlockEmergencyBox("emergency_box");
    GCBlocks.grating = new BlockGrating("grating");
    // Hide certain items from NEI
    GCBlocks.hiddenBlocks.add(GCBlocks.airLockSeal);
    GCBlocks.hiddenBlocks.add(GCBlocks.oxygenPipePull);
    GCBlocks.hiddenBlocks.add(GCBlocks.unlitTorch);
    GCBlocks.hiddenBlocks.add(GCBlocks.unlitTorchLit);
    GCBlocks.hiddenBlocks.add(GCBlocks.landingPadFull);
    GCBlocks.hiddenBlocks.add(GCBlocks.spaceStationBase);
    GCBlocks.hiddenBlocks.add(GCBlocks.bossSpawner);
    GCBlocks.hiddenBlocks.add(GCBlocks.slabGCDouble);
    GCBlocks.hiddenBlocks.add(GCBlocks.concealedRepeater_Powered);
    // Register blocks before register ores, so that the ItemStack picks up the correct item
    GCBlocks.registerBlocks();
    GCBlocks.setHarvestLevels();
    // Complete registration of various types of torches
    BlockUnlitTorch.register((BlockUnlitTorch) GCBlocks.unlitTorch, (BlockUnlitTorch) GCBlocks.unlitTorchLit, Blocks.torch);
    OreDictionary.registerOre("oreCopper", new ItemStack(GCBlocks.basicBlock, 1, 5));
    OreDictionary.registerOre("oreCopper", new ItemStack(GCBlocks.blockMoon, 1, 0));
    OreDictionary.registerOre("oreTin", new ItemStack(GCBlocks.basicBlock, 1, 6));
    OreDictionary.registerOre("oreTin", new ItemStack(GCBlocks.blockMoon, 1, 1));
    OreDictionary.registerOre("oreAluminum", new ItemStack(GCBlocks.basicBlock, 1, 7));
    OreDictionary.registerOre("oreAluminium", new ItemStack(GCBlocks.basicBlock, 1, 7));
    OreDictionary.registerOre("oreNaturalAluminum", new ItemStack(GCBlocks.basicBlock, 1, 7));
    OreDictionary.registerOre("oreSilicon", new ItemStack(GCBlocks.basicBlock, 1, 8));
    OreDictionary.registerOre("oreCheese", new ItemStack(GCBlocks.blockMoon, 1, 2));
    OreDictionary.registerOre("blockCopper", new ItemStack(GCBlocks.basicBlock, 1, 9));
    OreDictionary.registerOre("blockTin", new ItemStack(GCBlocks.basicBlock, 1, 10));
    OreDictionary.registerOre("blockAluminum", new ItemStack(GCBlocks.basicBlock, 1, 11));
    OreDictionary.registerOre("blockAluminium", new ItemStack(GCBlocks.basicBlock, 1, 11));
    OreDictionary.registerOre("blockSilicon", new ItemStack(GCBlocks.basicBlock, 1, 13));
    OreDictionary.registerOre("turfMoon", new ItemStack(GCBlocks.blockMoon, 1, EnumBlockBasicMoon.MOON_TURF.getMeta()));
}
Also used : EnumBlockBasicMoon(micdoodle8.mods.galacticraft.core.blocks.BlockBasicMoon.EnumBlockBasicMoon) ItemStack(net.minecraft.item.ItemStack)

Example 2 with BlockSpinThruster

use of micdoodle8.mods.galacticraft.core.blocks.BlockSpinThruster in project Galacticraft by micdoodle8.

the class SpinManager method refresh.

/**
 * This will check all blocks which are in contact with each other to find
 * the shape of the spacestation. It also finds the centre of mass (to
 * rotate around) and the moment of inertia (how easy/hard this is to
 * rotate).
 * <p/>
 * If placingThruster is true, it will return false if the thruster (at
 * baseBlock) is not in contact with the "existing" spacestation - so the
 * player cannot place thrusters on outlying disconnected blocks and expect
 * them to have an effect.
 * <p/>
 * Note: this check will briefly load, server-side, all chunks which have
 * spacestation blocks in them or 1 block adjacent to those.
 *
 * @param baseBlock
 * @return
 */
public boolean refresh(BlockPos baseBlock, boolean placingThruster) {
    if (this.oneSSBlock == null || this.worldProvider.worldObj.getBlockState(this.oneSSBlock).getBlock().isAir(this.worldProvider.worldObj, this.oneSSBlock)) {
        if (baseBlock != null) {
            this.oneSSBlock = baseBlock;
        } else {
            this.oneSSBlock = new BlockPos(0, 64, 0);
        }
    }
    // Find contiguous blocks using an algorithm like the oxygen sealer one
    List<BlockVec3> currentLayer = new LinkedList<BlockVec3>();
    List<BlockVec3> nextLayer = new LinkedList<BlockVec3>();
    final List<BlockPos> foundThrusters = new LinkedList<BlockPos>();
    this.checked.clear();
    currentLayer.add(new BlockVec3(this.oneSSBlock));
    this.checked.add(new BlockVec3(this.oneSSBlock));
    Block bStart = this.worldProvider.worldObj.getBlockState(this.oneSSBlock).getBlock();
    if (bStart instanceof BlockSpinThruster) {
        foundThrusters.add(this.oneSSBlock);
    }
    // Mass of a thruster
    float thismass = 0.1F;
    float thismassCentreX = 0.1F * this.oneSSBlock.getX();
    float thismassCentreY = 0.1F * this.oneSSBlock.getY();
    float thismassCentreZ = 0.1F * this.oneSSBlock.getZ();
    float thismoment = 0F;
    int thisssBoundsMaxX = this.oneSSBlock.getX();
    int thisssBoundsMinX = this.oneSSBlock.getX();
    int thisssBoundsMaxY = this.oneSSBlock.getY();
    int thisssBoundsMinY = this.oneSSBlock.getY();
    int thisssBoundsMaxZ = this.oneSSBlock.getZ();
    int thisssBoundsMinZ = this.oneSSBlock.getZ();
    while (currentLayer.size() > 0) {
        int bits;
        for (BlockVec3 vec : currentLayer) {
            bits = vec.sideDoneBits;
            if (vec.x < thisssBoundsMinX) {
                thisssBoundsMinX = vec.x;
            }
            if (vec.y < thisssBoundsMinY) {
                thisssBoundsMinY = vec.y;
            }
            if (vec.z < thisssBoundsMinZ) {
                thisssBoundsMinZ = vec.z;
            }
            if (vec.x > thisssBoundsMaxX) {
                thisssBoundsMaxX = vec.x;
            }
            if (vec.y > thisssBoundsMaxY) {
                thisssBoundsMaxY = vec.y;
            }
            if (vec.z > thisssBoundsMaxZ) {
                thisssBoundsMaxZ = vec.z;
            }
            for (int side = 0; side < 6; side++) {
                if ((bits & (1 << side)) == 1) {
                    continue;
                }
                BlockVec3 sideVec = vec.newVecSide(side);
                if (sideVec != null && !this.checked.contains(sideVec)) {
                    this.checked.add(sideVec);
                    Block b = sideVec.getBlockID(this.worldProvider.worldObj);
                    if (b != null && !b.isAir(this.worldProvider.worldObj, sideVec.toBlockPos()) && !(b instanceof BlockDynamicLiquid)) {
                        nextLayer.add(sideVec);
                        if (bStart.isAir(this.worldProvider.worldObj, this.oneSSBlock)) {
                            this.oneSSBlock = sideVec.toBlockPos();
                            bStart = b;
                        }
                        float m = 1.0F;
                        // Liquids have a mass of 1, stone, metal blocks etc will be heavier
                        if (!(b instanceof BlockLiquid)) {
                            // For most blocks, hardness gives a good idea of mass
                            m = b.getBlockHardness(this.worldProvider.worldObj, sideVec.toBlockPos());
                            if (m < 0.1F) {
                                m = 0.1F;
                            } else if (m > 30F) {
                                m = 30F;
                            }
                            // Wood items have a high hardness compared with their presumed mass
                            if (b.getMaterial() == Material.wood) {
                                m /= 4;
                            }
                        // TODO: higher mass for future Galacticraft hi-density item like neutronium
                        // Maybe also check for things in other mods by name: lead, uranium blocks?
                        }
                        thismassCentreX += m * sideVec.x;
                        thismassCentreY += m * sideVec.y;
                        thismassCentreZ += m * sideVec.z;
                        thismass += m;
                        thismoment += m * (sideVec.x * sideVec.x + sideVec.z * sideVec.z);
                        if (b instanceof BlockSpinThruster && !RedstoneUtil.isBlockReceivingRedstone(this.worldProvider.worldObj, sideVec.toBlockPos())) {
                            foundThrusters.add(sideVec.toBlockPos());
                        }
                    }
                }
            }
        }
        currentLayer = nextLayer;
        nextLayer = new LinkedList<BlockVec3>();
    }
    if (placingThruster && !this.checked.contains(new BlockVec3(baseBlock))) {
        if (foundThrusters.size() > 0) {
            // The thruster was not placed on the existing contiguous space station: it must be.
            if (ConfigManagerCore.enableDebug) {
                GCLog.info("Thruster placed on wrong part of space station: base at " + this.oneSSBlock + " - baseBlock was " + baseBlock + " - found " + foundThrusters.size());
            }
            return false;
        }
        // (This first check prevents an infinite loop)
        if (!this.oneSSBlock.equals(baseBlock)) {
            this.oneSSBlock = baseBlock;
            if (this.worldProvider.worldObj.getBlockState(this.oneSSBlock).getBlock().getMaterial() != Material.air) {
                return this.refresh(baseBlock, true);
            }
        }
        return false;
    }
    // Update thruster lists based on what was found
    this.thrustersPlus.clear();
    this.thrustersMinus.clear();
    for (BlockPos thruster : foundThrusters) {
        IBlockState state = this.worldProvider.worldObj.getBlockState(thruster);
        int facing = state.getBlock().getMetaFromState(state) & 8;
        if (facing == 0) {
            this.thrustersPlus.add(thruster);
        } else {
            this.thrustersMinus.add(thruster);
        }
    }
    // Calculate centre of mass
    float mass = thismass;
    this.massCentreX = thismassCentreX / thismass + 0.5F;
    float massCentreY = thismassCentreY / thismass + 0.5F;
    this.massCentreZ = thismassCentreZ / thismass + 0.5F;
    // System.out.println("(X,Z) = "+this.massCentreX+","+this.massCentreZ);
    this.setSpinCentre(this.massCentreX, this.massCentreZ);
    // The boundary is at the outer edges of the blocks
    this.ssBoundsMaxX = thisssBoundsMaxX + 1;
    this.ssBoundsMinX = thisssBoundsMinX;
    this.ssBoundsMaxY = thisssBoundsMaxY + 1;
    this.ssBoundsMinY = thisssBoundsMinY;
    this.ssBoundsMaxZ = thisssBoundsMaxZ + 1;
    this.ssBoundsMinZ = thisssBoundsMinZ;
    // Calculate momentOfInertia
    thismoment -= this.massCentreX * this.massCentreX * mass;
    thismoment -= this.massCentreZ * this.massCentreZ * mass;
    this.momentOfInertia = thismoment;
    // TODO
    // TODO defy gravity
    // TODO break blocks which are outside SS (not in checked)
    // TODO prevent spin if there is a huge number of blocks outside SS
    GCLog.debug("MoI = " + this.momentOfInertia + " CoMx = " + this.massCentreX + " CoMz = " + this.massCentreZ);
    // Send packets to clients in this dimension
    List<Object> objList = new ArrayList<Object>();
    objList.add(Double.valueOf(this.spinCentreX));
    objList.add(Double.valueOf(this.spinCentreZ));
    GalacticraftCore.packetPipeline.sendToDimension(new PacketSimple(PacketSimple.EnumSimplePacket.C_UPDATE_STATION_DATA, GCCoreUtil.getDimensionID(this.worldProvider), objList), GCCoreUtil.getDimensionID(this.worldProvider));
    objList = new ArrayList<Object>();
    objList.add(Integer.valueOf(this.ssBoundsMinX));
    objList.add(Integer.valueOf(this.ssBoundsMaxX));
    objList.add(Integer.valueOf(this.ssBoundsMinY));
    objList.add(Integer.valueOf(this.ssBoundsMaxY));
    objList.add(Integer.valueOf(this.ssBoundsMinZ));
    objList.add(Integer.valueOf(this.ssBoundsMaxZ));
    GalacticraftCore.packetPipeline.sendToDimension(new PacketSimple(PacketSimple.EnumSimplePacket.C_UPDATE_STATION_BOX, GCCoreUtil.getDimensionID(this.worldProvider), objList), GCCoreUtil.getDimensionID(this.worldProvider));
    this.updateSpinSpeed();
    return true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ArrayList(java.util.ArrayList) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) BlockDynamicLiquid(net.minecraft.block.BlockDynamicLiquid) LinkedList(java.util.LinkedList) BlockLiquid(net.minecraft.block.BlockLiquid) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.BlockPos) BlockSpinThruster(micdoodle8.mods.galacticraft.core.blocks.BlockSpinThruster) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Aggregations

ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)1 EnumBlockBasicMoon (micdoodle8.mods.galacticraft.core.blocks.BlockBasicMoon.EnumBlockBasicMoon)1 BlockSpinThruster (micdoodle8.mods.galacticraft.core.blocks.BlockSpinThruster)1 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)1 Block (net.minecraft.block.Block)1 BlockDynamicLiquid (net.minecraft.block.BlockDynamicLiquid)1 BlockLiquid (net.minecraft.block.BlockLiquid)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityFallingBlock (net.minecraft.entity.item.EntityFallingBlock)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.BlockPos)1