Exemple #1
0
        public void BrokenOff(CollectibleObject broken, float diameter)
        {
            --collectedObjects;
            this.diameter = diameter;

            EventManager.ObjectivesUpdated(this);
        }
        internal bool OnInteract(IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (slot.Empty)
            {
                if (TryTake(byPlayer, blockSel))
                {
                    return(true);
                }
                return(false);
            }
            else
            {
                CollectibleObject colObj = slot.Itemstack.Collectible;
                if (colObj.Attributes != null && colObj.Attributes["displaycaseable"].AsBool(false) == true)
                {
                    AssetLocation sound = slot.Itemstack?.Block?.Sounds?.Place;

                    if (TryPut(slot, blockSel))
                    {
                        Api.World.PlaySoundAt(sound != null ? sound : new AssetLocation("sounds/player/build"), byPlayer.Entity, byPlayer, true, 16);
                        return(true);
                    }

                    return(false);
                }
            }


            return(false);
        }
Exemple #3
0
        void TryStart()
        {
            BlockPos    bp         = Pos.Copy().Offset(rmInputFace);
            BlockEntity checkblock = Api.World.BlockAccessor.GetBlockEntity(bp);

            deviceState = enDeviceState.MATERIALHOLD;
            if (Api.World is IServerWorldAccessor)
            {
                workingitem = null;
                var inputContainer = checkblock as BlockEntityContainer;
                if (inputContainer == null)
                {
                    return;
                }
                if (inputContainer.Inventory.Empty)
                {
                    return;
                }
                for (int c = 0; c < inputContainer.Inventory.Count; c++)
                {
                    ItemSlot checkslot = inputContainer.Inventory[c];
                    if (checkslot == null)
                    {
                        continue;
                    }
                    if (checkslot.StackSize == 0)
                    {
                        continue;
                    }

                    Item  checkitem   = checkslot.Itemstack.Item;
                    Block checkiblock = checkslot.Itemstack.Block;

                    if (checkitem == null && checkiblock == null)
                    {
                        continue;
                    }
                    CollectibleObject co;
                    if (checkitem != null)
                    {
                        co = checkitem as CollectibleObject;
                    }
                    else
                    {
                        co = checkiblock as CollectibleObject;
                    }

                    if (!MacerationRecipe.CanMacerate(co, Api, MachineName))
                    {
                        continue;
                    }
                    workingitem = co;
                    //Item has been set, need to pull one item from the stack
                    deviceState = enDeviceState.RUNNING;
                    checkslot.TakeOut(1);
                    checkslot.MarkDirty();
                    break;
                }
            }
        }
Exemple #4
0
 public override bool CanHold(ItemSlot itemstackFromSourceSlot)
 {
     return
         (base.CanHold(itemstackFromSourceSlot) &&
          (!CollectibleObject.IsBackPack(itemstackFromSourceSlot.Itemstack) || CollectibleObject.IsEmptyBackPack(itemstackFromSourceSlot.Itemstack))
         );
 }
        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);
        }
Exemple #6
0
        internal bool OnInteract(IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (slot.Empty)
            {
                if (TryTake(byPlayer, blockSel))
                {
                    return(true);
                }
                return(false);
            }
            else
            {
                CollectibleObject colObj = slot.Itemstack.Collectible;

                if (!colObj.FirstCodePart().Contains("book"))
                {
                    return(false);
                }

                if (TryPut(slot, blockSel))
                {
                    Api.World.PlaySoundAt(new AssetLocation("game:sounds/player/build"), byPlayer.Entity, byPlayer, true, 16);
                    updateMeshes();
                    return(true);
                }
            }


            return(false);
        }
