Search in sources :

Example 31 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project ForestryMC by ForestryMC.

the class ProxyNetwork method sendToPlayer.

public void sendToPlayer(ForestryPacket packet, EntityPlayer entityplayer) {
    if (!(entityplayer instanceof EntityPlayerMP) || (entityplayer instanceof FakePlayer)) {
        return;
    }
    EntityPlayerMP player = (EntityPlayerMP) entityplayer;
    Forestry.packetHandler.sendPacket(packet.getPacket(), player);
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 32 with FakePlayer

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

the class CreativeDagger method onItemRightClick.

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;
    }
    findAndFillAltar(world, player, Integer.MAX_VALUE);
    return stack;
}
Also used : SacrificeKnifeUsedEvent(WayofTime.alchemicalWizardry.api.event.SacrificeKnifeUsedEvent) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 33 with FakePlayer

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

the class BlockUtils method breakBlock.

/**
 * Tries breaking a block safely and fires an event for it.
 *
 * @return Whether the block was successfully broken
 */
public static boolean breakBlock(@Nonnull World world, @Nonnull BlockPos pos, @Nullable IBlockState oldState, @Nonnull EntityPlayerMP player) {
    if (!world.isBlockLoaded(pos))
        return false;
    if (!(player instanceof FakePlayer) && !hasEditPermission(pos, player))
        return false;
    if (oldState == null)
        oldState = world.getBlockState(pos);
    BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, oldState, player);
    MinecraftForge.EVENT_BUS.post(event);
    if (event.isCanceled())
        return false;
    TileEntity tile = world.getTileEntity(pos);
    Block block = oldState.getBlock();
    if (block.removedByPlayer(oldState, world, pos, player, true)) {
        block.onPlayerDestroy(world, pos, oldState);
        block.harvestBlock(world, player, pos, oldState, tile, player.getHeldItemMainhand());
        world.notifyBlockUpdate(pos, oldState, Blocks.AIR.getDefaultState(), 3);
    } else
        return false;
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Block(net.minecraft.block.Block) BlockEvent(net.minecraftforge.event.world.BlockEvent) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 34 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project Overloaded by CJ-MC-Mods.

the class TileItemManipulator method update.

@Override
public void update() {
    ItemStack currentItem = itemStack.getStackInSlot(0);
    if (currentItem.isEmpty())
        return;
    FakePlayer player = getPlayer();
    BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos(this.getPos());
    for (int i = 0; i < player.interactionManager.getBlockReachDistance(); i++) {
        if (!this.getWorld().isAirBlock(blockPos.move(this.facing))) {
            EnumActionResult result = currentItem.getItem().onItemUse(player, getWorld(), blockPos, EnumHand.MAIN_HAND, facing.getOpposite(), 0.5f, 0.5f, 0.5f);
            //                        blockPos,this.facing.getOpposite(),0.5f,0.5f,0.5f);
            break;
        }
    }
}
Also used : EnumActionResult(net.minecraft.util.EnumActionResult) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 35 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project Overloaded by CJ-MC-Mods.

the class TileItemManipulator method getPlayer.

private FakePlayer getPlayer() {
    if (this.player == null || this.player.get() == null) {
        FakePlayer fakePlayer = FakePlayerFactory.get((WorldServer) this.getWorld(), FAKEPLAYER);
        this.player = new WeakReference<>(fakePlayer);
        fakePlayer.setLocationAndAngles(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), 0f, 0f);
        fakePlayer.inventory.clear();
    }
    return this.player.get();
}
Also used : 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