Beispiel #1
0
        private void PickupFarmland(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel)
        {
            Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position);

            if (block is BlockFarmland)
            {
                BlockEntity blockEntity = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position);
                if (blockEntity is BlockEntityFarmland)
                {
                    TreeAttribute tree = new TreeAttribute();
                    blockEntity.ToTreeAttributes(tree);
                    slot.Itemstack.Attributes["farmland"] = tree;
                    slot.Itemstack.Attributes.SetInt("farmId", byEntity.World.BlockAccessor.GetBlock(blockSel.Position).Id);
                    byEntity.World.BlockAccessor.SetBlock(0, blockSel.Position);
                    // BlockPos cropPos = blockSel.Position.AddCopy(0, 1, 0);
                    byEntity.World.BlockAccessor.TriggerNeighbourBlockUpdate(blockSel.Position);
                    // Block seedBlock = byEntity.World.BlockAccessor.GetBlock(cropPos);
                    // if (seedBlock is BlockCrop)
                    // {
                    // byEntity.World.BlockAccessor.BreakBlock(cropPos, byEntity as IPlayer);
                    // }
                    slot.MarkDirty();
                }
            }
        }
        public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d)
        {
            if (removedBlockentity != null)
            {
                this.blockEntityAttributes = new TreeAttribute();
                removedBlockentity.ToTreeAttributes(blockEntityAttributes);
                blockEntityClass = api.World.ClassRegistry.GetBlockEntityClass(removedBlockentity.GetType());
            }

            SimulationRange = (int)(0.75f * GlobalConstants.DefaultTrackingRange);
            base.Initialize(properties, api, InChunkIndex3d);

            // Need to capture this now before we remove the block and start to fall
            drops = Block.GetDrops(api.World, initialPos, null);

            lightHsv = Block.GetLightHsv(World.BlockAccessor, initialPos);

            SidedPos.Motion.Y = -0.02;
            blockAsStack      = new ItemStack(Block);


            if (api.Side == EnumAppSide.Client && fallSound != null && fallingNow.Count < 100)
            {
                fallingNow.Add(EntityId);
                ICoreClientAPI capi = api as ICoreClientAPI;
                sound = capi.World.LoadSound(new SoundParams()
                {
                    Location  = fallSound.WithPathPrefixOnce("sounds/").WithPathAppendixOnce(".ogg"),
                    Position  = new Vec3f((float)Pos.X, (float)Pos.Y, (float)Pos.Z),
                    Range     = 32,
                    Pitch     = 0.8f + (float)capi.World.Rand.NextDouble() * 0.3f,
                    Volume    = 1,
                    SoundType = EnumSoundType.Ambient
                });
                sound.Start();
                soundStartDelay = 0.05f + (float)capi.World.Rand.NextDouble() / 3f;
            }

            canFallSideways = WatchedAttributes.GetBool("canFallSideways");
            dustIntensity   = WatchedAttributes.GetFloat("dustIntensity");


            if (WatchedAttributes.HasAttribute("fallSound"))
            {
                fallSound = new AssetLocation(WatchedAttributes.GetString("fallSound"));
            }

            if (api.World.Side == EnumAppSide.Client)
            {
                particleSys = api.ModLoader.GetModSystem <FallingBlockParticlesModSystem>();
                particleSys.Register(this);
                physicsBh = GetBehavior <EntityBehaviorPassivePhysics>();
            }
        }
Beispiel #3
0
        public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d)
        {
            if (removedBlockentity != null)
            {
                this.blockEntityAttributes = new TreeAttribute();
                removedBlockentity.ToTreeAttributes(blockEntityAttributes);
                blockEntityClass = api.World.ClassRegistry.GetBlockEntityClass(removedBlockentity.GetType());
            }

            SimulationRange = 3 * api.World.BlockAccessor.ChunkSize;

            base.Initialize(properties, api, InChunkIndex3d);

            // Need to capture this now before we remove the block and start to fall
            drops = Block.GetDrops(api.World, initialPos, null);
        }
