示例#1
0
        public override void OnReceivedServerPacket(int packetid, byte[] data)
        {
            if (packetid == (int)EnumSignPacketId.OpenDialog)
            {
                using (MemoryStream ms = new MemoryStream(data))
                {
                    BinaryReader reader = new BinaryReader(ms);

                    string dialogClassName = reader.ReadString();
                    string dialogTitle     = reader.ReadString();
                    text = reader.ReadString();
                    if (text == null)
                    {
                        text = "";
                    }

                    IClientWorldAccessor clientWorld = (IClientWorldAccessor)api.World;

                    GuiDialogBlockEntityTextInput dlg = new GuiDialogBlockEntityTextInput(dialogTitle, pos, text, api as ICoreClientAPI, 3);
                    dlg.OnTextChanged = DidChangeTextClientSide;
                    dlg.OnCloseCancel = () =>
                    {
                        labelrenderer.SetNewText(text, color);
                        (api as ICoreClientAPI).Network.SendBlockEntityPacket(pos.X, pos.Y, pos.Z, (int)EnumSignPacketId.CancelEdit, null);
                    };
                    dlg.TryOpen();
                }
            }


            if (packetid == (int)EnumSignPacketId.NowText)
            {
                using (MemoryStream ms = new MemoryStream(data))
                {
                    BinaryReader reader = new BinaryReader(ms);
                    text = reader.ReadString();
                    if (text == null)
                    {
                        text = "";
                    }

                    if (labelrenderer != null)
                    {
                        labelrenderer.SetNewText(text, color);
                    }
                }
            }

            base.OnReceivedServerPacket(packetid, data);
        }
示例#2
0
        internal void UpdateVoxel(IPlayer byPlayer, ItemSlot itemslot, Vec3i voxelPos, BlockFacing facing, bool isBreak)
        {
            int mode = ChiselMode(byPlayer);

            if (mode == 5)
            {
                IClientWorldAccessor clientWorld = (IClientWorldAccessor)api.World;

                string prevName = blockName;
                GuiDialogBlockEntityTextInput dlg = new GuiDialogBlockEntityTextInput(Lang.Get("Block name"), pos, blockName, api as ICoreClientAPI);
                dlg.OnTextChanged = (text) => blockName = text;
                dlg.OnCloseCancel = () => blockName = prevName;
                dlg.TryOpen();
            }

            bool wasChanged = false;

            if (mode == 4)
            {
                RotateModel(byPlayer, isBreak);
                wasChanged = true;
            }
            else
            {
                int   size     = ChiselSize(byPlayer);
                Vec3i addAtPos = voxelPos.Clone().Add(size * facing.Normali.X, size * facing.Normali.Y, size * facing.Normali.Z);

                if (isBreak)
                {
                    wasChanged = SetVoxel(voxelPos, false, byPlayer);
                }
                else
                {
                    if (addAtPos.X >= 0 && addAtPos.X < 16 && addAtPos.Y >= 0 && addAtPos.Y < 16 && addAtPos.Z >= 0 && addAtPos.Z < 16)
                    {
                        wasChanged = SetVoxel(addAtPos, true, byPlayer);
                    }
                }
            }


            if (!wasChanged)
            {
                return;
            }

            if (api.Side == EnumAppSide.Client)
            {
                RegenMesh();
            }

            RegenSelectionBoxes(byPlayer);
            MarkDirty(true);

            // Send a custom network packet for server side, because
            // serverside blockselection index is inaccurate
            if (api.Side == EnumAppSide.Client)
            {
                SendUseOverPacket(byPlayer, voxelPos, facing, isBreak);
            }

            double posx = pos.X + voxelPos.X / 16f;
            double posy = pos.Y + voxelPos.Y / 16f;
            double posz = pos.Z + voxelPos.Z / 16f;

            api.World.PlaySoundAt(new AssetLocation("sounds/player/knap" + (api.World.Rand.Next(2) > 0 ? 1 : 2)), posx, posy, posz, byPlayer, true, 12, 1);

            if (byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)
            {
                itemslot.Itemstack?.Collectible.DamageItem(api.World, byPlayer.Entity, itemslot);
            }


            if (VoxelCuboids.Count == 0)
            {
                api.World.BlockAccessor.SetBlock(0, pos);
                return;
            }
        }
