Search in sources :

Example 1 with IGalacticraftWorldProvider

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

the class AsteroidsEventHandlerClient method onClientTick.

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onClientTick(ClientTickEvent event) {
    Minecraft minecraft = Minecraft.getMinecraft();
    WorldClient world = minecraft.theWorld;
    if (world != null) {
        if (world.provider instanceof WorldProviderAsteroids) {
            if (world.provider.getSkyRenderer() == null) {
                world.provider.setSkyRenderer(new SkyProviderAsteroids((IGalacticraftWorldProvider) world.provider));
            }
            if (world.provider.getCloudRenderer() == null) {
                world.provider.setCloudRenderer(new CloudRenderer());
            }
        }
    }
}
Also used : IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) CloudRenderer(micdoodle8.mods.galacticraft.core.client.CloudRenderer) SkyProviderAsteroids(micdoodle8.mods.galacticraft.planets.asteroids.client.SkyProviderAsteroids) Minecraft(net.minecraft.client.Minecraft) WorldClient(net.minecraft.client.multiplayer.WorldClient) WorldProviderAsteroids(micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with IGalacticraftWorldProvider

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

the class TransformerHooks method getGravityForEntity.

public static double getGravityForEntity(Entity entity) {
    if (entity.worldObj.provider instanceof IGalacticraftWorldProvider) {
        if (entity instanceof EntityChicken && !OxygenUtil.isAABBInBreathableAirBlock(entity.worldObj, entity.getEntityBoundingBox())) {
            return 0.08D;
        }
        final IGalacticraftWorldProvider customProvider = (IGalacticraftWorldProvider) entity.worldObj.provider;
        if (entity instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) entity;
            if (player.inventory != null) {
                int armorModLowGrav = 100;
                int armorModHighGrav = 100;
                for (int i = 0; i < 4; i++) {
                    ItemStack armorPiece = player.getCurrentArmor(i);
                    if (armorPiece != null && armorPiece.getItem() instanceof IArmorGravity) {
                        armorModLowGrav -= ((IArmorGravity) armorPiece.getItem()).gravityOverrideIfLow(player);
                        armorModHighGrav -= ((IArmorGravity) armorPiece.getItem()).gravityOverrideIfHigh(player);
                    }
                }
                if (armorModLowGrav > 100) {
                    armorModLowGrav = 100;
                }
                if (armorModHighGrav > 100) {
                    armorModHighGrav = 100;
                }
                if (armorModLowGrav < 0) {
                    armorModLowGrav = 0;
                }
                if (armorModHighGrav < 0) {
                    armorModHighGrav = 0;
                }
                if (customProvider.getGravity() > 0) {
                    return 0.08D - (customProvider.getGravity() * armorModLowGrav) / 100;
                }
                return 0.08D - (customProvider.getGravity() * armorModHighGrav) / 100;
            }
        }
        return 0.08D - customProvider.getGravity();
    } else if (entity instanceof IAntiGrav) {
        return 0;
    } else {
        return 0.08D;
    }
}
Also used : IAntiGrav(micdoodle8.mods.galacticraft.api.entity.IAntiGrav) EntityChicken(net.minecraft.entity.passive.EntityChicken) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) IArmorGravity(micdoodle8.mods.galacticraft.api.item.IArmorGravity)

Example 3 with IGalacticraftWorldProvider

use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider 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 4 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.result == null) {
        return;
    }
    EntityPlayerSP player = FMLClientHandler.instance().getClient().thePlayer;
    if (player != null && player.worldObj != null && player.worldObj.provider instanceof IGalacticraftWorldProvider && event != null) {
        // Only modify standard game sounds, not music
        if (event.result.getAttenuationType() != ISound.AttenuationType.NONE) {
            PlayerGearData gearData = ClientProxyCore.playerItemData.get(PlayerUtil.getName(player));
            float x = event.result.getXPosF();
            float y = event.result.getYPosF();
            float z = event.result.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 = AxisAlignedBB.fromBounds(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.worldObj, bb);
                if ((!playerInAtmosphere || !soundInAtmosphere)) {
                    float volume = event.result.getVolume();
                    // 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.name) && 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.worldObj.provider).getSoundVolReductionAmount());
                    this.soundPlayList.add(new SoundPlayEntry(event.name, x, y, z, newVolume));
                    ISound newSound = new PositionedSoundRecord(event.result.getSoundLocation(), newVolume, event.result.getPitch(), x, y, z);
                    event.manager.playSound(newSound);
                    event.result = null;
                    return;
                }
            }
        }
    }
}
Also used : ISound(net.minecraft.client.audio.ISound) PositionedSoundRecord(net.minecraft.client.audio.PositionedSoundRecord) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) 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)

Example 5 with IGalacticraftWorldProvider

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

the class EventHandlerGC method entityLivingEvent.

@SubscribeEvent
public void entityLivingEvent(LivingUpdateEvent event) {
    final EntityLivingBase entityLiving = event.entityLiving;
    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.worldObj.provider instanceof IGalacticraftWorldProvider) {
            if (!(entityLiving instanceof EntityPlayer) && (!(entityLiving instanceof IEntityBreathable) || !((IEntityBreathable) entityLiving).canBreath()) && !((IGalacticraftWorldProvider) entityLiving.worldObj.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)

Aggregations

IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)38 ItemStack (net.minecraft.item.ItemStack)14 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)11 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 Block (net.minecraft.block.Block)7 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)6 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)6 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)5 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 BlockPos (net.minecraft.util.BlockPos)5 WorldServer (net.minecraft.world.WorldServer)5 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)5 WorldClient (net.minecraft.client.multiplayer.WorldClient)4 EntityAutoRocket (micdoodle8.mods.galacticraft.api.prefab.entity.EntityAutoRocket)3 EntitySpaceshipBase (micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase)3 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)3 EntityLanderBase (micdoodle8.mods.galacticraft.core.entities.EntityLanderBase)3 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)3