Exemple #7
0
        public bool TryAdd(IPlayer byPlayer, int quantity = 1)
        {
            ItemSlot sourceSlot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (IsBurning)
            {
                return(false);
            }
            if (OutSlot.StackSize > 0)
            {
                return(false);
            }
            if (sourceSlot.Itemstack == null)
            {
                return(false);
            }

            CollectibleObject collectible = sourceSlot.Itemstack.Collectible;

            if (collectible.CombustibleProps?.SmeltedStack != null && collectible.CombustibleProps.MeltingPoint < 1500 && collectible.CombustibleProps.MeltingPoint >= 1000)
            {
                int prevsize = sourceSlot.StackSize;
                if (OreSlot.StackSize >= OreCapacity)
                {
                    return(false);
                }

                int moveableq = Math.Min(OreCapacity - OreSlot.StackSize, quantity);

                sourceSlot.TryPutInto(Api.World, OreSlot, moveableq);
                MarkDirty();

                Api.World.PlaySoundAt(OreSoundLocation, Pos.X, Pos.Y, Pos.Z, byPlayer);

                return(prevsize != sourceSlot.StackSize);
            }

            if (collectible.CombustibleProps?.BurnTemperature >= 1200 && collectible.CombustibleProps.BurnDuration > 30 && (float)FuelSlot.StackSize / OreSlot.StackSize < Coal2OreRatio)
            {
                int maxRequired  = (int)Math.Ceiling(OreSlot.StackSize * Coal2OreRatio);
                int qcoalMissing = maxRequired - FuelSlot.StackSize;

                int prevsize = sourceSlot.StackSize;
                if (FuelSlot.StackSize + quantity > 20)
                {
                    return(false);
                }

                int moveableq = Math.Min(qcoalMissing, Math.Min(20 - FuelSlot.StackSize, quantity));

                sourceSlot.TryPutInto(Api.World, FuelSlot, moveableq);
                MarkDirty();

                Api.World.PlaySoundAt(FuelSoundLocation, Pos.X, Pos.Y, Pos.Z, byPlayer);

                return(prevsize != sourceSlot.StackSize);
            }

            return(true);
        }
Exemple #8
0
        internal void Interact(IPlayer byPlayer)
        {
            ItemSlot          slot = byPlayer.InventoryManager.ActiveHotbarSlot;
            CollectibleObject obj  = slot.Itemstack.Collectible;

            if (obj.FirstCodePart() == "glass" && obj.Variant.ContainsKey("color"))
            {
                if (glass != "quartz" && byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)
                {
                    ItemStack stack = new ItemStack(api.World.GetBlock(new AssetLocation("glass-" + glass)));
                    if (!byPlayer.InventoryManager.TryGiveItemstack(stack, true))
                    {
                        api.World.SpawnItemEntity(stack, pos.ToVec3d().Add(0.5, 0, 0.5));
                    }
                }

                this.glass = obj.Variant["color"];
                if (byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative && glass != "quartz")
                {
                    slot.TakeOut(1);
                }

                if (api.Side == EnumAppSide.Client)
                {
                    (byPlayer as IClientPlayer).TriggerFpAnimation(EnumHandInteract.HeldItemInteract);
                }
                Vec3d soundpos = pos.ToVec3d().Add(0.5, 0, 0.5);
                api.World.PlaySoundAt(api.World.GetBlock(new AssetLocation("glass-" + glass)).Sounds.Place, soundpos.X, soundpos.Y, soundpos.Z, byPlayer);

                setLightColor(glass);

                MarkDirty(true);
            }
        }
 private void OpenBookHelper(CollectibleObject openToThisPage)
 {
     if (!gameObject.activeSelf)
     {
         if (openToThisPage != null)
         {
             int index = 0;
             while (index < collectibleObjects.Length)
             {
                 if (collectibleObjects [index] == openToThisPage)
                 {
                     TurnToSpread(index / 2);
                     index = collectibleObjects.Length;
                 }
                 index++;
             }
         }
         else
         {
             TurnToSpread(currentSpread);
         }
         clickBlocker.SetActive(true);
         gameObject.SetActive(true);
     }
 }
Exemple #10
0
 /// <summary>
 /// Fill out this page with data on an item.
 /// </summary>
 public void Fill(CollectibleObject collectibleObject)
 {
     if (collectibleObject.title.Length == 0)            // blank page
     {
         titleField.text  = collectibleObject.title;
         textField.text   = collectibleObject.text;
         iconField.sprite = collectibleObject.icon;
         m_voiceOver      = null;
         speakerButton.gameObject.SetActive(false);
     }
     else if (collectibleObject.discovered)
     {
         titleField.text  = collectibleObject.title;
         textField.text   = collectibleObject.text;
         iconField.sprite = collectibleObject.icon;
         m_voiceOver      = collectibleObject.voiceOver;
         speakerButton.gameObject.SetActive(true);
     }
     else
     {
         titleField.text  = "???";
         textField.text   = "";
         iconField.sprite = collectibleObject.iconBlurred;
         m_voiceOver      = null;
         speakerButton.gameObject.SetActive(false);
     }
 }
