Exemplo n.º 1
0
        public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor world, BlockSelection selection, IPlayer forPlayer)
        {
            return(new WorldInteraction[]
            {
                new WorldInteraction()
                {
                    ActionLangCode = "blockhelp-ingotpile-add",
                    MouseButton = EnumMouseButton.Right,
                    HotKeyCode = "sneak",
                    Itemstacks = new ItemStack[] { new ItemStack(this) },
                    GetMatchingStacks = (wi, bs, es) =>
                    {
                        IngotPileOverride pile = world.BlockAccessor.GetBlockEntity(bs.Position) as IngotPileOverride;
                        if (pile != null && pile.MaxStackSize > pile.inventory[0].StackSize && pile.inventory[0].Itemstack != null)
                        {
                            ItemStack displaystack = pile.inventory[0].Itemstack.Clone();
                            displaystack.StackSize = pile.DefaultTakeQuantity;
                            return new  ItemStack[] { displaystack };
                        }
                        return null;
                    }
                },
                new WorldInteraction()
                {
                    ActionLangCode = "blockhelp-ingotpile-remove",
                    MouseButton = EnumMouseButton.Right
                },


                new WorldInteraction()
                {
                    ActionLangCode = "blockhelp-ingotpile-4add",
                    MouseButton = EnumMouseButton.Right,
                    HotKeyCodes = new string[] { "sprint", "sneak" },
                    Itemstacks = new ItemStack[] { new ItemStack(this) },
                    GetMatchingStacks = (wi, bs, es) =>
                    {
                        IngotPileOverride pile = world.BlockAccessor.GetBlockEntity(bs.Position) as IngotPileOverride;
                        if (pile != null && pile.MaxStackSize > pile.inventory[0].StackSize && pile.inventory[0].Itemstack != null)
                        {
                            ItemStack displaystack = pile.inventory[0].Itemstack.Clone();
                            displaystack.StackSize = pile.BulkTakeQuantity;
                            return new  ItemStack[] { displaystack };
                        }
                        return null;
                    }
                },
                new WorldInteraction()
                {
                    ActionLangCode = "blockhelp-ingotpile-4remove",
                    HotKeyCode = "sprint",
                    MouseButton = EnumMouseButton.Right
                }
            }.Append(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer)));
        }
Exemplo n.º 2
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            BlockEntity be = world.BlockAccessor.GetBlockEntity(blockSel.Position);

            if (be is IngotPileOverride)
            {
                IngotPileOverride pile = (IngotPileOverride)be;
                return(pile.OnPlayerInteract(byPlayer));
            }

            return(false);
        }
Exemplo n.º 3
0
        internal bool Construct(ItemSlot slot, IWorldAccessor world, BlockPos pos, IPlayer player)
        {
            Block belowBlock = world.BlockAccessor.GetBlock(pos.DownCopy());

            if (!belowBlock.SideSolid[BlockFacing.UP.Index] && (belowBlock != this || FillLevel(world.BlockAccessor, pos.DownCopy()) != 8))
            {
                return(false);
            }


            world.BlockAccessor.SetBlock(BlockId, pos);

            BlockEntity be = world.BlockAccessor.GetBlockEntity(pos);

            if (be is IngotPileOverride)
            {
                IngotPileOverride pile = (IngotPileOverride)be;
                if (player.WorldData.CurrentGameMode == EnumGameMode.Creative)
                {
                    pile.inventory[0].Itemstack           = slot.Itemstack.Clone();
                    pile.inventory[0].Itemstack.StackSize = 1;
                }
                else
                {
                    pile.inventory[0].Itemstack = slot.TakeOut(player.Entity.Controls.Sprint ? pile.BulkTakeQuantity : pile.DefaultTakeQuantity);
                }

                pile.MarkDirty();
                world.BlockAccessor.MarkBlockDirty(pos);
                world.PlaySoundAt(new AssetLocation("sounds/block/ingot"), pos.X, pos.Y, pos.Z, player, false);
            }


            if (CollisionTester.AabbIntersect(
                    GetCollisionBoxes(world.BlockAccessor, pos)[0],
                    pos.X, pos.Y, pos.Z,
                    player.Entity.CollisionBox,
                    player.Entity.LocalPos.XYZ
                    ))
            {
                player.Entity.LocalPos.Y += GetCollisionBoxes(world.BlockAccessor, pos)[0].Y2;
            }

            (player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);

            return(true);
        }
Exemplo n.º 4
0
        public override int GetRandomColor(ICoreClientAPI capi, BlockPos pos, BlockFacing facing)
        {
            IngotPileOverride be = capi.World.BlockAccessor.GetBlockEntity(pos) as IngotPileOverride;

            if (be == null)
            {
                return(base.GetRandomColor(capi, pos, facing));
            }
            string metalType = be.MetalType;

            if (metalType == null)
            {
                return(base.GetRandomColor(capi, pos, facing));
            }

            return(capi.BlockTextureAtlas.GetRandomColor(Textures[be.MetalType].Baked.TextureSubId));
        }
Exemplo n.º 5
0
        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
        {
            BlockEntity be = world.BlockAccessor.GetBlockEntity(pos);

            if (be is IngotPileOverride)
            {
                IngotPileOverride pile  = (IngotPileOverride)be;
                ItemStack         stack = pile.inventory[0].Itemstack;
                if (stack != null)
                {
                    ItemStack pickstack = stack.Clone();
                    pickstack.StackSize = 1;
                    return(pickstack);
                }
            }

            return(new ItemStack(this));
        }
Exemplo n.º 6
0
        public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak)
            {
                return;
            }

            IPlayer byPlayer = null;

            if (byEntity is EntityPlayer)
            {
                byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
            }
            if (byPlayer == null)
            {
                return;
            }

            if (!byEntity.World.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak))
            {
                itemslot.MarkDirty();
                return;
            }

            BlockIngotPileOverride block = byEntity.World.GetBlock(new AssetLocation("ingotpile")) as BlockIngotPileOverride;

            if (block == null)
            {
                return;
            }

            BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position);

            if (be is IngotPileOverride)
            {
                IngotPileOverride pile = (IngotPileOverride)be;
                if (pile.OnPlayerInteract(byPlayer))
                {
                    handHandling = EnumHandHandling.PreventDefault;
                }
                return;
            }

            if (be is BlockEntityAnvil)
            {
                return;
            }

            BlockPos pos = blockSel.Position.AddCopy(blockSel.Face);

            if (byEntity.World.BlockAccessor.GetBlock(pos).Replaceable < 6000)
            {
                return;
            }

            be = byEntity.World.BlockAccessor.GetBlockEntity(pos);
            if (be is IngotPileOverride)
            {
                IngotPileOverride pile = (IngotPileOverride)be;
                if (pile.OnPlayerInteract(byPlayer))
                {
                    handHandling = EnumHandHandling.PreventDefault;
                }
                return;
            }


            if (block.Construct(itemslot, byEntity.World, blockSel.Position.AddCopy(blockSel.Face), byPlayer))
            {
                handHandling = EnumHandHandling.PreventDefault;
            }
        }