Search in sources :

Example 6 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 7 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)

Example 8 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)

Aggregations

FakePlayer (net.minecraftforge.common.util.FakePlayer)8 ItemStack (net.minecraft.item.ItemStack)4 EntityItem (net.minecraft.entity.item.EntityItem)3 IBlockState (net.minecraft.block.state.IBlockState)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 Container (net.minecraft.inventory.Container)2 BlockPos (net.minecraft.util.math.BlockPos)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 JsonObject (com.google.gson.JsonObject)1 ByteBuf (io.netty.buffer.ByteBuf)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 PacketOpenGui (ivorius.reccomplex.network.PacketOpenGui)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Block (net.minecraft.block.Block)1 Item (net.minecraft.item.Item)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 World (net.minecraft.world.World)1