Search in sources :

Example 1 with WorldProviderSpaceStation

use of micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation in project Galacticraft by micdoodle8.

the class EventHandlerGC method onPlayerClicked.

@SubscribeEvent
public void onPlayerClicked(PlayerInteractEvent event) {
    // Skip events triggered from Thaumcraft Golems and other non-players
    if (event.entityPlayer == null || event.entityPlayer.inventory == null || event.pos == null || (event.pos.getX() == 0 && event.pos.getY() == 0 && event.pos.getZ() == 0)) {
        return;
    }
    final World worldObj = event.entityPlayer.worldObj;
    if (worldObj == null) {
        return;
    }
    final Block idClicked = worldObj.getBlockState(event.pos).getBlock();
    if (idClicked == Blocks.bed && worldObj.provider instanceof IGalacticraftWorldProvider && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) && !worldObj.isRemote && !((IGalacticraftWorldProvider) worldObj.provider).hasBreathableAtmosphere()) {
        if (GalacticraftCore.isPlanetsLoaded) {
            GCPlayerStats stats = GCPlayerStats.get(event.entityPlayer);
            if (!stats.hasReceivedBedWarning()) {
                event.entityPlayer.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.bed_fail.message")));
                stats.setReceivedBedWarning(true);
            }
        }
        if (worldObj.provider instanceof WorldProviderSpaceStation) {
            // On space stations simply block the bed activation => no explosion
            event.setCanceled(true);
            return;
        }
        // Optionally prevent beds from exploding - depends on canRespawnHere() in the WorldProvider interacting with this
        EventHandlerGC.bedActivated = true;
        if (worldObj.provider.canRespawnHere() && !EventHandlerGC.bedActivated) {
            EventHandlerGC.bedActivated = true;
            // On planets allow the bed to be used to designate a player spawn point
            event.entityPlayer.setSpawnChunk(event.pos, false, GCCoreUtil.getDimensionID(event.world));
        } else {
            EventHandlerGC.bedActivated = false;
        }
    }
    final ItemStack heldStack = event.entityPlayer.inventory.getCurrentItem();
    final TileEntity tileClicked = worldObj.getTileEntity(event.pos);
    if (heldStack != null) {
        if (tileClicked != null && tileClicked instanceof IKeyable) {
            if (event.action.equals(PlayerInteractEvent.Action.LEFT_CLICK_BLOCK)) {
                event.setCanceled(!((IKeyable) tileClicked).canBreak() && !event.entityPlayer.capabilities.isCreativeMode);
                return;
            } else if (event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)) {
                if (heldStack.getItem() instanceof IKeyItem) {
                    if (((IKeyItem) heldStack.getItem()).getTier(heldStack) == -1 || ((IKeyable) tileClicked).getTierOfKeyRequired() == -1 || ((IKeyItem) heldStack.getItem()).getTier(heldStack) == ((IKeyable) tileClicked).getTierOfKeyRequired()) {
                        event.setCanceled(((IKeyable) tileClicked).onValidKeyActivated(event.entityPlayer, heldStack, event.face));
                    } else {
                        event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.entityPlayer, event.face));
                    }
                } else if (!event.entityPlayer.isSneaking()) {
                    event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.entityPlayer, event.face));
                }
            }
        }
        if (heldStack.getItem() instanceof ItemFlintAndSteel || heldStack.getItem() instanceof ItemFireball) {
            if (!worldObj.isRemote && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)) {
                if (idClicked != Blocks.tnt && OxygenUtil.noAtmosphericCombustion(event.entityPlayer.worldObj.provider) && !OxygenUtil.isAABBInBreathableAirBlock(event.entityLiving.worldObj, AxisAlignedBB.fromBounds(event.pos.getX(), event.pos.getY(), event.pos.getZ(), event.pos.getX() + 1, event.pos.getY() + 2, event.pos.getZ() + 1))) {
                    event.setCanceled(true);
                }
            }
        }
    } else if (tileClicked != null && tileClicked instanceof IKeyable) {
        if (event.action.equals(PlayerInteractEvent.Action.LEFT_CLICK_BLOCK)) {
            event.setCanceled(!((IKeyable) tileClicked).canBreak() && !event.entityPlayer.capabilities.isCreativeMode);
            return;
        }
        event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.entityPlayer, event.face));
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ItemFireball(net.minecraft.item.ItemFireball) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) IKeyItem(micdoodle8.mods.galacticraft.api.item.IKeyItem) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) ItemFlintAndSteel(net.minecraft.item.ItemFlintAndSteel) Block(net.minecraft.block.Block) IKeyable(micdoodle8.mods.galacticraft.api.item.IKeyable) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with WorldProviderSpaceStation

