Ejemplo n.º 1
0
        public override void OnAsyncClientParticleTick(IAsyncParticleManager manager, BlockPos pos, float windAffectednessAtPos, float secondsTicking)
        {
            if (IsExtinct)
            {
                base.OnAsyncClientParticleTick(manager, pos, windAffectednessAtPos, secondsTicking);
                return;
            }

            BlockEntityFirepit bef = manager.BlockAccess.GetBlockEntity(pos) as BlockEntityFirepit;

            if (bef != null && bef.CurrentModel == EnumFirepitModel.Wide)
            {
                for (int i = 0; i < ringParticles.Length; i++)
                {
                    AdvancedParticleProperties bps = ringParticles[i];
                    bps.WindAffectednesAtPos = windAffectednessAtPos;
                    bps.basePos.X            = pos.X + basePos[i].X;
                    bps.basePos.Y            = pos.Y + basePos[i].Y;
                    bps.basePos.Z            = pos.Z + basePos[i].Z;

                    manager.Spawn(bps);
                }

                return;
            }

            base.OnAsyncClientParticleTick(manager, pos, windAffectednessAtPos, secondsTicking);
        }
Ejemplo n.º 2
0
        int GetTempOfBlockOnFace(BlockFacing direction, BlockSelection currentPos, IWorldAccessor world)
        {
            BlockPos inputBlockpos = currentPos.Position.AddCopy(direction);

            Block block = world.BlockAccessor.GetBlock(inputBlockpos);

            world.Logger.Log(EnumLogType.Debug, $"Getting temp for: {block.Code.ToString()}");

            if (TempuratureValues.ContainsKey(block.Code.ToString()))
            {
                return(TempuratureValues[block.Code.ToString()]);
            }

            //TODO: add method to block entities getting their tempuratures.

            if (DynamicTemps.Contains(block.Code.ToString())) //the firepit... for now.
            {
                BlockEntityFirepit befirepit = (BlockEntityFirepit)world.BlockAccessor.GetBlockEntity(inputBlockpos);
                if (befirepit != null)
                {
                    return((int)befirepit.furnaceTemperature);
                }
            }

            return(20);
        }
Ejemplo n.º 3
0
        public override void OnTryIgniteBlockOver(EntityAgent byEntity, BlockPos pos, float secondsIgniting, ref EnumHandling handling)
        {
            BlockEntityFirepit bef = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityFirepit;

            if (bef != null && !bef.canIgniteFuel)
            {
                bef.canIgniteFuel          = true;
                bef.extinguishedTotalHours = api.World.Calendar.TotalHours;
            }

            handling = EnumHandling.PreventDefault;
        }
Ejemplo n.º 4
0
        public override EnumIgniteState OnTryIgniteBlock(EntityAgent byEntity, BlockPos pos, float secondsIgniting)
        {
            BlockEntityFirepit bef = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityFirepit;

            if (bef != null && bef.fuelSlot.Empty)
            {
                return(EnumIgniteState.NotIgnitablePreventDefault);
            }
            if (bef != null && bef.IsBurning)
            {
                return(EnumIgniteState.NotIgnitablePreventDefault);
            }

            return(secondsIgniting > 3 ? EnumIgniteState.IgniteNow : EnumIgniteState.Ignitable);
        }
Ejemplo n.º 5
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            int       stage = Stage;
            ItemStack stack = byPlayer.InventoryManager.ActiveHotbarSlot?.Itemstack;

            if (stage == 5)
            {
                BlockEntityFirepit bef = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityFirepit;

                if (bef != null && stack != null && byPlayer.Entity.Controls.Sneak)
                {
                    if (stack.Collectible.CombustibleProps != null && stack.Collectible.CombustibleProps.MeltingPoint > 0)
                    {
                        ItemStackMoveOperation op = new ItemStackMoveOperation(world, EnumMouseButton.Button1, 0, EnumMergePriority.DirectMerge, 1);
                        byPlayer.InventoryManager.ActiveHotbarSlot.TryPutInto(bef.inputSlot, ref op);
                        if (op.MovedQuantity > 0)
                        {
                            return(true);
                        }
                    }

                    if (stack.Collectible.CombustibleProps != null && stack.Collectible.CombustibleProps.BurnTemperature > 0)
                    {
                        ItemStackMoveOperation op = new ItemStackMoveOperation(world, EnumMouseButton.Button1, 0, EnumMergePriority.DirectMerge, 1);
                        byPlayer.InventoryManager.ActiveHotbarSlot.TryPutInto(bef.fuelSlot, ref op);
                        if (op.MovedQuantity > 0)
                        {
                            return(true);
                        }
                    }
                }

                return(base.OnBlockInteractStart(world, byPlayer, blockSel));
            }


            if (stack != null && TryConstruct(world, blockSel.Position, stack.Collectible))
            {
                if (byPlayer != null && byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)
                {
                    byPlayer.InventoryManager.ActiveHotbarSlot.TakeOut(1);
                }
                return(true);
            }


            return(false);
        }
