Search in sources :

Example 61 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project OpenModularTurrets by OpenModularTurretsTeam.

the class OMTEventHandler method entityHurtEvent.

@SubscribeEvent
public void entityHurtEvent(LivingHurtEvent event) {
    EntityLivingBase entity = event.getEntityLiving();
    int fakeDrops = OMTUtil.getFakeDropsLevel(entity);
    if (fakeDrops >= 0) {
        FakePlayer player = OMTFakePlayer.getFakePlayer((WorldServer) event.getEntityLiving().getEntityWorld());
        player.setHeldItem(EnumHand.MAIN_HAND, OMTFakePlayer.getSword(fakeDrops));
        entity.setLastAttackedEntity(player);
    }
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) OMTFakePlayer(omtteam.openmodularturrets.util.OMTFakePlayer) FakePlayer(net.minecraftforge.common.util.FakePlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 62 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project Random-Things by lumien231.

the class RTEventHandler method livingDeath.

@SubscribeEvent
public void livingDeath(LivingDeathEvent event) {
    if (!event.getEntityLiving().world.isRemote) {
        if (event.getEntityLiving() instanceof EntityDragon) {
            RTWorldInformation rtInfo = RTWorldInformation.getInstance();
            if (rtInfo != null) {
                rtInfo.setEnderDragonDefeated(true);
            }
        }
        if (event.getSource().getTrueSource() != null && !(event.getSource().getTrueSource() instanceof FakePlayer) && event.getSource().getTrueSource() instanceof EntityPlayer && !(event.getEntity() instanceof EntitySpirit)) {
            double chance = Numbers.SPIRIT_CHANCE_NORMAL;
            RTWorldInformation rtInfo = RTWorldInformation.getInstance();
            if (rtInfo != null) {
                if (rtInfo.isDragonDefeated()) {
                    chance += Numbers.SPIRIT_CHANCE_END_INCREASE;
                }
            }
            if (event.getEntityLiving().world.canBlockSeeSky(event.getEntityLiving().getPosition()) && !event.getEntityLiving().world.isDaytime()) {
                chance += event.getEntityLiving().world.getCurrentMoonPhaseFactor() / 100f * Numbers.SPIRIT_CHANCE_MOON_MULT;
            }
            if (Math.random() < chance) {
                event.getEntityLiving().world.spawnEntity(new EntitySpirit(event.getEntityLiving().world, event.getEntity().posX, event.getEntity().posY, event.getEntity().posZ));
            }
        }
        if (event.getEntityLiving() instanceof EntityPlayer) {
            if (!(event.getEntityLiving() instanceof FakePlayer)) {
                EntityPlayer player = (EntityPlayer) event.getEntityLiving();
                if (!event.isCanceled()) {
                    player.world.spawnEntity(new EntitySoul(player.world, player.posX, player.posY, player.posZ, player.getGameProfile().getName()));
                }
            }
        }
    }
}
Also used : EntityDragon(net.minecraft.entity.boss.EntityDragon) EntitySpirit(lumien.randomthings.entitys.EntitySpirit) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntitySoul(lumien.randomthings.entitys.EntitySoul) FakePlayer(net.minecraftforge.common.util.FakePlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 63 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project Bookshelf by Darkhax-Minecraft.

the class PlayerUtils method getFakePlayer.

/**
 * Gets a fake player using their game profile. If there are no matching fake players a new
 * one will be created using the provided factory.
 *
 * @param world A world instance used to load the fake player. This will be passed to the
 *        factory if no matching fake players were found.
 * @param profile The profile of the fake player to find. This will be passed to the
 *        factory if there are no matching fake players.
 * @param factory A factory used to create the fake player if a match could not be found.
 * @return The fake player that was found or created.
 */
public static FakePlayer getFakePlayer(ServerWorld world, GameProfile profile, BiFunction<ServerWorld, GameProfile, FakePlayer> factory) {
    final Map<GameProfile, FakePlayer> fakePlayers = getCurrentFakePlayers();
    FakePlayer fakePlayer = fakePlayers.get(profile);
    if (fakePlayer == null) {
        fakePlayer = factory.apply(world, profile);
        fakePlayers.put(profile, fakePlayer);
    }
    return fakePlayer;
}
Also used : GameProfile(com.mojang.authlib.GameProfile) BookshelfFakePlayer(net.darkhax.bookshelf.entity.BookshelfFakePlayer) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 64 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project Pearcel-Mod by MiningMark48.

the class EventOnPlayerAttack method onPlayerAttack.

@SubscribeEvent
public void onPlayerAttack(LivingHurtEvent e) {
    if (e.getEntityLiving() instanceof FakePlayer) {
        return;
    }
    if (e.getSource().getEntity() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) e.getSource().getEntity();
        if (!player.isCreative()) {
            if (e.getEntityLiving().getHealth() - e.getAmount() <= 0) {
                if (player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() == ModItems.pearcel_blood_dagger) {
                    ItemStack stack = player.getHeldItemMainhand();
                    if (!stack.hasTagCompound()) {
                        stack.setTagCompound(new NBTTagCompound());
                        stack.getTagCompound().setInteger("level", 1);
                    } else {
                        if (stack.getTagCompound().getInteger("level") <= 8) {
                            stack.getTagCompound().setInteger("level", stack.getTagCompound().getInteger("level") + 1);
                        } else {
                            stack.getTagCompound().setInteger("level", 0);
                            EntityItem item = new EntityItem(player.getEntityWorld(), player.posX, player.posY + 0.5, player.posZ);
                            item.setEntityItemStack(new ItemStack(ModItems.blood_drop));
                            Random rand = new Random();
                            int num = rand.nextInt(2) + 1;
                            for (int i = 0; i <= num; i++) {
                                player.getEntityWorld().spawnEntity(item);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Random(java.util.Random) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) FakePlayer(net.minecraftforge.common.util.FakePlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 65 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project Armourers-Workshop by RiskyKen.

the class EquipmentWardrobeHandler method onRender.

@SubscribeEvent
public void onRender(RenderPlayerEvent.Post event) {
    EntityPlayer player = event.entityPlayer;
    if (player instanceof MannequinFakePlayer) {
        return;
    }
    if (player.getGameProfile() == null) {
        return;
    }
    if (player instanceof FakePlayer) {
        return;
    }
    // Restore the head overlay.
    PlayerPointer playerPointer = new PlayerPointer(player);
    RenderPlayer renderer = event.renderer;
    if (equipmentWardrobeMap.containsKey(playerPointer)) {
        renderer.modelBipedMain.bipedHeadwear.isHidden = false;
    }
}
Also used : PlayerPointer(riskyken.armourersWorkshop.common.data.PlayerPointer) MannequinFakePlayer(riskyken.armourersWorkshop.client.render.MannequinFakePlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) RenderPlayer(net.minecraft.client.renderer.entity.RenderPlayer) MannequinFakePlayer(riskyken.armourersWorkshop.client.render.MannequinFakePlayer) FakePlayer(net.minecraftforge.common.util.FakePlayer) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

FakePlayer (net.minecraftforge.common.util.FakePlayer)73 ItemStack (net.minecraft.item.ItemStack)26 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)17 EntityPlayer (net.minecraft.entity.player.EntityPlayer)16 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)15 IBlockState (net.minecraft.block.state.IBlockState)14 BlockPos (net.minecraft.util.math.BlockPos)11 EntityItem (net.minecraft.entity.item.EntityItem)10 World (net.minecraft.world.World)8 TileEntity (net.minecraft.tileentity.TileEntity)7 Block (net.minecraft.block.Block)6 BaseBlock (mcjty.lib.container.BaseBlock)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 IGregTechTileEntity (gregtech.api.interfaces.tileentity.IGregTechTileEntity)3 MannequinFakePlayer (riskyken.armourersWorkshop.client.render.MannequinFakePlayer)3 PlayerPointer (riskyken.armourersWorkshop.common.data.PlayerPointer)3 SacrificeKnifeUsedEvent (WayofTime.alchemicalWizardry.api.event.SacrificeKnifeUsedEvent)2 IMinerStats (cavern.api.IMinerStats)2