use of micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation in project Galacticraft by micdoodle8.

the class OreGenOtherMods method onPlanetDecorated.

@SubscribeEvent
public void onPlanetDecorated(GCCoreEventPopulate.Post event) {
    this.worldObj = event.worldObj;
    this.randomGenerator = event.rand;
    this.pos = event.pos;
    int dimDetected = 0;
    WorldProvider prov = worldObj.provider;
    if (!(prov instanceof IGalacticraftWorldProvider) || (prov instanceof WorldProviderSpaceStation)) {
        return;
    }
    Block stoneBlock = null;
    int stoneMeta = 0;
    if (prov instanceof WorldProviderMoon) {
        stoneBlock = GCBlocks.blockMoon;
        stoneMeta = 4;
        dimDetected = 1;
    } else if (GalacticraftCore.isPlanetsLoaded && prov instanceof WorldProviderMars) {
        stoneBlock = MarsBlocks.marsBlock;
        stoneMeta = 9;
        dimDetected = 2;
    }
    if (stoneBlock == null) {
        return;
    }
    for (OreGenData ore : OreGenOtherMods.data) {
        if (ore.dimRestrict == 0 || ore.dimRestrict == dimDetected) {
            this.oreGen = new WorldGenMinableMeta(ore.oreBlock, ore.sizeCluster, ore.oreMeta, true, stoneBlock, stoneMeta);
            this.genStandardOre1(ore.numClusters, this.oreGen, ore.minHeight, ore.maxHeight);
        }
    }
}
Also used : WorldProviderMars(micdoodle8.mods.galacticraft.planets.mars.dimension.WorldProviderMars) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) WorldProvider(net.minecraft.world.WorldProvider) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) WorldProviderMoon(micdoodle8.mods.galacticraft.core.dimension.WorldProviderMoon) Block(net.minecraft.block.Block) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with WorldProviderSpaceStation

use of micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation in project Galacticraft by micdoodle8.

the class BlockSpinThruster method onUseWrench.

@Override
public boolean onUseWrench(World world, BlockPos pos, EntityPlayer entityPlayer, EnumFacing side, float hitX, float hitY, float hitZ) {
    EnumFacing currentFacing = world.getBlockState(pos).getValue(FACING);
    for (EnumFacing nextFacing = currentFacing.rotateY(); ; nextFacing = nextFacing.rotateY()) {
        if (this.canBlockStay(world, pos.offset(nextFacing.getOpposite()), nextFacing)) {
            world.setBlockState(pos, this.getStateFromMeta(nextFacing.getHorizontalIndex()), 2);
            break;
        }
        if (nextFacing == currentFacing) {
            break;
        }
    }
    if (world.provider instanceof WorldProviderSpaceStation && !world.isRemote) {
        WorldProviderSpaceStation worldOrbital = (WorldProviderSpaceStation) world.provider;
        worldOrbital.getSpinManager().refresh(pos, true);
    }
    return true;
}
Also used : WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)

Example 4 with WorldProviderSpaceStation

use of micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation in project Galacticraft by micdoodle8.

the class TransformerHooks method otherModPreventGenerate.

