Search in sources :

Example 21 with FakePlayer

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

the class BlockUtil method breakBlock.

public static boolean breakBlock(WorldServer world, BlockPos pos, NonNullList<ItemStack> drops, BlockPos ownerPos, GameProfile owner) {
    FakePlayer fakePlayer = BuildCraftAPI.fakePlayerProvider.getFakePlayer(world, owner, ownerPos);
    BreakEvent breakEvent = new BreakEvent(world, pos, world.getBlockState(pos), fakePlayer);
    MinecraftForge.EVENT_BUS.post(breakEvent);
    if (breakEvent.isCanceled()) {
        return false;
    }
    if (!world.isAirBlock(pos) && !world.isRemote && world.getGameRules().getBoolean("doTileDrops")) {
        drops.addAll(getItemStackFromBlock(world, pos, owner));
    }
    world.setBlockToAir(pos);
    return true;
}
Also used : BreakEvent(net.minecraftforge.event.world.BlockEvent.BreakEvent) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 22 with FakePlayer

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

the class BlockUtil method harvestBlock.

public static boolean harvestBlock(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;
    }
    IBlockState state = world.getBlockState(pos);
    if (!state.getBlock().canHarvestBlock(world, pos, fakePlayer)) {
        return false;
    }
    state.getBlock().onBlockHarvested(world, pos, state, fakePlayer);
    state.getBlock().harvestBlock(world, fakePlayer, pos, state, world.getTileEntity(pos), tool);
    world.setBlockToAir(pos);
    return true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BreakEvent(net.minecraftforge.event.world.BlockEvent.BreakEvent) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 23 with FakePlayer

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

the class BlockUtil method getFakePlayerWithTool.

public static FakePlayer getFakePlayerWithTool(WorldServer world, @Nonnull ItemStack tool, GameProfile owner) {
    FakePlayer player = BuildCraftAPI.fakePlayerProvider.getFakePlayer(world, owner);
    int i = 0;
    while (player.getHeldItemMainhand() != tool && i < 9) {
        if (i > 0) {
            player.inventory.setInventorySlotContents(i - 1, StackUtil.EMPTY);
        }
        player.inventory.setInventorySlotContents(i, tool);
        i++;
    }
    return player;
}
Also used : FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 24 with FakePlayer

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

the class TileFloodGate method update.

// ITickable
@Override
public void update() {
    if (world.isRemote) {
        return;
    }
    if (tank.getFluidAmount() < Fluid.BUCKET_VOLUME) {
        return;
    }
    tick++;
    if (tick % 16 == 0) {
        if (!tank.isEmpty() && !queue.isEmpty()) {
            FluidStack fluid = tank.drain(Fluid.BUCKET_VOLUME, false);
            if (fluid != null && fluid.amount >= Fluid.BUCKET_VOLUME) {
                BlockPos currentPos = queue.removeLast();
                List<BlockPos> path = paths.get(currentPos);
                boolean canFill = true;
                if (path != null) {
                    for (BlockPos p : path) {
                        if (p.equals(currentPos)) {
                            continue;
                        }
                        if (!canFillThrough(currentPos)) {
                            canFill = false;
                            break;
                        }
                    }
                }
                if (canFill && canFill(currentPos)) {
                    FakePlayer fakePlayer = BuildCraftAPI.fakePlayerProvider.getFakePlayer((WorldServer) world, getOwner(), currentPos);
                    if (FluidUtil.tryPlaceFluid(fakePlayer, world, currentPos, tank, fluid)) {
                        for (EnumFacing side : EnumFacing.VALUES) {
                            world.notifyNeighborsOfStateChange(currentPos.offset(side), BCFactoryBlocks.floodGate, false);
                        }
                        delayIndex = 0;
                        tick = 0;
                    }
                } else {
                    buildQueue();
                }
            }
        }
    }
    if (queue.isEmpty() && tick % getCurrentDelay() == 0) {
        delayIndex = Math.min(delayIndex + 1, REBUILD_DELAYS.length - 1);
        tick = 0;
        buildQueue();
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 25 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project BiomesOPlenty by Glitchfiend.

the class ItemJarEmpty method itemInteractionForEntity.

@Override
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase target, EnumHand hand) {
    // right clicking a pixie with an empty jar catches it in the jar
    if (target instanceof EntityPixie) {
        EntityPixie pixie = (EntityPixie) target;
        pixie.setDead();
        stack.setCount(stack.getCount() - 1);
        ItemStack pixieJar = new ItemStack(BOPItems.jar_filled, 1, ItemJarFilled.JarContents.PIXIE.ordinal());
        EntityItem pixieJarEntity = new EntityItem(player.world, player.posX, player.posY, player.posZ, pixieJar);
        if (!player.world.isRemote) {
            player.world.spawnEntity(pixieJarEntity);
            if (!(player instanceof FakePlayer)) {
                pixieJarEntity.onCollideWithPlayer(player);
            }
        }
        return true;
    }
    return false;
}
Also used : ItemStack(net.minecraft.item.ItemStack) EntityPixie(biomesoplenty.common.entities.EntityPixie) EntityItem(net.minecraft.entity.item.EntityItem) 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