Beispiel #1
0
        public bool DamagePart(IWorldAccessor world, Entity byEntity, IItemStack itemstack, int amount = 1)
        {
            ITreeAttribute ToolSlots = itemstack.Attributes.GetOrAddTreeAttribute("toolparts");
            IEnumerable <KeyValuePair <string, IAttribute> > validParts = ToolSlots.Where(pair =>
            {
                ItemStack part = (ItemStack)pair.Value.GetValue();

                return(part != null && part.Attributes.GetInt("durability", part.Collectible.GetDurability(part)) > 0);
            });

            // Damage sub parts, if there are any
            if (validParts.Count() > 0)
            {
                var        pair  = validParts.ElementAt(new Random().Next(0, validParts.Count()));
                IItemStack stack = pair.Value.GetValue() as IItemStack;
                ToolPart   part  = stack.Item as ToolPart;

                bool broken = false;

                if (part != null)
                {
                    broken = part.DamagePart(world, byEntity, stack);
                }

                // If the part is broken, then remove it
                if (broken)
                {
                    RemovePart(itemstack, pair.Key);
                }
            }

            // Damamge the tool

            int leftDurability = itemstack.Attributes.GetInt("durability", GetDurability(itemstack));

            leftDurability -= amount;
            itemstack.Attributes.SetInt("durability", leftDurability);

            if (leftDurability <= 0)
            {
                // Bound minimum durability
                leftDurability = 0;

                if (byEntity is EntityPlayer)
                {
                    IPlayer player = world.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
                    world.PlaySoundAt(new AssetLocation("sounds/effect/toolbreak"), player, player);
                }
                else
                {
                    world.PlaySoundAt(new AssetLocation("sounds/effect/toolbreak"), byEntity.Pos.X, byEntity.Pos.Y, byEntity.Pos.Z);
                }
            }

            itemstack.Attributes.SetInt("durability", leftDurability);

            // Notify the containing item if this part has broken
            return(TinkerProps.Breaks && leftDurability == 0);
        }
Beispiel #2
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (slot.Empty)
            {
                return(base.OnBlockInteractStart(world, byPlayer, blockSel));
            }

            if (!Repaired)
            {
                if (slot.Itemstack.Collectible.Code.Path == "metal-parts" && slot.StackSize >= 2)
                {
                    slot.TakeOut(2);
                    world.PlaySoundAt(new AssetLocation("sounds/effect/latch"), blockSel.Position.X + 0.5, blockSel.Position.Y, blockSel.Position.Z + 0.5, byPlayer, true, 16);

                    Block block = world.GetBlock(CodeWithVariant("state", "normal"));
                    world.BlockAccessor.SetBlock(block.Id, blockSel.Position);

                    BlockEntityStaticTranslocator be = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityStaticTranslocator;
                    if (be != null)
                    {
                        be.DoRepair();
                    }

                    return(true);
                }
            }
            else
            {
                BlockEntityStaticTranslocator be = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityStaticTranslocator;
                if (be == null)
                {
                    return(false);
                }

                if (!be.FullyRepaired && slot.Itemstack.Collectible is ItemTemporalGear)
                {
                    be.DoRepair();
                    slot.TakeOut(1);
                    world.PlaySoundAt(new AssetLocation("sounds/effect/latch"), blockSel.Position.X + 0.5, blockSel.Position.Y, blockSel.Position.Z + 0.5, byPlayer, true, 16);

                    return(true);
                }

                if (!be.Activated && slot.Itemstack.Collectible.Code.Path == "gear-rusty")
                {
                    be.DoActivate();
                    slot.TakeOut(1);
                    world.PlaySoundAt(new AssetLocation("sounds/effect/latch"), blockSel.Position.X + 0.5, blockSel.Position.Y, blockSel.Position.Z + 0.5, byPlayer, true, 16);
                    return(true);
                }
            }

            return(base.OnBlockInteractStart(world, byPlayer, blockSel));
        }
