Search in sources :

Example 36 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project Totemic by TeamTotemic.

the class BlockDrum method playDaMusicu.

public void playDaMusicu(WorldServer world, BlockPos pos, EntityPlayer player, TileDrum tileDrum, boolean isSneaking) {
    IBlockState state = world.getBlockState(pos);
    if (!isSneaking) {
        if (!(player instanceof FakePlayer)) {
            tileDrum.canPlay = false;
            Totemic.api.music().playMusic(world, pos, player, ModContent.drum);
            world.spawnParticle(EnumParticleTypes.NOTE, pos.getX() + 0.5, pos.getY() + 1.2, pos.getZ() + 0.5, 2, 0.0, 0.0, 0.0, 0.0);
            world.notifyBlockUpdate(pos, state, state, 7);
        }
    } else {
        tileDrum.canPlay = false;
        Totemic.api.music().playSelector(world, pos, player, ModContent.drum);
        world.spawnParticle(EnumParticleTypes.NOTE, pos.getX() + 0.5, pos.getY() + 1.2, pos.getZ() + 0.5, 2, 0.0, 0.0, 0.0, 0.0);
        world.spawnParticle(EnumParticleTypes.FIREWORKS_SPARK, pos.getX() + 0.5, pos.getY() + 1.2, pos.getZ() + 0.5, 2, 0.0, 0.0, 0.0, 0.0);
        world.notifyBlockUpdate(pos, state, state, 7);
    }
    TotemUtil.playSound(world, pos, ModSounds.drum, SoundCategory.PLAYERS, 1.0f, 1.0f);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 37 with FakePlayer

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

the class TileEngineCreative method onBlockActivated.

@Override
public boolean onBlockActivated(EntityPlayer player, EnumFacing side) {
    if (!getWorld().isRemote) {
        Item equipped = player.getCurrentEquippedItem() != null ? player.getCurrentEquippedItem().getItem() : null;
        if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(player, pos)) {
            powerMode = powerMode.getNext();
            energy = 0;
            if (!(player instanceof FakePlayer)) {
                if (BuildCraftCore.hidePowerNumbers) {
                    player.addChatMessage(new ChatComponentTranslation("chat.pipe.power.iron.mode.numberless", LocaleUtil.localize("chat.pipe.power.iron.level." + powerMode.maxPower)));
                } else {
                    player.addChatMessage(new ChatComponentTranslation("chat.pipe.power.iron.mode", powerMode.maxPower));
                }
            }
            sendNetworkUpdate();
            ((IToolWrench) equipped).wrenchUsed(player, pos);
            return true;
        }
    }
    return !player.isSneaking();
}
Also used : Item(net.minecraft.item.Item) IToolWrench(buildcraft.api.tools.IToolWrench) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 38 with FakePlayer

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

the class TemplateBuilder method doPlaceTask.

@Override
protected boolean doPlaceTask(PlaceTask placeTask) {
    FakePlayer fakePlayer = BuildCraftAPI.fakePlayerProvider.getFakePlayer((WorldServer) tile.getWorldBC(), tile.getOwner(), tile.getBuilderPos());
    fakePlayer.setHeldItem(fakePlayer.getActiveHand(), placeTask.items.get(0));
    return TemplateApi.templateRegistry.handle(tile.getWorldBC(), placeTask.pos, fakePlayer, placeTask.items.get(0));
}
Also used : FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 39 with FakePlayer

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

the class PipeBehaviourStripes method onDrop.

@PipeEventHandler
public void onDrop(PipeEventItem.Drop event) {
    if (direction == null) {
        return;
    }
    IPipeHolder holder = pipe.getHolder();
    World world = holder.getPipeWorld();
    BlockPos pos = holder.getPipePos();
    FakePlayer player = BuildCraftAPI.fakePlayerProvider.getFakePlayer((WorldServer) world, holder.getOwner(), pos);
    player.inventory.clear();
    // set the main hand of the fake player to the stack
    player.inventory.setInventorySlotContents(player.inventory.currentItem, event.getStack());
    if (PipeApi.stripeRegistry.handleItem(world, pos, direction, event.getStack(), player, this)) {
        event.setStack(StackUtil.EMPTY);
        for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
            ItemStack stack = player.inventory.removeStackFromSlot(i);
            if (!stack.isEmpty()) {
                sendItem(stack, direction);
            }
        }
    }
}
Also used : IPipeHolder(buildcraft.api.transport.pipe.IPipeHolder) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) FakePlayer(net.minecraftforge.common.util.FakePlayer) PipeEventHandler(buildcraft.api.transport.pipe.PipeEventHandler)

Example 40 with FakePlayer

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

the class BlockUtil method destroyBlock.

public static boolean destroyBlock(WorldServer world, BlockPos pos, @Nonnull ItemStack tool, GameProfile owner) {
    FakePlayer fakePlayer = getFakePlayerWithTool(world, tool, owner);
    BreakEvent breakEvent = new BreakEvent(world, pos, world.getBlockState(pos), fakePlayer);
    MinecraftForge.EVENT_BUS.post(breakEvent);
    if (breakEvent.isCanceled()) {
        return false;
    }
    world.destroyBlock(pos, true);
    return true;
}
Also used : BreakEvent(net.minecraftforge.event.world.BlockEvent.BreakEvent) 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