示例#3
0
        internal void UpdateVoxel(IPlayer byPlayer, ItemSlot itemslot, Vec3i voxelPos, BlockFacing facing, bool isBreak)
        {
            if (!Api.World.Claims.TryAccess(byPlayer, Pos, EnumBlockAccessFlags.Use))
            {
                MarkDirty(true, byPlayer);
                return;
            }


            EnumChiselMode mode = GetChiselMode(byPlayer);

            bool wasChanged = false;

            byte[] lightHsv = this.LightHsv;

            switch (mode)
            {
            case EnumChiselMode.Rename:
                IClientWorldAccessor clientWorld = (IClientWorldAccessor)Api.World;

                string prevName = BlockName;
                GuiDialogBlockEntityTextInput dlg = new GuiDialogBlockEntityTextInput(Lang.Get("Block name"), Pos, BlockName, Api as ICoreClientAPI, 500);
                dlg.OnTextChanged = (text) => BlockName = text;
                dlg.OnCloseCancel = () => BlockName = prevName;
                dlg.TryOpen();
                break;

            case EnumChiselMode.Flip:
                FlipVoxels(Block.SuggestedHVOrientation(byPlayer, new BlockSelection()
                {
                    Position = Pos.Copy(), HitPosition = new Vec3d(voxelPos.X / 16.0, voxelPos.Y / 16.0, voxelPos.Z / 16.0)
                })[0]);
                wasChanged = true;
                break;

            case EnumChiselMode.Rotate:
                RotateModel(isBreak ? 90 : -90, null);
                wasChanged = true;
                break;


            default:
                int   size     = GetChiselSize(byPlayer);
                Vec3i addAtPos = voxelPos.Clone().Add(size * facing.Normali.X, size * facing.Normali.Y, size * facing.Normali.Z);

                if (isBreak)
                {
                    wasChanged = SetVoxel(voxelPos, false, byPlayer, nowmaterialIndex);
                }
                else
                {
                    if (addAtPos.X >= 0 && addAtPos.X < 16 && addAtPos.Y >= 0 && addAtPos.Y < 16 && addAtPos.Z >= 0 && addAtPos.Z < 16)
                    {
                        wasChanged = SetVoxel(addAtPos, true, byPlayer, nowmaterialIndex);
                    }
                }

                break;
            }


            if (!wasChanged)
            {
                return;
            }

            if (Api.Side == EnumAppSide.Client)
            {
                RegenMesh();
            }

            RegenSelectionBoxes(byPlayer);
            MarkDirty(true, byPlayer);

            // Send a custom network packet for server side, because
            // serverside blockselection index is inaccurate
            if (Api.Side == EnumAppSide.Client)
            {
                SendUseOverPacket(byPlayer, voxelPos, facing, isBreak);
            }

            double posx = Pos.X + voxelPos.X / 16f;
            double posy = Pos.Y + voxelPos.Y / 16f;
            double posz = Pos.Z + voxelPos.Z / 16f;

            Api.World.PlaySoundAt(new AssetLocation("sounds/player/knap" + (Api.World.Rand.Next(2) > 0 ? 1 : 2)), posx, posy, posz, byPlayer, true, 12, 1);

            if (byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative && Api.World.Rand.Next(3) == 0)
            {
                itemslot.Itemstack?.Collectible.DamageItem(Api.World, byPlayer.Entity, itemslot);
            }


            if (VoxelCuboids.Count == 0)
            {
                Api.World.BlockAccessor.SetBlock(0, Pos);
                Api.World.BlockAccessor.RemoveBlockLight(LightHsv, Pos);
                return;
            }
        }