Beispiel #3
0
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, ref EnumHandling handling)
        {
            if (byPlayer == null)
            {
                return;                    // Fast return path for no player (although normally OnBlockBroken will specify a player)
            }
            ModSystemBlockReinforcement modBre;

            modBre = world.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>();
            BlockReinforcement bre = modBre.GetReinforcment(pos);

            if (bre != null && bre.Strength > 0)
            {
                handling = EnumHandling.PreventDefault;   // This prevents the block from breaking normally, while it any amount of reinforcement left

                world.PlaySoundAt(new AssetLocation("sounds/tool/breakreinforced"), pos.X, pos.Y, pos.Z, byPlayer);

                if (!byPlayer.HasPrivilege("denybreakreinforced"))
                {
                    modBre.ConsumeStrength(pos, 1);

                    world.BlockAccessor.MarkBlockDirty(pos);
                }
            }
        }
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemSlot hotbarSlot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (!hotbarSlot.Empty && hotbarSlot.Itemstack.Collectible.Code.Path == "bowl-burned")
            {
                BlockEntityCookedContainer bec = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityCookedContainer;
                if (bec == null)
                {
                    return(false);
                }

                bec.ServePlayer(byPlayer);
                return(true);
            }


            ItemStack stack = OnPickBlock(world, blockSel.Position);

            if (byPlayer.InventoryManager.TryGiveItemstack(stack, true))
            {
                world.BlockAccessor.SetBlock(0, blockSel.Position);
                world.PlaySoundAt(this.Sounds.Place, byPlayer, byPlayer);
                return(true);
            }


            return(base.OnBlockInteractStart(world, byPlayer, blockSel));
        }
        protected override void Open(IWorldAccessor world, IPlayer byPlayer, BlockPos position)
        {
            float breakChance = Attributes["breakOnTriggerChance"].AsFloat(0);

            if (world.Side == EnumAppSide.Server && world.Rand.NextDouble() < breakChance && byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)
            {
                world.BlockAccessor.BreakBlock(position, byPlayer);
                world.PlaySoundAt(new AssetLocation("sounds/effect/toolbreak"), position.X + 0.5, position.Y + 0.5, position.Z + 0.5, null);

                return;
            }

            AssetLocation newCode  = CodeWithVariant("state", IsOpened() ? "closed" : "opened");
            Block         newBlock = world.BlockAccessor.GetBlock(newCode);

            AssetLocation otherNewCode = newBlock.CodeWithVariant("part", IsUpperHalf() ? "down" : "up");

            world.BlockAccessor.ExchangeBlock(newBlock.BlockId, position);
            world.BlockAccessor.MarkBlockDirty(position);

            BlockPos otherPos  = position.AddCopy(0, IsUpperHalf() ? -1 : 1, 0);
            Block    otherPart = world.BlockAccessor.GetBlock(otherPos);


            if (otherPart is BlockDoor && ((BlockDoor)otherPart).IsUpperHalf() != IsUpperHalf())
            {
                world.BlockAccessor.ExchangeBlock(world.BlockAccessor.GetBlock(otherNewCode).BlockId, otherPos);
                world.BlockAccessor.MarkBlockDirty(otherPos);
            }
        }
        public override void OnBlockInteractStop(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handled)
        {
            handled = EnumHandling.PreventDefault;


            if (secondsUsed > harvestTime - 0.05f && harvestedStack != null && world.Side == EnumAppSide.Server)
            {
                float dropRate = 1;

                if (block.Attributes?.IsTrue("forageStatAffected") == true)
                {
                    dropRate *= byPlayer.Entity.Stats.GetBlended("forageDropRate");
                }

                ItemStack stack = harvestedStack.GetNextItemStack(dropRate);

                if (!byPlayer.InventoryManager.TryGiveItemstack(stack))
                {
                    world.SpawnItemEntity(stack, blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5));
                }

                if (harvestedBlock != null)
                {
                    world.BlockAccessor.SetBlock(harvestedBlock.BlockId, blockSel.Position);
                }

                world.PlaySoundAt(harvestingSound, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
            }
        }
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemSlot          activeHotbarSlot = byPlayer.InventoryManager.ActiveHotbarSlot;
            CollectibleObject collectible      = activeHotbarSlot.Itemstack.Collectible;

            if (!activeHotbarSlot.Empty && collectible.FirstCodePart() == "bowl" && collectible.Variant["type"] == "burned")
            {
                CookedContainerFixBE container = world.BlockAccessor.GetBlockEntity(blockSel.Position) as CookedContainerFixBE;
                if (container == null)
                {
                    return(false);
                }

                container.ServePlayer(byPlayer);
                return(true);
            }
            ItemStack itemstack = OnPickBlock(world, blockSel.Position);

            if (!byPlayer.InventoryManager.TryGiveItemstack(itemstack, true))
            {
                return(base.OnBlockInteractStart(world, byPlayer, blockSel));
            }

            world.BlockAccessor.SetBlock(0, blockSel.Position);
            world.PlaySoundAt(Sounds.Place, byPlayer, byPlayer, true, 32f, 1f);
            return(true);
        }