Ejemplo n.º 6
0
 public EnumFirepitModel GetDesiredFirepitModel(ItemStack stack, BlockEntityFirepit firepit, bool forOutputSlot)
 {
     return(EnumFirepitModel.Wide);
 }
Ejemplo n.º 7
0
 public IInFirepitRenderer GetRendererWhenInFirepit(ItemStack stack, BlockEntityFirepit firepit, bool forOutputSlot)
 {
     return(new PotInFirepitRenderer(api as ICoreClientAPI, stack, firepit.pos, forOutputSlot));
 }
Ejemplo n.º 8
0
        public override void OnLoaded(ICoreAPI api)
        {
            base.OnLoaded(api);

            IsExtinct = LastCodePart() != "lit";

            if (!IsExtinct && api.Side == EnumAppSide.Client)
            {
                ringParticles = new AdvancedParticleProperties[this.ParticleProperties.Length * 4];
                basePos       = new Vec3f[ringParticles.Length];

                Cuboidf[] spawnBoxes = new Cuboidf[]
                {
                    new Cuboidf(x1: 0.125f, y1: 0, z1: 0.125f, x2: 0.3125f, y2: 0.5f, z2: 0.875f),
                    new Cuboidf(x1: 0.7125f, y1: 0, z1: 0.125f, x2: 0.875f, y2: 0.5f, z2: 0.875f),
                    new Cuboidf(x1: 0.125f, y1: 0, z1: 0.125f, x2: 0.875f, y2: 0.5f, z2: 0.3125f),
                    new Cuboidf(x1: 0.125f, y1: 0, z1: 0.7125f, x2: 0.875f, y2: 0.5f, z2: 0.875f)
                };

                for (int i = 0; i < ParticleProperties.Length; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        AdvancedParticleProperties props = ParticleProperties[i].Clone();

                        Cuboidf box = spawnBoxes[j];
                        basePos[i * 4 + j] = new Vec3f(0, 0, 0);

                        props.PosOffset[0].avg = box.MidX;
                        props.PosOffset[0].var = box.Width / 2;

                        props.PosOffset[1].avg = 0.1f;
                        props.PosOffset[1].var = 0.05f;

                        props.PosOffset[2].avg = box.MidZ;
                        props.PosOffset[2].var = box.Length / 2;

                        props.Quantity.avg /= 4f;
                        props.Quantity.var /= 4f;

                        ringParticles[i * 4 + j] = props;
                    }
                }
            }


            interactions = ObjectCacheUtil.GetOrCreate(api, "firepitInteractions-" + Stage, () =>
            {
                List <ItemStack> canIgniteStacks = new List <ItemStack>();

                foreach (CollectibleObject obj in api.World.Collectibles)
                {
                    string firstCodePart = obj.FirstCodePart();

                    if (obj is Block && (obj as Block).HasBehavior <BlockBehaviorCanIgnite>() || obj is ItemFirestarter)
                    {
                        List <ItemStack> stacks = obj.GetHandBookStacks(api as ICoreClientAPI);
                        if (stacks != null)
                        {
                            canIgniteStacks.AddRange(stacks);
                        }
                    }
                }

                return(new WorldInteraction[]
                {
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-firepit-open",
                        MouseButton = EnumMouseButton.Right,
                        ShouldApply = (WorldInteraction wi, BlockSelection blockSelection, EntitySelection entitySelection) =>
                        {
                            return Stage == 5;
                        }
                    },
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-firepit-ignite",
                        MouseButton = EnumMouseButton.Right,
                        HotKeyCode = "sneak",
                        Itemstacks = canIgniteStacks.ToArray(),
                        GetMatchingStacks = (wi, bs, es) => {
                            BlockEntityFirepit bef = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityFirepit;
                            if (bef?.fuelSlot != null && !bef.fuelSlot.Empty && !bef.IsBurning)
                            {
                                return wi.Itemstacks;
                            }
                            return null;
                        }
                    },
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-firepit-refuel",
                        MouseButton = EnumMouseButton.Right,
                        HotKeyCode = "sneak"
                    }
                });
            });
        }
