Search in sources :

Example 11 with IGalacticraftWorldProvider

use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.

the class TransformerHooks method otherModGenerate.

public static void otherModGenerate(int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
    if (world.provider instanceof WorldProviderSpaceStation) {
        return;
    }
    if (!(world.provider instanceof IGalacticraftWorldProvider) || ConfigManagerCore.enableOtherModsFeatures) {
        try {
            net.minecraftforge.fml.common.registry.GameRegistry.generateWorld(chunkX, chunkZ, world, chunkGenerator, chunkProvider);
        } catch (Exception e) {
            GCLog.severe("Error in another mod's worldgen.  This is *NOT* a Galacticraft bug, report it to the other mod please.");
            GCLog.severe("Details:- Dimension:" + GCCoreUtil.getDimensionID(world) + "  Chunk cx,cz:" + chunkX + "," + chunkZ + "  Seed:" + world.getSeed());
            e.printStackTrace();
        }
        return;
    }
    if (!generatorsInitialised) {
        generatorsInitialised = true;
        if (ConfigManagerCore.whitelistCoFHCoreGen) {
            addWorldGenForName("CoFHCore custom oregen", "cofh.cofhworld.init.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();
        }
    }
}
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 12 with IGalacticraftWorldProvider

use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.

the class EventHandlerGC method entityLivingEvent.

@SubscribeEvent
public void entityLivingEvent(LivingEvent.LivingUpdateEvent event) {
    final EntityLivingBase entityLiving = event.getEntityLiving();
    if (entityLiving instanceof EntityPlayerMP) {
        GalacticraftCore.handler.onPlayerUpdate((EntityPlayerMP) entityLiving);
        if (GalacticraftCore.isPlanetsLoaded) {
            AsteroidsModule.playerHandler.onPlayerUpdate((EntityPlayerMP) entityLiving);
        }
        return;
    }
    if (entityLiving.ticksExisted % ConfigManagerCore.suffocationCooldown == 0) {
        if (entityLiving.world.provider instanceof IGalacticraftWorldProvider) {
            if (!(entityLiving instanceof EntityPlayer) && (!(entityLiving instanceof IEntityBreathable) || !((IEntityBreathable) entityLiving).canBreath()) && !((IGalacticraftWorldProvider) entityLiving.world.provider).hasBreathableAtmosphere()) {
                if (!OxygenUtil.isAABBInBreathableAirBlock(entityLiving)) {
                    GCCoreOxygenSuffocationEvent suffocationEvent = new GCCoreOxygenSuffocationEvent.Pre(entityLiving);
                    MinecraftForge.EVENT_BUS.post(suffocationEvent);
                    if (suffocationEvent.isCanceled()) {
                        return;
                    }
                    entityLiving.attackEntityFrom(DamageSourceGC.oxygenSuffocation, Math.max(ConfigManagerCore.suffocationDamage / 2, 1));
                    GCCoreOxygenSuffocationEvent suffocationEventPost = new GCCoreOxygenSuffocationEvent.Post(entityLiving);
                    MinecraftForge.EVENT_BUS.post(suffocationEventPost);
                }
            }
        }
    }
}
Also used : IEntityBreathable(micdoodle8.mods.galacticraft.api.entity.IEntityBreathable) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) GCCoreOxygenSuffocationEvent(micdoodle8.mods.galacticraft.api.event.oxygen.GCCoreOxygenSuffocationEvent) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 13 with IGalacticraftWorldProvider

use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.

the class EventHandlerGC method onPlayerRightClickedBlock.