Beispiel #8
0
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1f)
        {
            if (world.Side == EnumAppSide.Server && (byPlayer == null || byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative))
            {
                foreach (var bdrop in Drops)
                {
                    ItemStack drop = bdrop.GetNextItemStack();
                    if (drop != null)
                    {
                        world.SpawnItemEntity(drop, new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5), null);
                    }
                }

                world.PlaySoundAt(Sounds.GetBreakSound(byPlayer), pos.X, pos.Y, pos.Z, byPlayer);
            }

            if (byPlayer != null && Variant["state"] == "normal" && (byPlayer.InventoryManager.ActiveTool == EnumTool.Knife || byPlayer.InventoryManager.ActiveTool == EnumTool.Sickle || byPlayer.InventoryManager.ActiveTool == EnumTool.Scythe))
            {
                world.BlockAccessor.SetBlock(world.GetBlock(this.habitat == EnumReedsHabitat.Ice ? CodeWithVariants(new string[] { "habitat", "state" }, new string[] { "water", "harvested" })  : CodeWithVariant("state", "harvested")).BlockId, pos);
                return;
            }

            if (habitat != 0)
            {
                world.BlockAccessor.SetBlock(world.GetBlock(new AssetLocation("water-still-7")).BlockId, pos);
                world.BlockAccessor.GetBlock(pos).OnNeighbourBlockChange(world, pos, pos);
            }
            else
            {
                world.BlockAccessor.SetBlock(0, pos);
            }
        }
        public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldAccessForResolve)
        {
            base.FromTreeAttributes(tree, worldAccessForResolve);

            canTeleport   = tree.GetBool("canTele");
            repairState   = tree.GetInt("repairState");
            findNextChunk = tree.GetBool("findNextChunk", true);
            activated     = tree.GetBool("activated");

            if (canTeleport)
            {
                tpLocation = new BlockPos(tree.GetInt("teleX"), tree.GetInt("teleY"), tree.GetInt("teleZ"));

                if (tpLocation.X == 0 && tpLocation.Z == 0)
                {
                    tpLocation = null;                                         // For safety
                }
            }

            if (worldAccessForResolve != null && worldAccessForResolve.Side == EnumAppSide.Client)
            {
                somebodyIsTeleportingReceivedTotalMs = worldAccessForResolve.ElapsedMilliseconds;

                if (tree.GetBool("somebodyDidTeleport"))
                {
                    // Might get called from the SystemNetworkProcess thread
                    worldAccessForResolve.Api.Event.EnqueueMainThreadTask(
                        () => worldAccessForResolve.PlaySoundAt(new AssetLocation("sounds/effect/translocate-breakdimension"), Pos.X + 0.5f, Pos.Y + 0.5f, Pos.Z + 0.5f, null, false, 16),
                        "playtelesound"
                        );
                }
            }
        }
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, ref EnumHandling handling)
        {
            if (world.Side == EnumAppSide.Client)
            {
                handling = EnumHandling.PreventDefault;
                return;
            }

            ModSystemBlockReinforcement bre = world.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>();

            int strength = bre.GetRemainingStrength(pos);

            (byPlayer as IServerPlayer).SendMessage(GlobalConstants.CurrentChatGroup, "Strength left: " + strength, EnumChatType.Notification);


            if (strength > 0)
            {
                handling = EnumHandling.PreventDefault;

                world.PlaySoundAt(new AssetLocation("blockreinforcement", "sounds/breakreinforced"), pos.X, pos.Y, pos.Z, null);

                bre.ConsumeStrength(pos, 1);

                world.BlockAccessor.MarkBlockDirty(pos);
            }
        }
Beispiel #11
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemStack stack = OnPickBlock(world, blockSel.Position);

            if (!byPlayer.Entity.Controls.Sneak)
            {
                if (byPlayer.InventoryManager.TryGiveItemstack(stack, true))
                {
                    world.BlockAccessor.SetBlock(0, blockSel.Position);
                    world.PlaySoundAt(this.Sounds.Place, byPlayer, byPlayer);
                    return(true);
                }
                return(false);
            }



            if (GetContentNutritionProperties(world, stack, byPlayer.Entity) != null)
            {
                world.RegisterCallback((dt) =>
                {
                    if (byPlayer.Entity.Controls.HandUse == EnumHandInteract.BlockInteract)
                    {
                        byPlayer.Entity.PlayEntitySound("eat", byPlayer);
                    }
                }, 500);

                byPlayer.Entity.StartAnimation("eat");

                return(true);
            }

            return(false);
        }