public static boolean otherModPreventGenerate(int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
    if (!(world.provider instanceof IGalacticraftWorldProvider)) {
        return false;
    }
    if (world.provider instanceof WorldProviderSpaceStation) {
        return true;
    }
    if (ConfigManagerCore.enableOtherModsFeatures) {
        return false;
    }
    if (!generatorsInitialised) {
        generatorsInitialised = true;
        if (ConfigManagerCore.whitelistCoFHCoreGen) {
            addWorldGenForName("CoFHCore custom oregen", "cofh.core.world.WorldHandler");
        }
        addWorldGenForName("GalacticGreg oregen", "bloodasp.galacticgreg.GT_Worldgenerator_Space");
        addWorldGenForName("Dense Ores oregen", "com.rwtema.denseores.WorldGenOres");
        addWorldGenForName("AE2 meteorites worldgen", "appeng.worldgen.MeteoriteWorldGen");
        try {
            Class genThaumCraft = Class.forName("thaumcraft.common.lib.world.ThaumcraftWorldGenerator");
            if (genThaumCraft != null && ConfigManagerCore.enableThaumCraftNodes) {
                final Field regField = GameRegistry.class.getDeclaredField("worldGenerators");
                regField.setAccessible(true);
                Set<IWorldGenerator> registeredGenerators = (Set<IWorldGenerator>) regField.get(null);
                for (IWorldGenerator gen : registeredGenerators) {
                    if (genThaumCraft.isInstance(gen)) {
                        generatorTCAuraNodes = gen;
                        break;
                    }
                }
                if (generatorTCAuraNodes != null) {
                    generateTCAuraNodes = genThaumCraft.getDeclaredMethod("generateWildNodes", World.class, Random.class, int.class, int.class, boolean.class, boolean.class);
                    generateTCAuraNodes.setAccessible(true);
                    GCLog.info("Whitelisting ThaumCraft aura node generation on planets.");
                }
            }
        } catch (Exception e) {
        }
    }
    if (otherModGeneratorsWhitelist.size() > 0 || generateTCAuraNodes != null) {
        try {
            long worldSeed = world.getSeed();
            Random fmlRandom = new Random(worldSeed);
            long xSeed = fmlRandom.nextLong() >> 2 + 1L;
            long zSeed = fmlRandom.nextLong() >> 2 + 1L;
            long chunkSeed = (xSeed * chunkX + zSeed * chunkZ) ^ worldSeed;
            fmlRandom.setSeed(chunkSeed);
            for (IWorldGenerator gen : otherModGeneratorsWhitelist) {
                gen.generate(fmlRandom, chunkX, chunkZ, world, chunkGenerator, chunkProvider);
            }
            if (generateTCAuraNodes != null) {
                generateTCAuraNodes.invoke(generatorTCAuraNodes, world, fmlRandom, chunkX, chunkZ, false, true);
            }
        } catch (Exception e) {
            GCLog.severe("Error in another mod's worldgen.  This is *NOT* a Galacticraft bug, report it to the other mod please.");
            e.printStackTrace();
        }
    }
    return true;
}
Also used : Field(java.lang.reflect.Field) Set(java.util.Set) Random(java.util.Random) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) World(net.minecraft.world.World) IWorldGenerator(net.minecraftforge.fml.common.IWorldGenerator)

Example 5 with WorldProviderSpaceStation

use of micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation in project Galacticraft by micdoodle8.

the class FreefallHandler method postVanillaMotion.