@SubscribeEvent
public void onPlayerRightClickedBlock(PlayerInteractEvent.RightClickBlock event) {
    // Skip events triggered from Thaumcraft Golems and other non-players
    if (event.getEntityPlayer() == null || event.getEntityPlayer().inventory == null || event.getPos() == null || (event.getPos().getX() == 0 && event.getPos().getY() == 0 && event.getPos().getZ() == 0)) {
        return;
    }
    final World worldObj = event.getEntityPlayer().world;
    if (worldObj == null) {
        return;
    }
    final Block idClicked = worldObj.getBlockState(event.getPos()).getBlock();
    if (idClicked == Blocks.BED && worldObj.provider instanceof IGalacticraftWorldProvider && !worldObj.isRemote && !((IGalacticraftWorldProvider) worldObj.provider).hasBreathableAtmosphere()) {
        if (GalacticraftCore.isPlanetsLoaded) {
            GCPlayerStats stats = GCPlayerStats.get(event.getEntityPlayer());
            if (!stats.hasReceivedBedWarning()) {
                event.getEntityPlayer().sendMessage(new TextComponentString(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.getEntityPlayer().setSpawnChunk(event.getPos(), false, GCCoreUtil.getDimensionID(event.getWorld()));
        } else {
            EventHandlerGC.bedActivated = false;
        }
    }
    final ItemStack heldStack = event.getEntityPlayer().inventory.getCurrentItem();
    final TileEntity tileClicked = worldObj.getTileEntity(event.getPos());
    if (!heldStack.isEmpty()) {
        if (tileClicked != null && tileClicked instanceof IKeyable) {
            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.getEntityPlayer(), heldStack, event.getFace()));
                } else if (!event.getEntityPlayer().isSneaking()) {
                    event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.getEntityPlayer(), event.getFace()));
                }
            } else {
                event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.getEntityPlayer(), event.getFace()));
            }
        }
        if (heldStack.getItem() instanceof ItemFlintAndSteel || heldStack.getItem() instanceof ItemFireball) {
            if (!worldObj.isRemote) {
                if (idClicked != Blocks.TNT && OxygenUtil.noAtmosphericCombustion(event.getEntityPlayer().world.provider) && !OxygenUtil.isAABBInBreathableAirBlock(event.getEntityLiving().world, new AxisAlignedBB(event.getPos().getX(), event.getPos().getY(), event.getPos().getZ(), event.getPos().getX() + 1, event.getPos().getY() + 2, event.getPos().getZ() + 1))) {
                    event.setCanceled(true);
                }
            }
        }
    } else if (tileClicked != null && tileClicked instanceof IKeyable) {
        event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.getEntityPlayer(), event.getFace()));
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ItemFireball(net.minecraft.item.ItemFireball) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) IKeyItem(micdoodle8.mods.galacticraft.api.item.IKeyItem) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) IKeyable(micdoodle8.mods.galacticraft.api.item.IKeyable) World(net.minecraft.world.World) TextComponentString(net.minecraft.util.text.TextComponentString) TileEntity(net.minecraft.tileentity.TileEntity) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) ItemFlintAndSteel(net.minecraft.item.ItemFlintAndSteel) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 14 with IGalacticraftWorldProvider

use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.

the class GCEntityClientPlayerMP method getLocationCape.

// 
// @Override
// @SideOnly(Side.CLIENT)
// public void setVelocity(double xx, double yy, double zz)
// {
// if (this.world.provider instanceof WorldProviderOrbit)
// {
// ((WorldProviderOrbit)this.world.provider).setVelocityClient(this, xx, yy, zz);
// }
// super.setVelocity(xx, yy, zz);
// }
// 
/*@Override
    public void setInPortal()
    {
    	if (!(this.world.provider instanceof IGalacticraftWorldProvider))
    	{
    		super.setInPortal();
    	}
    } TODO Fix disable of portal */
@Override
public ResourceLocation getLocationCape() {
    if (this.getRidingEntity() instanceof EntitySpaceshipBase) {
        // Don't draw any cape if riding a rocket (the cape renders outside the rocket model!)
        return null;
    }
    ResourceLocation vanillaCape = super.getLocationCape();
    if (!this.checkedCape) {
        NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
        this.galacticraftCape = ClientProxyCore.capeMap.get(networkplayerinfo.getGameProfile().getId().toString().replace("-", ""));
        this.checkedCape = true;
    }
    if ((ConfigManagerCore.overrideCapes || vanillaCape == null) && galacticraftCape != null) {
        return galacticraftCape;
    }
    return vanillaCape;
}
Also used : EntitySpaceshipBase(micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase) NetworkPlayerInfo(net.minecraft.client.network.NetworkPlayerInfo) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 15 with IGalacticraftWorldProvider

use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.