Exemple #11
0
        public static bool CanMacerate(CollectibleObject co, ICoreAPI api, string machinename)
        {
            //TODO: change this to "CanMacerate", add a FindMacerate that returns items:
            //   - from the maceratelist directly - adding extra output based on RNG
            //   - generically where possible - eg stone block to stone gravel etc
            if (maceratelist == null)
            {
                LoadMacerateLists(api);
            }
            if (co == null)
            {
                return(false);
            }
            if (co.FirstCodePart() == "ore")
            {
                return(true);
            }
            if (co.FirstCodePart() == "nugget")
            {
                return(false);
            }                                                     //disabling nugget processing for now
            if (maceratelist.ContainsKey(co.FirstCodePart()))
            {
                bool result = maceratelist[co.FirstCodePart()].Any(val => val.machinename == machinename);
                return(result);
            }
            if (maceratelist.ContainsKey(co.Code.ToString()))
            {
                bool result = maceratelist[co.Code.ToString()].Any(val => val.machinename == machinename);
                return(result);
            }

            return(false);
        }
Exemple #12
0
        internal bool Interact(IPlayer byPlayer)
        {
            ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (slot.Empty)
            {
                return(false);
            }

            bool result           = false;
            CollectibleObject obj = slot.Itemstack.Collectible;

            if (obj.FirstCodePart() == "glass" && obj.Variant.ContainsKey("color"))
            {
                if (glass != "quartz" && byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)
                {
                    ItemStack stack = new ItemStack(Api.World.GetBlock(new AssetLocation("glass-" + glass)));
                    if (!byPlayer.InventoryManager.TryGiveItemstack(stack, true))
                    {
                        Api.World.SpawnItemEntity(stack, Pos.ToVec3d().Add(0.5, 0, 0.5));
                    }
                }

                this.glass = obj.Variant["color"];
                if (byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative && glass != "quartz")
                {
                    slot.TakeOut(1);
                }

                if (Api.Side == EnumAppSide.Client)
                {
                    (byPlayer as IClientPlayer).TriggerFpAnimation(EnumHandInteract.HeldItemInteract);
                }
                Vec3d soundpos = Pos.ToVec3d().Add(0.5, 0, 0.5);
                Api.World.PlaySoundAt(Api.World.GetBlock(new AssetLocation("glass-" + glass)).Sounds.Place, soundpos.X, soundpos.Y, soundpos.Z, byPlayer);

                setLightColor(origlightHsv, lightHsv, glass);

                MarkDirty(true);
                result = true;
            }

            if (lining == null || lining == "plain" && obj is ItemMetalPlate && (obj.Variant["metal"] == "gold" || obj.Variant["metal"] == "silver"))
            {
                lining = obj.Variant["metal"];
                if (Api.Side == EnumAppSide.Client)
                {
                    (byPlayer as IClientPlayer).TriggerFpAnimation(EnumHandInteract.HeldItemInteract);
                }
                Vec3d soundpos = Pos.ToVec3d().Add(0.5, 0, 0.5);
                Api.World.PlaySoundAt(new AssetLocation("sounds/block/plate"), soundpos.X, soundpos.Y, soundpos.Z, byPlayer);

                slot.TakeOut(1);
                MarkDirty(true);
                result = true;
            }

            return(result);
        }