Beispiel #12
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemStack hotbarstack = byPlayer.InventoryManager.ActiveHotbarSlot.Itemstack;

            if (hotbarstack != null && hotbarstack.Class == EnumItemClass.Block && hotbarstack.Collectible.Code.Path.StartsWith("bloomerychimney"))
            {
                Block aboveBlock = world.BlockAccessor.GetBlock(blockSel.Position.UpCopy());
                if (aboveBlock.IsReplacableBy(hotbarstack.Block))
                {
                    hotbarstack.Block.DoPlaceBlock(world, blockSel.Position.UpCopy(), BlockFacing.UP, hotbarstack);
                    world.PlaySoundAt(Sounds?.Place, blockSel.Position.X, blockSel.Position.Y + 1, blockSel.Position.Z, byPlayer, true, 16, 1);

                    byPlayer.InventoryManager.ActiveHotbarSlot.TakeOut(1);
                }



                return(true);
            }

            BlockEntityBloomery beb = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityBloomery;

            if (beb != null)
            {
                if (hotbarstack == null)
                {
                    return(false);
                }
                return(beb.TryAdd(byPlayer.InventoryManager.ActiveHotbarSlot));
            }

            return(base.OnBlockInteractStart(world, byPlayer, blockSel));
        }
Beispiel #13
0
        // Override to drop the barrel empty and drop its contents instead
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1)
        {
            if (world.Side == EnumAppSide.Server && (byPlayer == null || byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative))
            {
                ItemStack[] drops = new ItemStack[] { new ItemStack(this) };

                for (int i = 0; i < drops.Length; i++)
                {
                    world.SpawnItemEntity(drops[i], new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5), null);
                }

                world.PlaySoundAt(Sounds.GetBreakSound(byPlayer), pos.X, pos.Y, pos.Z, byPlayer);
            }

            if (EntityClass != null)
            {
                BlockEntity entity = world.BlockAccessor.GetBlockEntity(pos);
                if (entity != null)
                {
                    entity.OnBlockBroken();
                }
            }

            world.BlockAccessor.SetBlock(0, pos);
        }
Beispiel #14
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            if (!PlacedBlockEating)
            {
                return(base.OnBlockInteractStart(world, byPlayer, blockSel));
            }

            ItemStack stack = OnPickBlock(world, blockSel.Position);

            if (!byPlayer.Entity.Controls.Sneak)
            {
                if (byPlayer.InventoryManager.TryGiveItemstack(stack, true))
                {
                    world.BlockAccessor.SetBlock(0, blockSel.Position);
                    world.PlaySoundAt(Sounds.Place, byPlayer, byPlayer);
                    return(true);
                }
                return(false);
            }

            BlockEntityMeal bemeal    = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityMeal;
            DummySlot       dummySlot = new DummySlot(stack, bemeal.inventory);

            dummySlot.MarkedDirty += () => true;

            return(tryPlacedBeginEatMeal(dummySlot, byPlayer));
        }
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, ref EnumHandling handling)
        {
            ModSystemBlockReinforcement modBre;

            if (byPlayer?.WorldData.CurrentGameMode == EnumGameMode.Creative)
            {
                if (world.Side == EnumAppSide.Server)
                {
                    modBre = world.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>();
                    modBre.ClearReinforcement(pos);
                }
                return;
            }


            modBre = world.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>();
            BlockReinforcement bre = modBre.GetReinforcment(pos);

            if (bre != null && bre.Strength > 0)
            {
                handling = EnumHandling.PreventDefault;

                world.PlaySoundAt(new AssetLocation("sounds/tool/breakreinforced"), pos.X, pos.Y, pos.Z, byPlayer);

                modBre.ConsumeStrength(pos, 1);

                world.BlockAccessor.MarkBlockDirty(pos);
            }
        }
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1f)
        {
            Block prev = GetPrevLayer(world);

            if (prev != null)
            {
                if (world.Side == EnumAppSide.Server && (byPlayer == null || byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative))
                {
                    ItemStack[] drops = GetDrops(world, pos, byPlayer, dropQuantityMultiplier);

                    if (drops != null)
                    {
                        for (int i = 0; i < drops.Length; i++)
                        {
                            world.SpawnItemEntity(drops[i], new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5), null);
                        }
                    }

                    world.PlaySoundAt(Sounds.GetBreakSound(byPlayer), pos.X, pos.Y, pos.Z, byPlayer);
                }

                if (byPlayer == null || byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)
                {
                    world.BlockAccessor.SetBlock(prev.BlockId, pos);
                }
                else
                {
                    world.BlockAccessor.SetBlock(0, pos);
                }

                return;
            }

            base.OnBlockBroken(world, pos, byPlayer);
        }
