Exemplo n.º 1
0
        public override void OnNeighourBlockChange(IWorldAccessor world, BlockPos pos, BlockPos neibpos)
        {
            Block nBlock = neibpos.GetBlock(world);

            if (!nBlock.WildCardMatch(new AssetLocation("stair*")) && !nBlock.WildCardMatch(new AssetLocation("air*")))
            {
                return;
            }

            AssetLocation[] cardinal = GetCardinal(world, pos);

            if (side)
            {
                StairsCheck(world, pos, cardinal);
            }
            else if (corner)
            {
                CornersCheck(world, pos, cardinal);
            }
        }
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
        {
            BlockPos pos   = blockSel.Position;
            Block    block = pos.GetBlock(byEntity.World);

            if (block != null && byEntity.Controls.Sneak && (block.FirstCodePart().Contains("skinned") || block.FirstCodePart().Contains("dead")))
            {
                if (a && byEntity.World.Side.IsServer())
                {
                    a = false;
                    byEntity.World.RegisterGameTickListener(dt => a = true, 4000);

                    AssetLocation location = new AssetLocation("game:sounds/player/scrape");
                    byEntity.World.PlaySoundAt(location, pos.X, pos.Y, pos.Z, byEntity as IPlayer);
                }

                handling = EnumHandHandling.Handled;
                return;
            }
            else
            {
                base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling);
            }
        }
Exemplo n.º 3
0
 public static Block GetBlock(this BlockPos Pos, ICoreAPI Api)
 {
     return(Pos.GetBlock(Api.World));
 }
Exemplo n.º 4
0
 public static Block GetBlock(this BlockPos pos, ICoreAPI api)
 {
     return(pos.GetBlock(api.World));
 }
Exemplo n.º 5
0
        public bool OnPlayerInteract(IPlayer byPlayer, BlockSelection blockSel)
        {
            BlockPos Pos   = blockSel?.Position;
            Block    block = Pos?.GetBlock(byPlayer.Entity.World);
            ItemSlot slot  = byPlayer?.InventoryManager?.ActiveHotbarSlot;

            if (block == null || slot?.Itemstack == null)
            {
                return(false);
            }
            bool shouldbreak = false;

            foreach (var val in InWorldCraftingRecipes)
            {
                foreach (var recipe in val.Value)
                {
                    if (recipe.Disabled || (recipe.Takes.AllowedVariants != null && !block.WildCardMatch(recipe.Takes.AllowedVariants)) || (recipe.Tool.AllowedVariants != null && !slot.Itemstack.Collectible.WildCardMatch(recipe.Tool.AllowedVariants)) ||
                        (recipe.Takes.Attributes != null) && recipe.Takes.Attributes.Token.HasValues && block.Attributes.Token != recipe.Takes.Attributes.Token)
                    {
                        continue;
                    }
                    if (block.WildCardMatch(recipe.Takes.Code))
                    {
                        if (IsValid(byPlayer, recipe, slot))
                        {
                            if (recipe.IsSwap)
                            {
                                var make = recipe.Makes[0].Clone();
                                make.Resolve(byPlayer.Entity.World, null);
                                if (make.IsBlock())
                                {
                                    if (recipe.Remove)
                                    {
                                        byPlayer.Entity.World.BlockAccessor.SetBlock(0, Pos);
                                    }
                                    Block resolvedBlock = make.ResolvedItemstack.Block;
                                    byPlayer.Entity.World.BlockAccessor.SetBlock(resolvedBlock.BlockId, Pos);
                                    resolvedBlock.OnBlockPlaced(byPlayer.Entity.World, Pos);
                                    TakeOrDamage(recipe, slot, byPlayer);
                                    shouldbreak = true;
                                }
                            }
                            else if (recipe.IsCreate)
                            {
                                foreach (var make in recipe.Makes)
                                {
                                    var makeClone = make.Clone();
                                    makeClone.Resolve(byPlayer.Entity.World, null);
                                    byPlayer.Entity.World.SpawnItemEntity(makeClone.ResolvedItemstack, Pos.MidPoint(), new Vec3d(0.0, 0.1, 0.0));
                                }
                                TakeOrDamage(recipe, slot, byPlayer);
                                if (recipe.Remove)
                                {
                                    byPlayer.Entity.World.BlockAccessor.SetBlock(0, Pos);
                                }
                                shouldbreak = true;
                            }
                            if (byPlayer.Entity.World.Side.IsServer())
                            {
                                byPlayer.Entity.World.PlaySoundAt(recipe.CraftSound, Pos);
                            }
                        }
                        else
                        {
                            continue;
                        }

                        slot.MarkDirty();
                        break;
                    }
                }
                if (shouldbreak)
                {
                    return(true);
                }
            }
            return(false);
        }