Exemple #13
0
 public static int GetAttributeInt(CollectibleObject block, string attrname, int def = 0)
 {
     if (block != null && block.Attributes != null && block.Attributes[attrname] != null)
     {
         return(block.Attributes[attrname].AsInt(def));
     }
     return(def);
 }
 public override bool CanHold(ItemSlot sourceSlot)
 {
     return
         (base.CanHold(sourceSlot) &&
          (!CollectibleObject.IsBackPack(sourceSlot.Itemstack) || CollectibleObject.IsEmptyBackPack(sourceSlot.Itemstack)) &&
          inventory.CanContain(this, sourceSlot)
         );
 }
 public override bool CanTakeFrom(ItemSlot sourceSlot, EnumMergePriority priority = EnumMergePriority.AutoMerge)
 {
     if (CollectibleObject.IsBackPack(sourceSlot.Itemstack) && !CollectibleObject.IsEmptyBackPack(sourceSlot.Itemstack))
     {
         return(false);
     }
     return(base.CanTakeFrom(sourceSlot, priority));
 }
Exemple #16
0
        public static FoodNutritionProperties[] GetContentNutritionProperties(IWorldAccessor world, ItemSlot inSlot, ItemStack[] contentStacks, EntityAgent forEntity, bool mulWithStacksize = false, float nutritionMul = 1, float healthMul = 1)
        {
            List <FoodNutritionProperties> foodProps = new List <FoodNutritionProperties>();

            if (contentStacks == null)
            {
                return(foodProps.ToArray());
            }

            for (int i = 0; i < contentStacks.Length; i++)
            {
                if (contentStacks[i] == null)
                {
                    continue;
                }

                CollectibleObject       obj = contentStacks[i].Collectible;
                FoodNutritionProperties stackProps;

                if (obj.CombustibleProps != null && obj.CombustibleProps.SmeltedStack != null)
                {
                    stackProps = obj.CombustibleProps.SmeltedStack.ResolvedItemstack.Collectible.GetNutritionProperties(world, obj.CombustibleProps.SmeltedStack.ResolvedItemstack, forEntity);
                }
                else
                {
                    stackProps = obj.GetNutritionProperties(world, contentStacks[i], forEntity);
                }

                if (obj.Attributes?["nutritionPropsWhenInMeal"].Exists == true)
                {
                    stackProps = obj.Attributes?["nutritionPropsWhenInMeal"].AsObject <FoodNutritionProperties>();
                }

                if (stackProps == null)
                {
                    continue;
                }

                float mul = mulWithStacksize ? contentStacks[i].StackSize : 1;

                FoodNutritionProperties props = stackProps.Clone();

                DummySlot       slot       = new DummySlot(contentStacks[i], inSlot.Inventory);
                TransitionState state      = contentStacks[i].Collectible.UpdateAndGetTransitionState(world, slot, EnumTransitionType.Perish);
                float           spoilState = state != null ? state.TransitionLevel : 0;

                float satLossMul = GlobalConstants.FoodSpoilageSatLossMul(spoilState, slot.Itemstack, forEntity);
                float healthLoss = GlobalConstants.FoodSpoilageHealthLossMul(spoilState, slot.Itemstack, forEntity);
                props.Satiety *= satLossMul * nutritionMul * mul;
                props.Health  *= healthLoss * healthMul * mul;

                foodProps.Add(props);
            }

            return(foodProps.ToArray());
        }
 /// <summary>
 /// Return all collectible objects.
 /// </summary>
 public CollectibleObject [] GetAllCollectibleObjects(int numberDiscovered)
 {
     CollectibleObject [] tempCollectibles = new CollectibleObject [allCollectibleObjects.Length];
     for (int x = 0; x < tempCollectibles.Length; x++)
     {
         tempCollectibles [x]            = new CollectibleObject(allCollectibleObjects [x]);
         tempCollectibles [x].discovered = x < numberDiscovered;
     }
     return(tempCollectibles);
 }
        void loadToolMeshes()
        {
            BlockFacing facing = getFacing().GetCW();

            if (facing == null)
            {
                return;
            }

            Vec3f facingNormal = facing.Normalf;

            Vec3f origin = new Vec3f(0.5f, 0.5f, 0.5f);

            ICoreClientAPI clientApi = (ICoreClientAPI)api;

            for (int i = 0; i < 4; i++)
            {
                toolMeshes[i] = null;
                IItemStack stack = inventory[i].Itemstack;
                if (stack == null)
                {
                    continue;
                }

                tmpItem = stack.Collectible;

                if (stack.Class == EnumItemClass.Item)
                {
                    clientApi.Tesselator.TesselateItem(stack.Item, out toolMeshes[i], this);
                }
                else
                {
                    clientApi.Tesselator.TesselateBlock(stack.Block, out toolMeshes[i]);
                }

                if (stack.Class == EnumItemClass.Item && stack.Item.Shape?.VoxelizeTexture == true)
                {
                    toolMeshes[i].Scale(origin, 0.33f, 0.33f, 0.33f);
                    toolMeshes[i].Translate(((i % 2) == 0) ? 0.23f : -0.3f, (i > 1) ? 0.2f : -0.3f, 0.429f * ((facing.Axis == EnumAxis.X) ? -1 : 1));
                    toolMeshes[i].Rotate(origin, 0, facing.HorizontalAngleIndex * 90 * GameMath.DEG2RAD, 0);
                    toolMeshes[i].Rotate(origin, 180 * GameMath.DEG2RAD, 0, 0);
                }
                else
                {
                    toolMeshes[i].Scale(origin, 0.6f, 0.6f, 0.6f);
                    float x = ((i > 1) ? -0.2f : 0.3f);
                    float z = ((i % 2 == 0) ? 0.23f : -0.2f) * (facing.Axis == EnumAxis.X ? 1 : -1);

                    toolMeshes[i].Translate(x, 0.429f, z);
                    toolMeshes[i].Rotate(origin, 0, facing.HorizontalAngleIndex * 90 * GameMath.DEG2RAD, GameMath.PIHALF);
                    toolMeshes[i].Rotate(origin, 0, GameMath.PIHALF, 0);
                }
            }
        }