Beispiel #4
0
        public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d)
        {
            if (removedBlockentity != null)
            {
                this.blockEntityAttributes = new TreeAttribute();
                removedBlockentity.ToTreeAttributes(blockEntityAttributes);
                blockEntityClass = api.World.ClassRegistry.GetBlockEntityClass(removedBlockentity.GetType());
            }

            SimulationRange = 3 * api.World.BlockAccessor.ChunkSize;
            base.Initialize(properties, api, InChunkIndex3d);

            // Need to capture this now before we remove the block and start to fall
            drops = Block.GetDrops(api.World, initialPos, null);

            lightHsv = Block.GetLightHsv(World.BlockAccessor, initialPos);

            LocalPos.Motion.Y = -0.02;
            blockAsStack      = new ItemStack(Block);


            if (api.Side == EnumAppSide.Client && fallSound != null)
            {
                ICoreClientAPI capi = api as ICoreClientAPI;
                sound = capi.World.LoadSound(new SoundParams()
                {
                    Location  = fallSound.WithPathPrefixOnce("sounds/").WithPathAppendixOnce(".ogg"),
                    Position  = new Vec3f((float)Pos.X, (float)Pos.Y, (float)Pos.Z),
                    Range     = 32,
                    Pitch     = 0.8f + (float)capi.World.Rand.NextDouble() * 0.3f,
                    Volume    = 1,
                    SoundType = EnumSoundType.Ambient
                });
                soundStartDelay = 0.05f + (float)capi.World.Rand.NextDouble() / 3f;
            }

            canFallSideways = WatchedAttributes.GetBool("canFallSideways");
            dustyFall       = WatchedAttributes.GetBool("dustyFall");


            if (WatchedAttributes.HasAttribute("fallSound"))
            {
                fallSound = new AssetLocation(WatchedAttributes.GetString("fallSound"));
            }
        }
Beispiel #5
0
        //when the player uses the middle button to select a block
        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
        {
            Block       block = world.BlockAccessor.GetBlock(CodeWithParts("north", "down"));
            BlockEntity bec   = world.BlockAccessor.GetBlockEntity(pos);

            if (bec == null)
            {
                return(null);
            }

            TreeAttribute tree = new TreeAttribute();

            bec.ToTreeAttributes(tree);
            tree.RemoveAttribute("posx");
            tree.RemoveAttribute("posy");
            tree.RemoveAttribute("posz");

            return(new ItemStack(block.Id, EnumItemClass.Block, 1, tree, world));
        }
        public void MoveBlock(BlockPos fromPos, BlockPos toPos)
        {
            Block block = bA.GetBlock(fromPos);

            if (block.EntityClass != null)
            {
                TreeAttribute attribs = new TreeAttribute();
                BlockEntity   be      = bA.GetBlockEntity(fromPos);
                if (be != null)
                {
                    be.ToTreeAttributes(attribs);
                    attribs.SetInt("posx", toPos.X);
                    attribs.SetInt("posy", toPos.Y);
                    attribs.SetInt("posz", toPos.Z);

                    bA.SetBlock(0, fromPos);
                    bA.SetBlock(block.BlockId, toPos);

                    BlockEntity be2 = bA.GetBlockEntity(toPos);

                    if (be2 != null)
                    {
                        be2.FromTreeAtributes(attribs, api.World);
                    }
                }
            }
            else
            {
                bA.SetBlock(0, fromPos);
                bA.SetBlock(block.BlockId, toPos);
                if (bA.GetBlock(toPos).Id != 0)
                {
                    api.World.SpawnCubeParticles(toPos, toPos.ToVec3d().Add(0.5), 4, 32);
                }
            }
        }
Beispiel #7
0
        public int MoveArea(int dx, int dy, int dz, BlockPos start, BlockPos end)
        {
            int updated = 0;

            BlockPos startPos = new BlockPos(Math.Min(start.X, end.X), Math.Min(start.Y, end.Y), Math.Min(start.Z, end.Z));
            BlockPos endPos   = new BlockPos(Math.Max(start.X, end.X), Math.Max(start.Y, end.Y), Math.Max(start.Z, end.Z));
            BlockPos curPos   = startPos.Copy();

            int wx = endPos.X - startPos.X;
            int wy = endPos.Y - startPos.Y;
            int wz = endPos.Z - startPos.Z;

            int   quantityBlocks = dx * dy * dz;
            Block block          = sapi.World.Blocks[0];

            if (!MayPlace(block, quantityBlocks))
            {
                return(0);
            }


            BlockPos newPos  = new BlockPos();
            BlockPos prevPos = new BlockPos();

            Dictionary <BlockPos, ITreeAttribute> blockEntityData = new Dictionary <BlockPos, ITreeAttribute>();

            // Clear area
            while (curPos.X < endPos.X)
            {
                curPos.Y = startPos.Y;
                while (curPos.Y < endPos.Y)
                {
                    curPos.Z = startPos.Z;
                    while (curPos.Z < endPos.Z)
                    {
                        BlockEntity be = workspace.revertableBlockAccess.GetBlockEntity(curPos);
                        if (be != null)
                        {
                            TreeAttribute tree = new TreeAttribute();
                            be.ToTreeAttributes(tree);
                            blockEntityData[curPos.AddCopy(dx, dy, dz)] = tree;
                        }

                        workspace.revertableBlockAccess.SetBlock(0, curPos);

                        curPos.Z++;
                    }

                    curPos.Y++;
                }

                curPos.X++;
            }


            curPos = startPos.Copy();

            // move selection
            while (curPos.X < endPos.X)
            {
                curPos.Y = startPos.Y;
                while (curPos.Y < endPos.Y)
                {
                    curPos.Z = startPos.Z;
                    while (curPos.Z < endPos.Z)
                    {
                        newPos.Set(curPos.X + dx, curPos.Y + dy, curPos.Z + dz);
                        int prevBlockId = workspace.revertableBlockAccess.GetBlockId(curPos);
                        workspace.revertableBlockAccess.SetBlock(prevBlockId, newPos);

                        curPos.Z++;
                    }

                    curPos.Y++;
                }

                curPos.X++;
            }

            workspace.revertableBlockAccess.Commit();

            // restore block entity data
            foreach (var val in blockEntityData)
            {
                BlockEntity be = workspace.revertableBlockAccess.GetBlockEntity(val.Key);
                if (be != null)
                {
                    val.Value.SetInt("posx", val.Key.X);
                    val.Value.SetInt("posy", val.Key.Y);
                    val.Value.SetInt("posz", val.Key.Z);

                    be.FromTreeAttributes(val.Value, this.sapi.World);
                }
            }

            return(updated);
        }
