Exemple #1
0
        public override void OnGroundIdle(EntityItem entityItem)
        {
            entityItem.Die(EnumDespawnReason.Removed);

            if (entityItem.World.Side == EnumAppSide.Server)
            {
                Vec3d pos = entityItem.ServerPos.XYZ;

                WaterTightContainableProps props = BlockLiquidContainerBase.GetContainableProps(entityItem.Itemstack);
                float litres = (float)entityItem.Itemstack.StackSize / props.ItemsPerLitre;

                entityItem.World.SpawnCubeParticles(pos, entityItem.Itemstack, 0.75f, Math.Min(100, (int)(2 * litres)), 0.45f);
                entityItem.World.PlaySoundAt(new AssetLocation("sounds/environment/smallsplash"), (float)pos.X, (float)pos.Y, (float)pos.Z, null);

                BlockEntityFarmland bef = api.World.BlockAccessor.GetBlockEntity(pos.AsBlockPos) as BlockEntityFarmland;
                if (bef != null)
                {
                    bef.WaterFarmland(Height.ToInt() / 6f, false);
                    bef.MarkDirty(true);
                }
            }



            base.OnGroundIdle(entityItem);
        }
Exemple #2
0
        public void WaterFarmland(float dt, bool waterNeightbours = true)
        {
            currentlyWateredSeconds += dt;
            lastWateredMs            = api.World.ElapsedMilliseconds;

            if (currentlyWateredSeconds > 1f)
            {
                if (IsWatered && waterNeightbours)
                {
                    foreach (BlockFacing neib in BlockFacing.HORIZONTALS)
                    {
                        BlockPos            npos = pos.AddCopy(neib);
                        BlockEntityFarmland bef  = api.World.BlockAccessor.GetBlockEntity(npos) as BlockEntityFarmland;
                        if (bef != null)
                        {
                            bef.WaterFarmland(1.01f, false);
                        }
                    }
                }

                lastWateredTotalHours = api.World.Calendar.TotalHours;
                UpdateFarmlandBlock();
                currentlyWateredSeconds--;
            }
        }
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1)
        {
            base.OnBlockBroken(world, pos, byPlayer, dropQuantityMultiplier);

            BlockEntityFarmland befarmland = world.BlockAccessor.GetBlockEntity(pos.DownCopy()) as BlockEntityFarmland;

            befarmland?.OnCropBlockBroken();
        }
        public override void OnBlockPlaced(IWorldAccessor world, BlockPos blockPos, ItemStack byItemStack = null)
        {
            base.OnBlockPlaced(world, blockPos, byItemStack);

            if (byItemStack != null)
            {
                BlockEntityFarmland befarmland = world.BlockAccessor.GetBlockEntity(blockPos) as BlockEntityFarmland;
                befarmland?.CreatedFromSoil(byItemStack.Block);
            }
        }
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            BlockEntityFarmland befarmland = world.BlockAccessor.GetBlockEntity(blockSel.Position.DownCopy()) as BlockEntityFarmland;
            if (befarmland != null && befarmland.OnBlockInteract(byPlayer)) return true;

            BEBehaviorFruiting bef = world.BlockAccessor.GetBlockEntity(blockSel.Position)?.GetBehavior<BEBehaviorFruiting>();
            if (bef != null) return true;  //Move to BlockInteractStep

            return base.OnBlockInteractStart(world, byPlayer, blockSel);
        }
        public override string GetPlacedBlockName(IWorldAccessor world, BlockPos pos)
        {
            BlockEntityFarmland befarmland = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityFarmland;

            if (befarmland != null)
            {
                Block farmlandBlock = api.World.GetBlock(CodeWithVariant("state", befarmland.IsVisiblyMoist ? "moist" : "dry"));
                return(new ItemStack(farmlandBlock).GetName());
            }
            return(base.GetPlacedBlockName(world, pos));
        }
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            BlockEntityFarmland befarmland = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityFarmland;

            if (befarmland != null && befarmland.OnBlockInteract(byPlayer))
            {
                return(true);
            }

            return(base.OnBlockInteractStart(world, byPlayer, blockSel));
        }