Exemple #19
0
        public void CollectObject(CollectibleObject collected, float diameter)
        {
            ++collectedObjects;
            this.diameter = diameter;

            EventManager.ObjectivesUpdated(this);

            if (collectedObjects >= totalCollectibleObjects)
            {
                EventManager.Victory(this);
            }
        }
Exemple #20
0
    void loadToolMeshes()
    {
        Vec3f origin = new Vec3f(0.5f, 0.5f, 0.5f);

        ICoreClientAPI clientApi = (ICoreClientAPI)Api;

        toolMeshes[0] = null;
        IItemStack stack = inventory[0].Itemstack;

        if (stack == null)
        {
            return;
        }

        tmpItem = stack.Collectible;

        if (stack.Class == EnumItemClass.Item)
        {
            clientApi.Tesselator.TesselateItem(stack.Item, out toolMeshes[0], this);
        }
        else
        {
            clientApi.Tesselator.TesselateBlock(stack.Block, out toolMeshes[0]);
        }


        //float zOff = i > 1 ? (-1.8f / 16f) : 0;

        if (stack.Class == EnumItemClass.Item)
        {
            if (stack.Item.Shape?.VoxelizeTexture == true)
            {
                toolMeshes[0].Scale(origin, 0.33f, 0.33f, 0.33f);
            }
            else
            {
                origin.Y = 1f / 30f;
                toolMeshes[0].Scale(origin, 0.5f, 0.5f, 0.5f);
                toolMeshes[0].Rotate(origin, 0, 0, 90 * GameMath.DEG2RAD);
                toolMeshes[0].Translate(0, 0.5f, 0);
            }
        }
        else
        {
            toolMeshes[0].Scale(origin, 0.3f, 0.3f, 0.3f);
            //float x = ((i > 1) ? -0.2f : 0.3f);
            //float z = ((i % 2 == 0) ? 0.23f : -0.2f) * (facing.Axis == EnumAxis.X ? 1f : -1f);

            //toolMeshes[0].Translate(x, 0.433f + zOff, z);
            //toolMeshes[0].Rotate(origin, 0, facing.HorizontalAngleIndex * 90 * GameMath.DEG2RAD, GameMath.PIHALF);
            //toolMeshes[0].Rotate(origin, 0, GameMath.PIHALF, 0);
        }
    }
        protected virtual MeshData genMesh(ItemStack stack)
        {
            MeshData mesh;
            var      dynBlock = stack.Collectible as IContainedMeshSource;

            if (dynBlock != null)
            {
                mesh = dynBlock.GenMesh(stack, capi.BlockTextureAtlas, Pos);
                mesh.Rotate(new Vec3f(0.5f, 0.5f, 0.5f), 0, Block.Shape.rotateY * GameMath.DEG2RAD, 0);
            }
            else
            {
                ICoreClientAPI capi = Api as ICoreClientAPI;
                if (stack.Class == EnumItemClass.Block)
                {
                    mesh = capi.TesselatorManager.GetDefaultBlockMesh(stack.Block).Clone();
                }
                else
                {
                    nowTesselatingObj   = stack.Collectible;
                    nowTesselatingShape = null;
                    if (stack.Item.Shape != null)
                    {
                        nowTesselatingShape = capi.TesselatorManager.GetCachedShape(stack.Item.Shape.Base);
                    }
                    capi.Tesselator.TesselateItem(stack.Item, out mesh, this);

                    mesh.RenderPassesAndExtraBits.Fill((short)EnumChunkRenderPass.BlendNoCull);
                }
            }

            if (stack.Collectible.Attributes?[AttributeTransformCode].Exists == true)
            {
                ModelTransform transform = stack.Collectible.Attributes?[AttributeTransformCode].AsObject <ModelTransform>();
                transform.EnsureDefaultValues();
                mesh.ModelTransform(transform);

                transform.Rotation.X = 0;
                transform.Rotation.Y = Block.Shape.rotateY;
                transform.Rotation.Z = 0;
                mesh.ModelTransform(transform);
            }

            if (stack.Class == EnumItemClass.Item && (stack.Item.Shape == null || stack.Item.Shape.VoxelizeTexture))
            {
                mesh.Rotate(new Vec3f(0.5f, 0.5f, 0.5f), GameMath.PIHALF, 0, 0);
                mesh.Scale(new Vec3f(0.5f, 0.5f, 0.5f), 0.33f, 0.5f, 0.33f);
                mesh.Translate(0, -7.5f / 16f, 0f);
            }

            return(mesh);
        }
        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);
        }