Beispiel #17
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            string collectibleCode = byPlayer.InventoryManager.ActiveHotbarSlot?.Itemstack?.Collectible.Code.Path;

            if (collectibleCode == "beenade-opened" || collectibleCode == "beenade-closed")
            {
                return(false);
            }



            if (byPlayer.WorldData.CurrentGameMode == EnumGameMode.Creative && byPlayer.InventoryManager.ActiveHotbarSlot.Itemstack?.Collectible.Code.Path.Contains("honeycomb") == true)
            {
                BlockEntityBeehive beh = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityBeehive;
                if (beh != null && !beh.Harvestable)
                {
                    beh.Harvestable = true;
                    beh.MarkDirty(true);
                }
                return(true);
            }

            if (byPlayer.InventoryManager.TryGiveItemstack(new ItemStack(this)))
            {
                world.BlockAccessor.SetBlock(0, blockSel.Position);
                world.PlaySoundAt(new AssetLocation("sounds/block/planks"), blockSel.Position.X + 0.5, blockSel.Position.Y, blockSel.Position.Z + 0.5, byPlayer, false);

                return(true);
            }

            return(false);
        }
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            Block block = GetPottedPlant(world);

            if (block != null)
            {
                return(false);
            }

            IItemStack heldItem = byPlayer.InventoryManager.ActiveHotbarSlot.Itemstack;

            if (heldItem != null && heldItem.Class == EnumItemClass.Block)
            {
                block = GetBlockToPlant(world, heldItem);
                if (block != null && this != block)
                {
                    world.PlaySoundAt(block.Sounds?.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
                    world.BlockAccessor.SetBlock(block.BlockId, blockSel.Position);

                    byPlayer.InventoryManager.ActiveHotbarSlot.TakeOut(1);
                    byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty();

                    return(true);
                }
            }
            return(false);
        }
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling)
        {
            if (!world.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.Use))
            {
                return(false);
            }
            if (!block.Code.Path.Contains("empty"))
            {
                handling = EnumHandling.PreventDefault;

                //handles the collection of items, and the transformation of the block.
                world.Logger.VerboseDebug("Collecting item(s) from target block at {0}.", blockSel.Position);

                if (block.Drops != null && block.Drops.Length > 1)
                {
                    BlockDropItemStack drop  = block.Drops[0];
                    ItemStack          stack = drop.GetNextItemStack();

                    if (!byPlayer.InventoryManager.TryGiveItemstack(stack))
                    {
                        world.SpawnItemEntity(drop.GetNextItemStack(), blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5));
                    }

                    AssetLocation loc = block.Code.CopyWithPath(block.Code.Path.Replace(block.Code.Path.Split('-').Last(), "empty"));

                    world.BlockAccessor.SetBlock(world.GetBlock(loc).BlockId, blockSel.Position);

                    world.PlaySoundAt(new AssetLocation("sounds/player/collect"), blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
                }

                return(true);
            }

            return(false);
        }
 public override void OnEntityCollide(IWorldAccessor world, Entity entity, BlockPos pos, BlockFacing facing, Vec3d collideSpeed, bool isImpact)
 {
     if (isImpact && facing.Axis == EnumAxis.Y)
     {
         world.PlaySoundAt(tickSound, entity.Pos.X, entity.Pos.Y, entity.Pos.Z);
         entity.Pos.Motion.Y *= -0.8;
     }
 }
