Ejemplo n.º 1
0
        public override ItemStack onRightClick(World world, EntityPlayer player, ItemStack stack, PlayerRayHit hit)
        {
            Transform camera = player.mainCamera;

            Entity entity = world.spawnEntity(this.registeredEntity, camera.position + camera.forward * 1.5f, camera.rotation);

            entity.gameObject.GetComponent <Rigidbody>().AddForce(camera.forward * this.getThrowSpeed(), ForceMode.Impulse);

            return(stack.safeDeduction());
        }
Ejemplo n.º 2
0
        public override ItemStack onRightClick(World world, EntityPlayer player, ItemStack stack, PlayerRayHit hit)
        {
            string s = null;

            if (hit.unityRaycastHit.distance <= player.getReach())
            {
                if (hit.hitState.block != null)
                {
                    s = ObjectData.getInfo(hit.hitState.block);
                }
                else if (hit.entity != null)
                {
                    s = hit.entity.getMagnifyingText();
                }
                if (s != null)
                {
                    player.setMagnifyingText(s);
                }
            }
            return(stack);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Callback for when the player clicks while holding this item.  Return the passed in item stack.
 /// </summary>
 public virtual ItemStack onRightClick(World world, EntityPlayer player, ItemStack stack, PlayerRayHit hit)
 {
     return(stack);
 }
Ejemplo n.º 4
0
        public void handleInput()
        {
            this.playerMover.updateMover();

            bool      isShiftDown = Input.GetKey(KeyCode.LeftShift);
            ItemStack heldStack   = this.containerHotbar.getHeldItem();

            // Find out what the player is looking at.
            PlayerRayHit playerHit = this.getPlayerRayHit();

            if (playerHit != null)
            {
                // We are looking at something
                if (playerHit.hitBlock())
                {
                    if (Input.GetMouseButton(0))
                    {
                        this.blockBreakEffect.update(this, (BlockPos)this.posLookingAt, playerHit.hitState.block, playerHit.hitState.meta);
                    }
                    if (Input.GetMouseButtonDown(1))
                    {
                        bool flag = playerHit.hitState.block.onRightClick(
                            this.world,
                            this,
                            heldStack,
                            (BlockPos)this.posLookingAt,
                            playerHit.hitState.meta,
                            playerHit.getClickedBlockFace(),
                            playerHit.unityRaycastHit.point - ((BlockPos)this.posLookingAt).toVector());
                        if (!flag)
                        {
                            if (heldStack != null)
                            {
                                ItemStack clickResult = heldStack.item.onRightClick(this.world, this, heldStack, playerHit);
                                this.containerHotbar.setHeldItem(clickResult);
                            }
                        }
                    }
                }
                else if (playerHit.hitEntity())
                {
                    if (playerHit.entity is EntityLiving && Input.GetMouseButtonDown(0))
                    {
                        // Player is hitting an entity
                        int damage = 1;
                        if (heldStack != null && heldStack.item is ItemSword)
                        {
                            damage = ((ItemSword)heldStack.item).damageAmount;
                        }
                        ((EntityLiving)playerHit.entity).damage(damage, "Player");
                    }
                    if (Input.GetMouseButtonDown(1))
                    {
                        // Player is right clicking on an entity
                        playerHit.entity.onEntityInteract(this);
                    }
                }
            }
            else
            {
                // We are clicking on the air
                if (Input.GetMouseButtonDown(1) && heldStack != null)
                {
                    this.containerHotbar.setHeldItem(heldStack.item.onRightClick(this.world, this, heldStack, playerHit));
                }
            }

            // Keycodes for each of the number keys across the keyboard
            for (int i = 0; i < 9; i++)
            {
                if (Input.GetKeyDown((KeyCode)(i + 49)))
                {
                    if (isShiftDown)
                    {
                        if (this.containerHotbar.getIndex() != i)
                        {
                            ItemStack tempIndex = this.containerHotbar.getHeldItem();
                            this.containerHotbar.setHeldItem(this.dataHotbar.getStack(i, 0));
                            this.dataHotbar.setStack(this.containerHotbar.getIndex(), 0, tempIndex);

                            this.containerHotbar.updateHudItemName();
                        }
                    }
                    else
                    {
                        this.containerHotbar.setSelected(i, true);
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.Q))
            {
                ItemStack toDrop = null;
                ItemStack stack  = this.containerHotbar.getHeldItem();
                if (stack != null)
                {
                    int count = (isShiftDown ? stack.count : 1);
                    toDrop = new ItemStack(stack.item, stack.meta, count);
                    this.containerHotbar.setHeldItem(stack.safeDeduction(count));
                }
                if (toDrop != null)
                {
                    this.dropItem(toDrop);
                }
            }

            float f = Input.GetAxis("Mouse ScrollWheel");

            if (f != 0)
            {
                this.containerHotbar.scroll(f > 0 ? -1 : (f < 0 ? 1 : 0));
            }
        }
Ejemplo n.º 5
0
        public override ItemStack onRightClick(World world, EntityPlayer player, ItemStack stack, PlayerRayHit hit)
        {
            if (hit != null && hit.unityRaycastHit.distance <= player.getReach())
            {
                BlockPos pos = BlockPos.fromRaycastHit(hit.unityRaycastHit);

                Direction clickedDirNormal = hit.getClickedBlockFace();
                BlockPos  newPos           = pos.move(clickedDirNormal);
                int       meta             = stack.meta;

                Vector3 angle = new Vector3(player.transform.position.x, 0, player.transform.position.z) - new Vector3(hit.unityRaycastHit.point.x, 0, hit.unityRaycastHit.point.z);
                if (!Physics.CheckBox(newPos.toVector(), new Vector3(0.4f, 0.4f, 0.4f)) && world.getBlock(newPos).isReplaceable&& this.block.isValidPlaceLocation(world, newPos, meta, clickedDirNormal, hit.hitState, angle))
                {
                    world.setBlock(newPos, this.block, this.block.adjustMetaOnPlace(world, newPos, meta, clickedDirNormal, angle));
                    stack = stack.safeDeduction();
                }
            }
            return(stack);
        }
Ejemplo n.º 6
0
 public override ItemStack onRightClick(World world, EntityPlayer player, ItemStack stack, PlayerRayHit hit)
 {
     if (player.health < 100)  // || player.hunger < 99f) {
     {
         player.setHealth(player.health + this.restoredHealth);
         player.setHunger(player.hunger + this.restoredHunger);
         return(stack.safeDeduction());
     }
     return(stack);
 }