Exemple #8
0
        public void WaterFarmland(float dt, bool waterNeightbours = true)
        {
            moistureLevel = Math.Min(1, moistureLevel + dt / 2);

            if (waterNeightbours)
            {
                foreach (BlockFacing neib in BlockFacing.HORIZONTALS)
                {
                    BlockPos            npos = base.Pos.AddCopy(neib);
                    BlockEntityFarmland bef  = Api.World.BlockAccessor.GetBlockEntity(npos) as BlockEntityFarmland;
                    if (bef != null)
                    {
                        bef.WaterFarmland(dt / 3, false);
                    }
                }
            }

            updateMoistureLevel(Api.World.Calendar.TotalDays, lastWaterDistance);
        }
        public override ItemStack[] GetDrops(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1)
        {
            BlockEntityFarmland befarmland = world.BlockAccessor.GetBlockEntity(pos.DownCopy()) as BlockEntityFarmland;

            if (befarmland == null)
            {
                dropQuantityMultiplier *= byPlayer?.Entity.Stats.GetBlended("wildCropDropRate") ?? 1;
            }

            ItemStack[] drops = base.GetDrops(world, pos, byPlayer, dropQuantityMultiplier);


            if (befarmland != null)
            {
                drops = befarmland.GetDrops(drops);
            }

            return(drops);
        }
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (blockSel == null)
            {
                return(false);
            }
            if (slot.Itemstack.TempAttributes.GetInt("refilled") > 0)
            {
                return(false);
            }

            float prevsecondsused = slot.Itemstack.TempAttributes.GetFloat("secondsUsed");

            slot.Itemstack.TempAttributes.SetFloat("secondsUsed", secondsUsed);

            float remainingwater = GetRemainingWateringSeconds(slot.Itemstack);

            SetRemainingWateringSeconds(slot.Itemstack, remainingwater -= secondsUsed - prevsecondsused);


            if (remainingwater <= 0)
            {
                return(false);
            }

            IWorldAccessor world = byEntity.World;

            BlockPos targetPos = blockSel.Position;

            Block facingBlock = world.BlockAccessor.GetBlock(blockSel.Position.AddCopy(blockSel.Face));

            if (facingBlock.Code.Path == "fire")
            {
                world.BlockAccessor.SetBlock(0, blockSel.Position.AddCopy(blockSel.Face));
            }

            Block block           = world.BlockAccessor.GetBlock(blockSel.Position);
            bool  notOnSolidblock = false;

            if ((block.CollisionBoxes == null || block.CollisionBoxes.Length == 0) && !block.IsLiquid())
            {
                notOnSolidblock = true;
                targetPos       = targetPos.DownCopy();
            }

            BlockEntityFarmland be = world.BlockAccessor.GetBlockEntity(targetPos) as BlockEntityFarmland;

            if (be != null)
            {
                be.WaterFarmland(secondsUsed - prevsecondsused);
            }

            float speed = 4f;

            if (world.Side == EnumAppSide.Client)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                tf.Origin.Set(0.5f, 0.2f, 0.5f);
                tf.Translation.Set(-Math.Min(0.25f, speed * secondsUsed / 4), 0, 0);

                tf.Rotation.Z = GameMath.Min(60, secondsUsed * 90 * speed, 80 - remainingwater * 5);
                byEntity.Controls.UsingHeldItemTransformBefore = tf;
            }

            IPlayer byPlayer = null;

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


            if (secondsUsed > 1 / speed)
            {
                Vec3d pos = blockSel.Position.ToVec3d().Add(blockSel.HitPosition);
                if (notOnSolidblock)
                {
                    pos.Y = (int)pos.Y + 0.05;
                }
                WaterParticles.MinPos = pos.Add(-0.125 / 2, 1 / 16f, -0.125 / 2);
                byEntity.World.SpawnParticles(WaterParticles, byPlayer);
            }

            return(true);
        }
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (blockSel == null)
            {
                return(false);
            }
            if (slot.Itemstack.TempAttributes.GetInt("refilled") > 0)
            {
                return(false);
            }

            float prevsecondsused = slot.Itemstack.TempAttributes.GetFloat("secondsUsed");

            slot.Itemstack.TempAttributes.SetFloat("secondsUsed", secondsUsed);

            float remainingwater = GetRemainingWateringSeconds(slot.Itemstack);

            SetRemainingWateringSeconds(slot.Itemstack, remainingwater -= secondsUsed - prevsecondsused);


            if (remainingwater <= 0)
            {
                return(false);
            }

            IWorldAccessor world = byEntity.World;

            BlockPos targetPos = blockSel.Position;

            if (api.World.Side == EnumAppSide.Server)
            {
                var beburningBh = world.BlockAccessor.GetBlockEntity(blockSel.Position.AddCopy(blockSel.Face))?.GetBehavior <BEBehaviorBurning>();
                if (beburningBh != null)
                {
                    beburningBh.KillFire(false);
                }

                beburningBh = world.BlockAccessor.GetBlockEntity(blockSel.Position)?.GetBehavior <BEBehaviorBurning>();
                if (beburningBh != null)
                {
                    beburningBh.KillFire(false);
                }

                Vec3i voxelPos = new Vec3i();
                for (int dx = -2; dx < 2; dx++)
                {
                    for (int dy = -2; dy < 2; dy++)
                    {
                        for (int dz = -2; dz < 2; dz++)
                        {
                            int x = (int)(blockSel.HitPosition.X * 16);
                            int y = (int)(blockSel.HitPosition.Y * 16);
                            int z = (int)(blockSel.HitPosition.Z * 16);
                            if (x + dx < 0 || x + dx > 15 || y + dy < 0 || y + dy > 15 || z + dz < 0 || z + dz > 15)
                            {
                                continue;
                            }

                            voxelPos.Set(x + dx, y + dy, z + dz);

                            int   faceAndSubPosition = CollectibleBehaviorArtPigment.BlockSelectionToSubPosition(blockSel.Face, voxelPos);
                            Block decorblock         = world.BlockAccessor.GetDecor(blockSel.Position, faceAndSubPosition);

                            if (decorblock?.FirstCodePart() == "caveart")
                            {
                                world.BlockAccessor.BreakDecor(blockSel.Position, blockSel.Face, faceAndSubPosition);
                            }
                        }
                    }
                }
            }

            Block block           = world.BlockAccessor.GetBlock(blockSel.Position);
            bool  notOnSolidblock = false;

            if ((block.CollisionBoxes == null || block.CollisionBoxes.Length == 0) && !block.IsLiquid())
            {
                notOnSolidblock = true;
                targetPos       = targetPos.DownCopy();
            }

            BlockEntityFarmland be = world.BlockAccessor.GetBlockEntity(targetPos) as BlockEntityFarmland;

            if (be != null)
            {
                be.WaterFarmland(secondsUsed - prevsecondsused);
            }

            float speed = 3f;

            if (world.Side == EnumAppSide.Client)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                tf.Origin.Set(0.5f, 0.2f, 0.5f);
                tf.Translation.Set(-Math.Min(0.25f, speed * secondsUsed / 2), 0, 0);
                tf.Rotation.Z = GameMath.Min(60, secondsUsed * 90 * speed, 120 - remainingwater * 4);
                byEntity.Controls.UsingHeldItemTransformBefore = tf;
            }

            IPlayer byPlayer = null;

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


            if (secondsUsed > 1 / speed)
            {
                Vec3d pos = blockSel.Position.ToVec3d().Add(blockSel.HitPosition);
                if (notOnSolidblock)
                {
                    pos.Y = (int)pos.Y + 0.05;
                }
                WaterParticles.MinPos = pos.Add(-0.125 / 2, 1 / 16f, -0.125 / 2);
                byEntity.World.SpawnParticles(WaterParticles, byPlayer);
            }

            return(true);
        }