Exemple #23
0
        public void RegisterLiquidStackRenderer(CollectibleObject obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj cannot be null");
            }
            if (obj.Attributes?["waterTightContainerProps"].Exists == null)
            {
                throw new ArgumentException("This collectible object has no waterTightContainerProps");
            }

            capi.Event.RegisterItemstackRenderer(obj, (inSlot, renderInfo, modelMat, posX, posY, posZ, size, color, rotate, showStackSize) => RenderLiquidItemStackGui(inSlot, renderInfo, modelMat, posX, posY, posZ, size, color, rotate, showStackSize), EnumItemRenderTarget.Gui);
        }
        public bool CanPlant(CollectibleObject seed)
        {
            if (seed == null)
            {
                return(false);
            }
            if (seed is ItemPlantableSeed || seed.WildCardMatch(modSeed) || FindMatchCode(seed.Code))
            {
                return(true);
            }

            return(false);
        }
Exemple #25
0
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1)
        {
            //base.OnBlockBroken(world, pos, byPlayer, dropQuantityMultiplier);
            // Ugly: copy pasted from Block so EnumHandled.Last prevents placement of empty rock

            dropQuantityMultiplier *= byPlayer?.Entity.Stats.GetBlended("oreDropRate") ?? 1;

            EnumHandling handled = EnumHandling.PassThrough;

            foreach (BlockBehavior behavior in BlockBehaviors)
            {
                behavior.OnBlockBroken(world, pos, byPlayer, ref handled);
                if (handled == EnumHandling.PreventSubsequent)
                {
                    return;
                }
            }

            if (handled == EnumHandling.PreventDefault)
            {
                return;
            }

            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);
            }

            world.BlockAccessor.SetBlock(0, pos);


            if (byPlayer != null && byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)
            {
                CollectibleObject coll = byPlayer?.InventoryManager.ActiveHotbarSlot.Itemstack?.Collectible;
                if (LastCodePart(1) == "flint" && (coll == null || coll.ToolTier == 0))
                {
                    world.BlockAccessor.SetBlock(world.GetBlock(new AssetLocation("rock-" + LastCodePart())).BlockId, pos);
                }
            }
        }
        public bool TryConstruct(IWorldAccessor world, BlockPos pos, CollectibleObject obj, IPlayer player)
        {
            int stage = Stage;

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

            CombustibleProperties combprops = obj.CombustibleProps;

            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);

                    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).igniteWithFuel(combprops, 4);
                }
            }

            return(true);
        }
        public bool TryAdd(ItemSlot sourceSlot, int quantity = 1)
        {
            if (IsBurning)
            {
                return(false);
            }
            if (OutSlot.StackSize > 0)
            {
                return(true);
            }
            if (sourceSlot.Itemstack == null)
            {
                return(true);
            }

            CollectibleObject collectible = sourceSlot.Itemstack.Collectible;

            if (collectible.CombustibleProps?.SmeltedStack != null && collectible.CombustibleProps.MeltingPoint < 1500 && collectible.CombustibleProps.MeltingPoint >= 1000)
            {
                int prevsize = sourceSlot.StackSize;
                if (OreSlot.StackSize >= OreCapacity)
                {
                    return(true);
                }

                int moveableq = Math.Min(OreCapacity - OreSlot.StackSize, quantity);

                sourceSlot.TryPutInto(api.World, OreSlot, moveableq);
                MarkDirty();
                return(prevsize != sourceSlot.StackSize);
            }

            if (collectible.CombustibleProps?.BurnTemperature >= 1200 && collectible.CombustibleProps.BurnDuration > 30)
            {
                int prevsize = sourceSlot.StackSize;
                if (FuelSlot.StackSize + quantity > 20)
                {
                    return(true);
                }

                int moveableq = Math.Min(20 - FuelSlot.StackSize, quantity);

                sourceSlot.TryPutInto(api.World, FuelSlot, moveableq);
                MarkDirty();
                return(prevsize != sourceSlot.StackSize);
            }

            return(true);
        }
        public bool CanAdd(ItemStack stack, int quantity = 1)
        {
            if (IsBurning)
            {
                return(false);
            }
            if (OutSlot.StackSize > 0)
            {
                return(false);
            }
            if (stack == null)
            {
                return(false);
            }

            CollectibleObject collectible = stack.Collectible;

            if (collectible.CombustibleProps?.SmeltedStack != null && collectible.CombustibleProps.MeltingPoint < 1500 && collectible.CombustibleProps.MeltingPoint >= 1000)
            {
                int prevsize = stack.StackSize;

                if (OreSlot.StackSize + quantity > OreCapacity)
                {
                    return(false);
                }
                if (!OreSlot.Empty && !OreSlot.Itemstack.Equals(api.World, stack, GlobalConstants.IgnoredStackAttributes))
                {
                    return(false);
                }
                return(true);
            }

            if (collectible.CombustibleProps?.BurnTemperature >= 1200 && collectible.CombustibleProps.BurnDuration > 30)
            {
                int prevsize = stack.StackSize;
                if (FuelSlot.StackSize + quantity > 6)
                {
                    return(false);
                }
                if (!FuelSlot.Empty && !FuelSlot.Itemstack.Equals(api.World, stack, GlobalConstants.IgnoredStackAttributes))
                {
                    return(false);
                }

                return(true);
            }

            return(false);
        }
Exemple #29
0
 private void CookStacks(ItemStack[] stacks)
 {
     for (int i = 0; i < stacks.Length; i++)
     {
         if (stacks[i] == null)
         {
             continue;
         }
         CollectibleObject obj = stacks[i].Collectible;
         if (obj.CombustibleProps != null && obj.CombustibleProps.SmeltedStack != null)
         {
             stacks[i] = obj.CombustibleProps.SmeltedStack.ResolvedItemstack;
         }
     }
 }
    public CollectibleObject GetCollectibleObjectFromSerialization(CollectibleObjectSerialization collectibleObjectSerialization)
    {
        if (collectibleObjectSerialization == null)
        {
            throw new System.InvalidOperationException("Do not search for null");
        }
        CollectibleObject temp = new CollectibleObject(collectibleObjectSerialization);

        foreach (CollectibleObject co in collectibleObjects)
        {
            if (co == temp)
            {
                return(co);
            }
        }
        throw new System.InvalidOperationException("This serialization was not found");
    }