Beispiel #8
0
        public void MirrorArea(BlockPos startPos, BlockPos endPos, BlockFacing dir, bool selectNewArea, bool growNewArea)
        {
            BlockPos curPos = startPos.Copy();

            BlockPos offset = new BlockPos(
                (endPos.X - startPos.X) * dir.Normali.X,
                (endPos.Y - startPos.Y) * dir.Normali.Y,
                (endPos.Z - startPos.Z) * dir.Normali.Z
                );

            BlockPos pos = new BlockPos();
            Block    block;

            Dictionary <BlockPos, ITreeAttribute> blockEntityData = new Dictionary <BlockPos, ITreeAttribute>();

            while (curPos.X < endPos.X)
            {
                curPos.Y = startPos.Y;

                while (curPos.Y < endPos.Y)
                {
                    curPos.Z = startPos.Z;

                    while (curPos.Z < endPos.Z)
                    {
                        int blockId = workspace.revertableBlockAccess.GetBlockId(curPos);

                        if (dir.Axis == EnumAxis.Y)
                        {
                            block = sapi.World.GetBlock(sapi.World.Blocks[blockId].GetVerticallyFlippedBlockCode());
                        }
                        else
                        {
                            block = sapi.World.GetBlock(sapi.World.Blocks[blockId].GetHorizontallyFlippedBlockCode(dir.Axis));
                        }

                        // Mirrored position inside the same area
                        int mX = dir.Axis == EnumAxis.X ? startPos.X + (endPos.X - curPos.X) - 1 : curPos.X;
                        int mY = dir.Axis == EnumAxis.Y ? startPos.Y + (endPos.Y - curPos.Y) - 1 : curPos.Y;
                        int mZ = dir.Axis == EnumAxis.Z ? startPos.Z + (endPos.Z - curPos.Z) - 1 : curPos.Z;

                        pos.Set(mX + offset.X, mY + offset.Y, mZ + offset.Z);

                        BlockEntity be = workspace.revertableBlockAccess.GetBlockEntity(curPos);
                        if (be != null)
                        {
                            TreeAttribute tree = new TreeAttribute();
                            be.ToTreeAttributes(tree);
                            blockEntityData[pos.Copy()] = tree;
                        }


                        workspace.revertableBlockAccess.SetBlock(block.BlockId, pos);

                        curPos.Z++;
                    }
                    curPos.Y++;
                }
                curPos.X++;
            }

            workspace.revertableBlockAccess.Commit();
            Good("Marked area mirrored " + dir);

            // restore block entity data
            foreach (var val in blockEntityData)
            {
                BlockEntity be = workspace.revertableBlockAccess.GetBlockEntity(val.Key);
                if (be != null)
                {
                    ITreeAttribute tree = val.Value;

                    tree.SetInt("posx", val.Key.X);
                    tree.SetInt("posy", val.Key.Y);
                    tree.SetInt("posz", val.Key.Z);

                    if (be is IBlockEntityRotatable)
                    {
                        (be as IBlockEntityRotatable).OnTransformed(tree, 0, dir.Axis);
                    }

                    be.FromTreeAttributes(tree, this.sapi.World);
                }
            }

            if (selectNewArea)
            {
                workspace.StartMarker.Add(offset);
                workspace.EndMarker.Add(offset);
                ResendBlockHighlights();
            }

            if (growNewArea)
            {
                workspace.StartMarker.Set(
                    startPos.X + (offset.X < 0 ? offset.X : 0),
                    startPos.Y + (offset.Y < 0 ? offset.Y : 0),
                    startPos.Z + (offset.Z < 0 ? offset.Z : 0)
                    );

                workspace.EndMarker.Set(
                    endPos.X + (offset.X > 0 ? offset.X : 0),
                    endPos.Y + (offset.Y > 0 ? offset.Y : 0),
                    endPos.Z + (offset.Z > 0 ? offset.Z : 0)
                    );

                ResendBlockHighlights();
            }
        }