Search in sources :

Example 71 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project BloodMagic by WayofTime.

the class ItemDiabloKey method onItemRightClick.

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    World world = par3EntityPlayer.worldObj;
    if (!EnergyItems.checkAndSetItemOwner(par1ItemStack, par3EntityPlayer) || par3EntityPlayer instanceof FakePlayer || par3EntityPlayer instanceof EntityPlayerMP) {
        return par1ItemStack;
    }
    if (world != null) {
        double posX = par3EntityPlayer.posX;
        double posY = par3EntityPlayer.posY;
        double posZ = par3EntityPlayer.posZ;
        world.playSoundEffect((double) ((float) posX + 0.5F), (double) ((float) posY + 0.5F), (double) ((float) posZ + 0.5F), "random.fizz", 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
        SpellHelper.sendIndexedParticleToAllAround(world, posX, posY, posZ, 20, world.provider.dimensionId, 4, posX, posY, posZ);
    }
    if (!par3EntityPlayer.worldObj.isRemote && !(par3EntityPlayer.getClass().equals(EntityPlayerMP.class))) {
        return par1ItemStack;
    }
    if (par3EntityPlayer.isSneaking()) {
        return par1ItemStack;
    }
    NBTTagCompound itemTag = par1ItemStack.getTagCompound();
    if (itemTag == null || itemTag.getString("ownerName").equals("")) {
        return par1ItemStack;
    }
    String ownerName = itemTag.getString("ownerName");
    ItemStack[] inv = par3EntityPlayer.inventory.mainInventory;
    for (ItemStack itemStack : inv) {
        if (itemStack == null) {
            continue;
        }
        Item item = itemStack.getItem();
        if (item instanceof ItemDiabloKey) {
            continue;
        }
        if (item instanceof IBindable) {
            EnergyItems.checkAndSetItemOwner(itemStack, ownerName);
        }
    }
    return par1ItemStack;
}
Also used : Item(net.minecraft.item.Item) IBindable(WayofTime.alchemicalWizardry.api.items.interfaces.IBindable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 72 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project BloodMagic by WayofTime.

the class SacrificialDagger method onItemRightClick.

@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
    if (this.canUseForSacrifice(stack)) {
        player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
        return stack;
    }
    if (!player.capabilities.isCreativeMode) {
        SacrificeKnifeUsedEvent evt = new SacrificeKnifeUsedEvent(player, true, true, 2);
        if (MinecraftForge.EVENT_BUS.post(evt)) {
            return stack;
        }
        if (evt.shouldDrainHealth) {
            player.setHealth(player.getHealth() - 2);
        }
        if (!evt.shouldFillAltar) {
            return stack;
        }
    }
    if (player instanceof FakePlayer) {
        return stack;
    }
    double posX = player.posX;
    double posY = player.posY;
    double posZ = player.posZ;
    world.playSoundEffect((double) ((float) posX + 0.5F), (double) ((float) posY + 0.5F), (double) ((float) posZ + 0.5F), "random.fizz", 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
    float f = 1.0F;
    float f1 = f * 0.6F + 0.4F;
    float f2 = f * f * 0.7F - 0.5F;
    float f3 = f * f * 0.6F - 0.7F;
    for (int l = 0; l < 8; ++l) {
        world.spawnParticle("reddust", posX + Math.random() - Math.random(), posY + Math.random() - Math.random(), posZ + Math.random() - Math.random(), f1, f2, f3);
    }
    if (!world.isRemote && SpellHelper.isFakePlayer(world, player)) {
        return stack;
    }
    if (player.isPotionActive(AlchemicalWizardry.customPotionSoulFray)) {
        findAndFillAltar(world, player, 20);
    } else {
        findAndFillAltar(world, player, 200);
    }
    if (player.getHealth() <= 0.001f) {
        player.onDeath(DamageSource.generic);
    }
    return stack;
}
Also used : SacrificeKnifeUsedEvent(WayofTime.alchemicalWizardry.api.event.SacrificeKnifeUsedEvent) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 73 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project Wizardry by TeamWizardry.

the class BlockUtils method placeBlock.

public static boolean placeBlock(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing facing, @Nonnull ItemStack stack) {
    if (!world.isBlockLoaded(pos))
        return false;
    FakePlayer player = FakePlayerFactory.get((WorldServer) world, PLACER);
    player.moveToBlockPosAndAngles(pos, 0, -90);
    player.setHeldItem(EnumHand.MAIN_HAND, stack);
    player.setSneaking(true);
    if (!hasEditPermission(pos, player))
        return false;
    EnumActionResult result = player.interactionManager.processRightClickBlock(player, world, stack, EnumHand.MAIN_HAND, pos, facing, 0, 0, 0);
    return result != EnumActionResult.FAIL;
}
Also used : EnumActionResult(net.minecraft.util.EnumActionResult) FakePlayer(net.minecraftforge.common.util.FakePlayer)

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