Ejemplo n.º 9
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            int       stage = Stage;
            ItemStack stack = byPlayer.InventoryManager.ActiveHotbarSlot?.Itemstack;

            if (stage == 5)
            {
                BlockEntityFirepit bef = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityFirepit;

                if (bef != null && stack?.Block != null && stack.Block.HasBehavior <BlockBehaviorCanIgnite>())
                {
                    return(false);
                }

                if (bef != null && stack != null && byPlayer.Entity.Controls.Sneak)
                {
                    if (stack.Collectible.CombustibleProps != null && stack.Collectible.CombustibleProps.MeltingPoint > 0)
                    {
                        ItemStackMoveOperation op = new ItemStackMoveOperation(world, EnumMouseButton.Button1, 0, EnumMergePriority.DirectMerge, 1);
                        byPlayer.InventoryManager.ActiveHotbarSlot.TryPutInto(bef.inputSlot, ref op);
                        if (op.MovedQuantity > 0)
                        {
                            (byPlayer as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);
                            return(true);
                        }
                    }

                    if (stack.Collectible.CombustibleProps != null && stack.Collectible.CombustibleProps.BurnTemperature > 0)
                    {
                        ItemStackMoveOperation op = new ItemStackMoveOperation(world, EnumMouseButton.Button1, 0, EnumMergePriority.DirectMerge, 1);
                        byPlayer.InventoryManager.ActiveHotbarSlot.TryPutInto(bef.fuelSlot, ref op);
                        if (op.MovedQuantity > 0)
                        {
                            (byPlayer as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);
                            return(true);
                        }
                    }
                }

                if (stack?.Collectible.Attributes?.IsTrue("mealContainer") == true)
                {
                    ItemSlot potSlot = null;
                    if (bef?.inputStack?.Collectible is BlockCookedContainer)
                    {
                        potSlot = bef.inputSlot;
                    }
                    if (bef?.outputStack?.Collectible is BlockCookedContainer)
                    {
                        potSlot = bef.outputSlot;
                    }

                    if (potSlot != null)
                    {
                        BlockCookedContainer blockPot   = potSlot.Itemstack.Collectible as BlockCookedContainer;
                        ItemSlot             targetSlot = byPlayer.InventoryManager.ActiveHotbarSlot;
                        if (byPlayer.InventoryManager.ActiveHotbarSlot.StackSize > 1)
                        {
                            targetSlot = new DummySlot(targetSlot.TakeOut(1));
                            byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty();
                            blockPot.ServeIntoStack(targetSlot, potSlot, world);
                            if (!byPlayer.InventoryManager.TryGiveItemstack(targetSlot.Itemstack, true))
                            {
                                world.SpawnItemEntity(targetSlot.Itemstack, byPlayer.Entity.ServerPos.XYZ);
                            }
                        }
                        else
                        {
                            blockPot.ServeIntoStack(targetSlot, potSlot, world);
                        }
                    }
                    else
                    {
                        return(false);
                    }

                    return(true);
                }



                return(base.OnBlockInteractStart(world, byPlayer, blockSel));
            }


            if (stack != null && TryConstruct(world, blockSel.Position, stack.Collectible, byPlayer))
            {
                if (byPlayer != null && byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)
                {
                    byPlayer.InventoryManager.ActiveHotbarSlot.TakeOut(1);
                }
                return(true);
            }


            return(false);
        }