Beispiel #21
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            BlockPos pos = blockSel.Position;

            if (Variant["state"] == "closed")
            {
                world.BlockAccessor.SetBlock(world.GetBlock(CodeWithVariant("state", "opened")).Id, pos);
                world.PlaySoundAt(new AssetLocation("sounds/block/cokeovendoor-open"), pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5, byPlayer, true);
            }
            else
            {
                world.BlockAccessor.SetBlock(world.GetBlock(CodeWithVariant("state", "closed")).Id, pos);
                world.PlaySoundAt(new AssetLocation("sounds/block/cokeovendoor-close"), pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5, byPlayer, true);
            }

            return(true);
        }
        protected bool TryCollectLowest(IPlayer byPlayer, IWorldAccessor world, BlockPos pos)
        {
            Block ladderBlock = world.BlockAccessor.GetBlock(pos);

            if (ladderBlock.FirstCodePart() != ownFirstCodePart)
            {
                return(false);
            }

            BlockPos belowPos = pos.DownCopy();
            Block    belowBlock;

            while (belowPos.Y > 0)
            {
                belowBlock = world.BlockAccessor.GetBlock(belowPos);
                if (belowBlock.FirstCodePart() != ownFirstCodePart)
                {
                    break;
                }

                belowPos.Down();
            }

            belowPos.Up();
            Block collectBlock = world.BlockAccessor.GetBlock(belowPos);

            var bh = collectBlock.GetBehavior <BlockBehaviorLadder>();

            if (bh == null || !bh.isFlexible)
            {
                return(false);
            }

            if (!world.Claims.TryAccess(byPlayer, belowPos, EnumBlockAccessFlags.BuildOrBreak))
            {
                return(false);
            }

            ItemStack[] stacks = collectBlock.GetDrops(world, pos, byPlayer);

            world.BlockAccessor.SetBlock(0, belowPos);
            world.PlaySoundAt(collectBlock.Sounds.Break, pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5, byPlayer);

            if (stacks.Length > 0)
            {
                if (!byPlayer.InventoryManager.TryGiveItemstack(stacks[0], true))
                {
                    world.SpawnItemEntity(stacks[0], byPlayer.Entity.Pos.XYZ);
                }
            }


            return(true);
        }
Beispiel #23
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;
            }

            IWorldAccessor world        = byEntity.World;
            Block          firepitBlock = world.GetBlock(new AssetLocation("firepit-construct1"));

            if (firepitBlock == null)
            {
                return;
            }


            BlockPos onPos = blockSel.DidOffset ? blockSel.Position : blockSel.Position.AddCopy(blockSel.Face);

            IPlayer byPlayer = byEntity.World.PlayerByUid((byEntity as EntityPlayer)?.PlayerUID);

            if (!byEntity.World.Claims.TryAccess(byPlayer, onPos, EnumBlockAccessFlags.BuildOrBreak))
            {
                return;
            }



            Block block   = world.BlockAccessor.GetBlock(onPos.DownCopy());
            Block atBlock = world.BlockAccessor.GetBlock(onPos);

            string useless = "";

            if (!block.CanAttachBlockAt(byEntity.World.BlockAccessor, firepitBlock, onPos.DownCopy(), BlockFacing.UP))
            {
                return;
            }
            if (!firepitBlock.CanPlaceBlock(world, byPlayer, new BlockSelection()
            {
                Position = onPos, Face = BlockFacing.UP
            }, ref useless))
            {
                return;
            }

            world.BlockAccessor.SetBlock(firepitBlock.BlockId, onPos);

            if (firepitBlock.Sounds != null)
            {
                world.PlaySoundAt(firepitBlock.Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
            }

            itemslot.Itemstack.StackSize--;
            handHandling = EnumHandHandling.PreventDefaultAction;
        }
Beispiel #24
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            BlockPos pos = blockSel.Position;

            Open(world, byPlayer, pos);

            world.PlaySoundAt(new AssetLocation("sounds/block/door"), pos.X + 0.5f, pos.Y + 0.5f, pos.Z + 0.5f, byPlayer);

            TryOpenConnectedDoor(world, byPlayer, pos);
            return(true);
        }
Beispiel #25
0
        public override void OnBlockInteractStop(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemSlot activeslot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (activeslot.Itemstack.Item.Tool == EnumTool.Hammer && world.Side == EnumAppSide.Server)
            {
                world.PlaySoundAt(Sounds.Place, byPlayer);
                Swap(world, byPlayer, blockSel);
                world.SpawnCubeParticles(blockSel.Position, blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5), 2, 32);
            }
        }
