Search in sources :

Example 76 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project Galacticraft by micdoodle8.

the class ItemTier1Rocket method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = playerIn.getHeldItem(hand);
    boolean padFound = false;
    TileEntity tile = null;
    if (worldIn.isRemote && playerIn instanceof EntityPlayerSP) {
        ClientProxyCore.playerClientHandler.onBuild(8, (EntityPlayerSP) playerIn);
        return EnumActionResult.PASS;
    } else {
        float centerX = -1;
        float centerY = -1;
        float centerZ = -1;
        for (int i = -1; i < 2; i++) {
            for (int j = -1; j < 2; j++) {
                BlockPos pos1 = pos.add(i, 0, j);
                IBlockState state = worldIn.getBlockState(pos1);
                final Block id = state.getBlock();
                int meta = id.getMetaFromState(state);
                if (id == GCBlocks.landingPadFull && meta == 0) {
                    padFound = true;
                    tile = worldIn.getTileEntity(pos.add(i, 0, j));
                    centerX = pos.getX() + i + 0.5F;
                    centerY = pos.getY() + 0.4F;
                    centerZ = pos.getZ() + j + 0.5F;
                    break;
                }
            }
            if (padFound) {
                break;
            }
        }
        if (padFound) {
            if (!placeRocketOnPad(stack, worldIn, tile, centerX, centerY, centerZ)) {
                return EnumActionResult.FAIL;
            }
            if (!playerIn.capabilities.isCreativeMode) {
                stack.shrink(1);
            }
            return EnumActionResult.SUCCESS;
        } else {
            return EnumActionResult.PASS;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 77 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project Galacticraft by micdoodle8.

the class PacketSimpleAsteroids method handleClientSide.

@SideOnly(Side.CLIENT)
@Override
public void handleClientSide(EntityPlayer player) {
    EntityPlayerSP playerBaseClient = null;
    if (player instanceof EntityPlayerSP) {
        playerBaseClient = (EntityPlayerSP) player;
    }
    TileEntity tile;
    switch(this.type) {
        case C_TELEPAD_SEND:
            Entity entity = playerBaseClient.world.getEntityByID((Integer) this.data.get(1));
            if (entity != null && entity instanceof EntityLivingBase) {
                BlockVec3 pos = (BlockVec3) this.data.get(0);
                entity.setPosition(pos.x + 0.5, pos.y + 2.2, pos.z + 0.5);
            }
            break;
        case C_UPDATE_GRAPPLE_POS:
            entity = playerBaseClient.world.getEntityByID((Integer) this.data.get(0));
            if (entity != null && entity instanceof EntityGrapple) {
                Vector3 vec = (Vector3) this.data.get(1);
                entity.setPosition(vec.x, vec.y, vec.z);
            }
            break;
        default:
            break;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityGrapple(micdoodle8.mods.galacticraft.planets.asteroids.entities.EntityGrapple) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 78 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project Galacticraft by micdoodle8.

the class TransformerHooks method getFogColorHook.

@SideOnly(Side.CLIENT)
public static Vec3d getFogColorHook(World world) {
    EntityPlayerSP player = FMLClientHandler.instance().getClient().player;
    if (world.provider.getSkyRenderer() instanceof SkyProviderOverworld) {
        float var20 = ((float) (player.posY) - Constants.OVERWORLD_SKYPROVIDER_STARTHEIGHT) / 1000.0F;
        var20 = MathHelper.sqrt(var20);
        final float var21 = Math.max(1.0F - var20 * 40.0F, 0.0F);
        Vec3d vec = world.getFogColor(1.0F);
        return new Vec3d(vec.x * Math.max(1.0F - var20 * 1.29F, 0.0F), vec.y * Math.max(1.0F - var20 * 1.29F, 0.0F), vec.z * Math.max(1.0F - var20 * 1.29F, 0.0F));
    }
    return world.getFogColor(1.0F);
}
Also used : SkyProviderOverworld(micdoodle8.mods.galacticraft.core.client.SkyProviderOverworld) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) Vec3d(net.minecraft.util.math.Vec3d) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 79 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project Galacticraft by micdoodle8.

the class EventHandlerGC method getNextSchematic.

@SideOnly(Side.CLIENT)
private static ISchematicPage getNextSchematic(int currentIndex) {
    EntityPlayerSP player = PlayerUtil.getPlayerBaseClientFromPlayer(FMLClientHandler.instance().getClient().player, false);
    GCPlayerStatsClient stats = GCPlayerStatsClient.get(player);
    final int size = stats.getUnlockedSchematics().size();
    final HashMap<Integer, Integer> idList = new HashMap<Integer, Integer>(size, 1F);
    for (int i = 0; i < size; i++) {
        idList.put(i, stats.getUnlockedSchematics().get(i).getPageID());
    }
    final SortedSet<Integer> keys = new TreeSet<Integer>(idList.keySet());
    final Iterator<Integer> iterator = keys.iterator();
    for (int count = 0; count < keys.size(); count++) {
        final int i = iterator.next();
        final ISchematicPage page = SchematicRegistry.getMatchingRecipeForID(idList.get(i));
        if (page.getPageID() == currentIndex) {
            if (count + 1 < stats.getUnlockedSchematics().size()) {
                return stats.getUnlockedSchematics().get(count + 1);
            } else {
                return null;
            }
        }
    }
    return null;
}
Also used : GCPlayerStatsClient(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStatsClient) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ISchematicPage(micdoodle8.mods.galacticraft.api.recipe.ISchematicPage) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 80 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP 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

EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)158 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)31 Minecraft (net.minecraft.client.Minecraft)29 ItemStack (net.minecraft.item.ItemStack)29 BlockPos (net.minecraft.util.math.BlockPos)27 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)23 Entity (net.minecraft.entity.Entity)21 EntityPlayer (net.minecraft.entity.player.EntityPlayer)13 TileEntity (net.minecraft.tileentity.TileEntity)13 WorldClient (net.minecraft.client.multiplayer.WorldClient)11 IBlockState (net.minecraft.block.state.IBlockState)10 Tessellator (net.minecraft.client.renderer.Tessellator)10 GCPlayerStatsClient (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStatsClient)8 ArrayList (java.util.ArrayList)6 Block (net.minecraft.block.Block)6 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)6 Vec3d (net.minecraft.util.math.Vec3d)6 World (net.minecraft.world.World)6 UUID (java.util.UUID)5 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)5