the class EventHandlerGC method onSoundPlayed.

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onSoundPlayed(PlaySoundEvent event) {
    // The event.result starts off equal to event.sound, but could have been altered or set to null by another mod
    if (event.getResultSound() == null) {
        return;
    }
    EntityPlayerSP player = FMLClientHandler.instance().getClient().player;
    if (player != null && player.world != null && player.world.provider instanceof IGalacticraftWorldProvider) {
        // Only modify standard game sounds, not music
        if (event.getResultSound().getAttenuationType() != ISound.AttenuationType.NONE) {
            PlayerGearData gearData = ClientProxyCore.playerItemData.get(PlayerUtil.getName(player));
            float x = event.getResultSound().getXPosF();
            float y = event.getResultSound().getYPosF();
            float z = event.getResultSound().getZPosF();
            if (gearData == null || gearData.getFrequencyModule() == -1) {
                // If the player doesn't have a frequency module, and the player isn't in an oxygenated environment
                // Note: this is a very simplistic approach, and nowhere near realistic, but required for performance reasons
                AxisAlignedBB bb = new AxisAlignedBB(x - 0.0015D, y - 0.0015D, z - 0.0015D, x + 0.0015D, y + 0.0015D, z + 0.0015D);
                boolean playerInAtmosphere = OxygenUtil.isAABBInBreathableAirBlock(player);
                boolean soundInAtmosphere = OxygenUtil.isAABBInBreathableAirBlock(player.world, bb);
                if ((!playerInAtmosphere || !soundInAtmosphere)) {
                    float volume = 1.0F;
                    float pitch = 1.0F;
                    if (volumeField == null) {
                        try {
                            // TODO Obfuscated environment support
                            volumeField = PositionedSound.class.getDeclaredField(GCCoreUtil.isDeobfuscated() ? "volume" : "field_147662_b");
                            volumeField.setAccessible(true);
                            // TODO Obfuscated environment support
                            pitchField = PositionedSound.class.getDeclaredField(GCCoreUtil.isDeobfuscated() ? "pitch" : "field_147663_c");
                            pitchField.setAccessible(true);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    if (volumeField != null && pitchField != null) {
                        try {
                            volume = event.getSound() instanceof PositionedSound ? (float) volumeField.get(event.getSound()) : 1.0F;
                            pitch = event.getSound() instanceof PositionedSound ? (float) pitchField.get(event.getSound()) : 1.0F;
                        } catch (IllegalAccessException e) {
                            e.printStackTrace();
                        }
                    }
                    // First check for duplicate firing of PlaySoundEvent17 on this handler's own playing of a reduced volume sound (see below)
                    for (int i = 0; i < this.soundPlayList.size(); i++) {
                        SoundPlayEntry entry = this.soundPlayList.get(i);
                        if (entry.name.equals(event.getName()) && entry.x == x && entry.y == y && entry.z == z && entry.volume == volume) {
                            this.soundPlayList.remove(i);
                            return;
                        }
                    }
                    // If it's not a duplicate: play the same sound but at reduced volume
                    float newVolume = volume / Math.max(0.01F, ((IGalacticraftWorldProvider) player.world.provider).getSoundVolReductionAmount());
                    this.soundPlayList.add(new SoundPlayEntry(event.getName(), x, y, z, newVolume));
                    SoundEvent soundEvent = SoundEvent.REGISTRY.getObject(event.getResultSound().getSoundLocation());
                    if (soundEvent != null) {
                        ISound newSound = new PositionedSoundRecord(soundEvent, SoundCategory.NEUTRAL, newVolume, pitch, x, y, z);
                        event.getManager().playSound(newSound);
                        event.setResultSound(null);
                    } else {
                        GCLog.severe("Sound event null! " + event.getName() + " " + event.getResultSound().getSoundLocation());
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) PositionedSound(net.minecraft.client.audio.PositionedSound) SoundEvent(net.minecraft.util.SoundEvent) PlaySoundEvent(net.minecraftforge.client.event.sound.PlaySoundEvent) ISound(net.minecraft.client.audio.ISound) PositionedSoundRecord(net.minecraft.client.audio.PositionedSoundRecord) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) PlayerGearData(micdoodle8.mods.galacticraft.core.wrappers.PlayerGearData) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)52 ItemStack (net.minecraft.item.ItemStack)16 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)14 BlockPos (net.minecraft.util.math.BlockPos)13 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)9 EntityPlayer (net.minecraft.entity.player.EntityPlayer)9 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)8 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)7 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)7 ResourceLocation (net.minecraft.util.ResourceLocation)7 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)6 IBlockState (net.minecraft.block.state.IBlockState)6 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)6 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)6 Block (net.minecraft.block.Block)5 WorldClient (net.minecraft.client.multiplayer.WorldClient)5 EnumFacing (net.minecraft.util.EnumFacing)5 WorldServer (net.minecraft.world.WorldServer)5 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)4 TileEntity (net.minecraft.tileentity.TileEntity)4