@SideOnly(Side.CLIENT)
public void postVanillaMotion(EntityPlayerSP p) {
    World world = p.worldObj;
    WorldProvider worldProvider = world.provider;
    if (!(worldProvider instanceof IZeroGDimension)) {
        return;
    }
    ZeroGravityEvent zeroGEvent = new ZeroGravityEvent.Motion(p);
    MinecraftForge.EVENT_BUS.post(zeroGEvent);
    if (zeroGEvent.isCanceled()) {
        return;
    }
    boolean freefall = stats.isInFreefall();
    freefall = this.testFreefall(p, freefall);
    stats.setInFreefall(freefall);
    stats.setInFreefallFirstCheck(true);
    SpinManager spinManager = null;
    if (worldProvider instanceof WorldProviderSpaceStation && !stats.getPlatformControlled()) {
        spinManager = ((WorldProviderSpaceStation) worldProvider).getSpinManager();
    }
    boolean doCentrifugal = spinManager != null;
    if (freefall) {
        this.pjumpticks = 0;
        // Reverse effects of deceleration
        p.motionX /= 0.91F;
        p.motionZ /= 0.91F;
        p.motionY /= 0.9800000190734863D;
        if (spinManager != null) {
            doCentrifugal = spinManager.updatePlayerForSpin(p, 1F);
        }
        // Do freefall motion
        if (!p.capabilities.isCreativeMode) {
            this.freefallMotion(p);
        } else {
            p.capabilities.isFlying = true;
            // Half the normal acceleration in Creative mode
            double dx = p.motionX - this.pPrevMotionX;
            double dy = p.motionY - this.pPrevMotionY;
            double dz = p.motionZ - this.pPrevMotionZ;
            p.motionX -= dx / 2;
            p.motionY -= dy / 2;
            p.motionZ -= dz / 2;
            if (p.motionX > 1.2F) {
                p.motionX = 1.2F;
            }
            if (p.motionX < -1.2F) {
                p.motionX = -1.2F;
            }
            if (p.motionY > 0.7F) {
                p.motionY = 0.7F;
            }
            if (p.motionY < -0.7F) {
                p.motionY = -0.7F;
            }
            if (p.motionZ > 1.2F) {
                p.motionZ = 1.2F;
            }
            if (p.motionZ < -1.2F) {
                p.motionZ = -1.2F;
            }
        }
    // TODO: Think about endless drift?
    // Player may run out of oxygen - that will kill the player eventually if can't get back to SS
    // Could auto-kill + respawn the player if floats too far away (config option whether to lose items or not)
    // But we want players to be able to enjoy the view of the spinning space station from the outside
    // Arm and leg movements could start tumbling the player?
    } else // Not freefall - within arm's length of something or jumping
    {
        double dy = p.motionY - this.pPrevMotionY;
        // if (p.motionY != 0) p.motionY = this.pPrevMotionY;
        if (p.movementInput.jump) {
            if ((p.onGround || stats.isSsOnGroundLast()) && !p.capabilities.isCreativeMode) {
                if (this.pjumpticks < 25)
                    this.pjumpticks++;
                p.motionY -= dy;
            } else {
                p.motionY += 0.015D;
                if (this.pjumpticks == 0) {
                    p.motionY -= dy;
                }
            }
        } else if (this.pjumpticks > 0) {
            p.motionY += 0.0145D * this.pjumpticks;
            this.pjumpticks = 0;
        } else if (p.movementInput.sneak) {
            if (!p.onGround) {
                p.motionY -= 0.015D;
            }
            this.pjumpticks = 0;
        }
    }
    // Artificial gravity
    if (doCentrifugal && !p.onGround) {
        spinManager.applyCentrifugalForce(p);
    }
    this.pPrevMotionX = p.motionX;
    this.pPrevMotionY = p.motionY;
    this.pPrevMotionZ = p.motionZ;
}
Also used : ZeroGravityEvent(micdoodle8.mods.galacticraft.api.event.ZeroGravityEvent) SpinManager(micdoodle8.mods.galacticraft.core.dimension.SpinManager) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) WorldProvider(net.minecraft.world.WorldProvider) World(net.minecraft.world.World) IZeroGDimension(micdoodle8.mods.galacticraft.api.world.IZeroGDimension) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)15 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)6 Block (net.minecraft.block.Block)6 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)5 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)4 World (net.minecraft.world.World)4 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)4 EntitySpaceshipBase (micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase)3 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)3 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)3 IZeroGDimension (micdoodle8.mods.galacticraft.api.world.IZeroGDimension)3 SpaceRace (micdoodle8.mods.galacticraft.core.dimension.SpaceRace)3 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)3 S07PacketRespawn (net.minecraft.network.play.server.S07PacketRespawn)3 TileEntity (net.minecraft.tileentity.TileEntity)3 WorldProvider (net.minecraft.world.WorldProvider)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 Field (java.lang.reflect.Field)2 ZeroGravityEvent (micdoodle8.mods.galacticraft.api.event.ZeroGravityEvent)2 GuiCelestialSelection (micdoodle8.mods.galacticraft.core.client.gui.screen.GuiCelestialSelection)2