Beispiel #26
0
 public override void OnEntityCollide(IWorldAccessor world, Entity entity, BlockPos pos, BlockFacing facing, Vec3d collideSpeed, bool isImpact)
 {
     if (isImpact && facing.Axis == EnumAxis.Y)
     {
         if (Sounds?.Break != null && System.Math.Abs(collideSpeed.Y) > 0.2)
         {
             world.PlaySoundAt(Sounds.Break, entity.Pos.X, entity.Pos.Y, entity.Pos.Z);
         }
         entity.Pos.Motion.Y = GameMath.Clamp(-entity.Pos.Motion.Y * 0.8, -0.5, 0.5);
     }
 }
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemStack stack = OnPickBlock(world, blockSel.Position);

            if (byPlayer.InventoryManager.TryGiveItemstack(stack, true))
            {
                world.BlockAccessor.SetBlock(0, blockSel.Position);
                world.PlaySoundAt(this.Sounds.Place, byPlayer, byPlayer);
                return(true);
            }
            return(false);
        }
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            if (Empty)
            {
                ItemStack heldStack = byPlayer.InventoryManager.ActiveHotbarSlot.Itemstack;
                if (heldStack != null && heldStack.Collectible.Code.Path.Equals("torch-basic-lit-up"))
                {
                    byPlayer.InventoryManager.ActiveHotbarSlot.TakeOut(1);
                    byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty();

                    Block filledBlock = world.GetBlock(CodeWithVariant("state", "filled"));
                    world.BlockAccessor.SetBlock(filledBlock.BlockId, blockSel.Position);

                    if (Sounds?.Place != null)
                    {
                        world.PlaySoundAt(Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
                    }

                    return(true);
                }
            }
            else
            {
                ItemStack stack = new ItemStack(world.GetBlock(new AssetLocation("torch-basic-lit-up")));
                if (byPlayer.InventoryManager.TryGiveItemstack(stack, true))
                {
                    Block filledBlock = world.GetBlock(CodeWithVariant("state", "empty"));
                    world.BlockAccessor.SetBlock(filledBlock.BlockId, blockSel.Position);

                    if (Sounds?.Place != null)
                    {
                        world.PlaySoundAt(Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
                    }

                    return(true);
                }
            }

            return(base.OnBlockInteractStart(world, byPlayer, blockSel));
        }
        public bool TryConstruct(IWorldAccessor world, BlockPos pos, CollectibleObject obj, IPlayer player)
        {
            int stage = Stage;

            if (obj.Attributes?.IsTrue("firepitConstructable") != true)
            {
                return(false);
            }

            if (stage == 5)
            {
                return(false);
            }

            if (stage == 4 && world.BlockAccessor.GetBlock(pos.DownCopy()).Code.Path.Equals("firewoodpile"))
            {
                Block charcoalPitBlock = world.GetBlock(new AssetLocation("charcoalpit"));
                if (charcoalPitBlock != null)
                {
                    world.BlockAccessor.SetBlock(charcoalPitBlock.BlockId, pos);

                    BlockEntityCharcoalPit be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCharcoalPit;
                    be?.Init(player);

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

                    return(true);
                }
            }

            Block block = world.GetBlock(CodeWithParts(NextStageCodePart));

            world.BlockAccessor.ExchangeBlock(block.BlockId, pos);
            world.BlockAccessor.MarkBlockDirty(pos);
            if (block.Sounds != null)
            {
                world.PlaySoundAt(block.Sounds.Place, pos.X, pos.Y, pos.Z, player);
            }

            if (stage == 4)
            {
                BlockEntity be = world.BlockAccessor.GetBlockEntity(pos);
                if (be is BlockEntityFirepit)
                {
                    ((BlockEntityFirepit)be).inventory[0].Itemstack = new ItemStack(obj, 4);
                }
            }

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

            return(true);
        }
        private void ReplaceLiquidBlock(Block liquidBlock, BlockPos pos, IWorldAccessor world)
        {
            Block replacementBlock = GetReplacementBlock(liquidBlock, world);

            if (replacementBlock != null)
            {
                world.BulkBlockAccessor.SetBlock(replacementBlock.BlockId, pos);
                NotifyNeighborsOfBlockChange(pos, world);
                GenerateSteamParticles(pos, world);
                world.PlaySoundAt(collisionReplaceSound, pos.X, pos.Y, pos.Z);
                world.RegisterCallbackUnique(OnDelayedWaterUpdateCheck, pos.UpCopy(), spreadDelay);
            }
        }