示例#1
0
        public static void Postfix(BlockEntityChisel __instance)
        {
            try
            {
                ChiselPlusPropertyAccessor accessor = new ChiselPlusPropertyAccessor(__instance.Api);

                EnumChiselPlusMesh setMesh = accessor.Properties[__instance.Pos].Mesh;

                if (setMesh != EnumChiselPlusMesh.none && __instance.MaterialIds != null)
                {
                    Vec3f rot = accessor.Properties[__instance.Pos].Rotation;

                    ICoreClientAPI capi = (__instance.Api as ICoreClientAPI);
                    string         name = Enum.GetName(typeof(EnumChiselPlusMesh), setMesh);
                    if (name == null)
                    {
                        return;
                    }
                    string code = string.Format("chiselplus:genericblocks-{0}", name);

                    capi.Tesselator.TesselateBlock(capi.World.BlockAccessor.GetBlock(new AssetLocation(code)), out MeshData mesh);

                    TextureSource            texSource = new TextureSource(__instance.Api.World as ClientMain, capi.BlockTextureAtlas.Size, capi.World.BlockAccessor.GetBlock(__instance.MaterialIds.FirstOrDefault()));
                    Dictionary <string, int> textureCodeToIdMapping = AccessTools.Field(typeof(TextureSource), "textureCodeToIdMapping").GetValue(texSource) as Dictionary <string, int>;

                    mesh.SetTexPos(texSource[textureCodeToIdMapping.FirstOrDefault().Key]);
                    mesh.Rotate(new Vec3f(0.5f, 0.5f, 0.5f), GameMath.DEG2RAD * rot.X, GameMath.DEG2RAD * rot.Y, GameMath.DEG2RAD * rot.Z);
                    __instance.Mesh = mesh;
                }
            }
            catch (Exception)
            {
            }
        }
示例#2
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
        {
            if (blockSel?.BlockEntity(api) is BlockEntityChisel)
            {
                handling = EnumHandHandling.PreventDefault;
                BlockEntityChisel entityChisel  = ((BlockEntityChisel)blockSel.BlockEntity(api));
                ITreeAttribute    blueprintTree = slot?.Itemstack?.Attributes;
                ITreeAttribute    dummy         = blueprintTree.Clone();
                entityChisel.ToTreeAttributes(dummy);
                blueprintTree["materials"] = dummy["materials"];

                if (byEntity.Controls.Sneak)
                {
                    blueprintTree["cuboids"] = new IntArrayAttribute();
                    entityChisel.ToTreeAttributes(blueprintTree);
                    slot.MarkDirty();
                }
                else if (blueprintTree["cuboids"] != null)
                {
                    entityChisel.FromTreeAtributes(blueprintTree, api.World);
                }
                if (api.Side.IsClient())
                {
                    entityChisel.RegenMesh();
                }
            }
            base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling);
        }
示例#3
0
        public override void StartServerSide(ICoreServerAPI Api)
        {
            sapi = Api;
            sapi.RegisterCommand("setmaterial", "Set the material of currently looked at chiseled block", "[block code]", (player, groupId, args) =>
            {
                BlockPos pos          = player.CurrentBlockSelection.Position;
                BlockEntityChisel bet = sapi.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityChisel;
                Block block           = sapi.World.GetBlock(new AssetLocation(args.PopWord()));

                if (bet == null)
                {
                    player.SendMessage(groupId, "Not looking at a chiseled block. Must look at one to set its material", EnumChatType.CommandError);
                    return;
                }
                if (block == null)
                {
                    player.SendMessage(groupId, "Did not supply a valid block code", EnumChatType.CommandError);
                    return;
                }

                bet.MaterialIds = new int[] { block.Id };
                bet.MarkDirty(true);
                player.SendMessage(groupId, "Material set.", EnumChatType.CommandError);
            }
                                 , Privilege.controlserver);
        }
        private void onSetChiselMat(IServerPlayer player, int groupId, CmdArgs args)
        {
            BlockPos pos = player.CurrentBlockSelection?.Position;

            if (pos == null)
            {
                player.SendMessage(groupId, "Look at a block first", EnumChatType.CommandError);
                return;
            }

            BlockEntityChisel bechisel = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityChisel;

            if (bechisel == null)
            {
                player.SendMessage(groupId, "Not looking at a chiseled block", EnumChatType.CommandError);
                return;
            }

            Block block = player.InventoryManager?.ActiveHotbarSlot?.Itemstack?.Block;

            if (block == null)
            {
                player.SendMessage(groupId, "You need a block in your active hand", EnumChatType.CommandError);
                return;
            }

            for (int i = 0; i < bechisel.MaterialIds.Length; i++)
            {
                bechisel.MaterialIds[i] = block.Id;
            }

            bechisel.MarkDirty(true);
            player.SendMessage(groupId, "Ok material set", EnumChatType.CommandError);
            return;
        }
示例#5
0
        public static void Prefix(BlockEntityChisel __instance, ref ITreeAttribute tree)
        {
            ChiselPlusPropertyAccessor accessor = new ChiselPlusPropertyAccessor(__instance.Api);

            var store = accessor.Properties[__instance.Pos];

            tree.SetInt("chiselplusmesh", (int)store.Mesh);
            tree.SetFloat("chiselplusRotX", store.Rotation.X);
            tree.SetFloat("chiselplusRotY", store.Rotation.Y);
            tree.SetFloat("chiselplusRotZ", store.Rotation.Z);
        }
        private MeshRef CreateModel(ItemStack forStack)
        {
            ITreeAttribute tree = forStack.Attributes;

            ushort[]    materials    = (tree["materials"] as IntArrayAttribute).AsUShort;
            List <uint> voxelCuboids = new List <uint>((tree["cuboids"] as IntArrayAttribute).AsUint);

            MeshData mesh = BlockEntityChisel.CreateMesh(capi, voxelCuboids, materials);

            mesh.Rgba2 = null;

            return(capi.Render.UploadMesh(mesh));
        }
示例#7
0
        private MeshRef CreateModel(ItemStack forStack)
        {
            ITreeAttribute tree = forStack.Attributes;

            int[]       materials    = BlockEntityChisel.MaterialIdsFromAttributes(tree, capi.World);
            uint[]      cuboids      = (tree["cuboids"] as IntArrayAttribute)?.AsUint;
            List <uint> voxelCuboids = cuboids == null ? new List <uint>() : new List <uint>(cuboids);

            MeshData mesh = BlockEntityChisel.CreateMesh(capi, voxelCuboids, materials);

            mesh.Rgba2 = null;

            return(capi.Render.UploadMesh(mesh));
        }
示例#8
0
        public static void Postfix(BlockEntityChisel __instance, IPlayer byPlayer, BlockSelection blockSel, bool isBreak)
        {
            if (!__instance.Api.World.Claims.TryAccess(byPlayer, __instance.Pos, EnumBlockAccessFlags.Use))
            {
                __instance.MarkDirty(true);
                return;
            }

            ChiselPlusPropertyAccessor accessor = new ChiselPlusPropertyAccessor(__instance.Api);

            if (!accessor.Properties.ContainsKey(__instance.Pos))
            {
                accessor.Properties[__instance.Pos] = new ChiselPlusProperties();
            }

            EnumChiselPlusMode mode = (EnumChiselPlusMode)__instance.ChiselMode(byPlayer);

            if (__instance.Api.Side.IsServer())
            {
                switch (mode)
                {
                case EnumChiselPlusMode.ChiselPlus:
                    if (isBreak)
                    {
                        EnumChiselPlusMesh mesh = accessor.Properties[__instance.Pos].Mesh;
                        accessor.Properties[__instance.Pos].Mesh = mesh > EnumChiselPlusMesh.slopehalf ? EnumChiselPlusMesh.none : mesh + 1;
                    }
                    else
                    {
                        bool success;

                        accessor.Properties[__instance.Pos].Rotation.Z += (success = byPlayer.Entity.Controls.Sneak) ? 45 : 0;
                        accessor.Properties[__instance.Pos].Rotation.X += (success = byPlayer.Entity.Controls.Sprint && !success) ? 45 : 0;
                        accessor.Properties[__instance.Pos].Rotation.Y += !success ? 45 : 0;
                    }
                    __instance.MarkDirty();
                    break;

                default:
                    break;
                }
            }

            if (__instance.Api.Side.IsClient())
            {
                __instance.RegenMesh();
                __instance.MarkDirty(true);
            }
        }
示例#9
0
        public override void StartServerSide(ICoreServerAPI Api)
        {
            sapi = Api;
            sapi.Event.PlayerJoin += (player) =>
            {
                ServerMain server       = (sapi.World as ServerMain);
                var        PlayerGroups = server.GetField <ServerMain, ServerSystem[]>("Systems").OfType <ServerySystemPlayerGroups>().Single();
                var        serverAdmin  = (object)(new ServerPlayer(server, ServerWorldPlayerData.CreateNew("!!!ImmersionAdmin", "!!!ImmersionAdmin")));
                if (!PlayerGroups.PlayerGroupsByUid.Any(g => g.Value.Name == "suplayer"))
                {
                    PlayerGroups.CallMethod("CmdCreategroup", (object)(serverAdmin), (object)0, new CmdArgs("suplayer"));
                }
                var group = PlayerGroups.PlayerGroupsByUid.Where(t => t.Value.Name == "suplayer").Single().Value;
                if (player.Privileges.Contains(Privilege.ban))
                {
                    server.PlayerDataManager.PlayerDataByUid[player.PlayerUID].JoinGroup(group, EnumPlayerGroupMemberShip.Op);
                }
                else
                {
                    server.PlayerDataManager.PlayerDataByUid[player.PlayerUID].JoinGroup(group, EnumPlayerGroupMemberShip.Member);
                }

                server.PlayerDataManager.playerDataDirty   = true;
                server.PlayerDataManager.playerGroupsDirty = true;
            };

            sapi.RegisterCommand("setmaterial", "Set the material of currently looked at chiseled block", "[block code]", (player, groupId, args) =>
            {
                BlockPos pos          = player.CurrentBlockSelection.Position;
                BlockEntityChisel bet = sapi.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityChisel;
                Block block           = sapi.World.GetBlock(new AssetLocation(args.PopWord()));

                if (bet == null)
                {
                    player.SendMessage(groupId, "Not looking at a chiseled block. Must look at one to set its material", EnumChatType.CommandError);
                    return;
                }
                if (block == null)
                {
                    player.SendMessage(groupId, "Did not supply a valid block code", EnumChatType.CommandError);
                    return;
                }

                bet.MaterialIds = new int[] { block.Id };
                bet.MarkDirty(true);
                player.SendMessage(groupId, "Material set.", EnumChatType.CommandError);
            }
                                 , Privilege.controlserver);
        }
示例#10
0
        public static void Postfix(BlockEntityChisel __instance, ICoreAPI api)
        {
            ChiselPlusPropertyAccessor accessor = new ChiselPlusPropertyAccessor(api);

            if (!accessor.Properties.ContainsKey(__instance.Pos))
            {
                accessor.Properties[__instance.Pos] = new ChiselPlusProperties();
            }

            if (api.Side.IsClient())
            {
                __instance.RegenMesh();
                __instance.MarkDirty(true);
            }
        }
示例#11
0
        public static void Postfix(BlockEntityChisel __instance, ref ITreeAttribute tree, ref IWorldAccessor worldAccessForResolve)
        {
            ChiselPlusPropertyAccessor accessor = new ChiselPlusPropertyAccessor(worldAccessForResolve.Api);

            if (!accessor.Properties.ContainsKey(__instance.Pos))
            {
                accessor.Properties[__instance.Pos] = new ChiselPlusProperties();
            }

            accessor.Properties[__instance.Pos].Mesh       = (EnumChiselPlusMesh)(tree.TryGetInt("chiselplusmesh") ?? -1);
            accessor.Properties[__instance.Pos].Rotation.X = tree.TryGetFloat("chiselplusRotX") ?? 0.0f;
            accessor.Properties[__instance.Pos].Rotation.Y = tree.TryGetFloat("chiselplusRotY") ?? 0.0f;
            accessor.Properties[__instance.Pos].Rotation.Z = tree.TryGetFloat("chiselplusRotZ") ?? 0.0f;

            if (__instance.Api?.Side.IsClient() ?? false)
            {
                __instance.MarkDirty(true);
            }
        }
示例#12
0
        private void onUpgradeCmd(IServerPlayer player, int groupId, CmdArgs args)
        {
            var wmod = api.ModLoader.GetModSystem <WorldEdit.WorldEdit>();

            var workspace = wmod.GetWorkSpace(player.PlayerUID);

            if (workspace == null || workspace.StartMarker == null || workspace.EndMarker == null)
            {
                player.SendMessage(groupId, "Select an area with worldedit first", EnumChatType.CommandError);
                return;
            }

            int      startx = Math.Min(workspace.StartMarker.X, workspace.EndMarker.X);
            int      endx   = Math.Max(workspace.StartMarker.X, workspace.EndMarker.X);
            int      starty = Math.Min(workspace.StartMarker.Y, workspace.EndMarker.Y);
            int      endy   = Math.Max(workspace.StartMarker.Y, workspace.EndMarker.Y);
            int      startz = Math.Min(workspace.StartMarker.Z, workspace.EndMarker.Z);
            int      endZ   = Math.Max(workspace.StartMarker.Z, workspace.EndMarker.Z);
            BlockPos pos    = new BlockPos();

            Dictionary <string, Block> blocksByName = new Dictionary <string, Block>();

            foreach (var block in api.World.Blocks)
            {
                if (block.IsMissing || block.Code == null)
                {
                    continue;
                }
                blocksByName[block.GetHeldItemName(new ItemStack(block))] = block;
            }

            int graniteBlockId = api.World.GetBlock(new AssetLocation("rock-granite")).Id;

            for (int x = startx; x < endx; x++)
            {
                for (int y = starty; y < endy; y++)
                {
                    for (int z = startz; z < endZ; z++)
                    {
                        pos.Set(x, y, z);

                        Block block = api.World.BlockAccessor.GetBlock(x, y, z);
                        if (block is BlockChisel)
                        {
                            BlockEntityChisel bechisel = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityChisel;
                            if (bechisel.MaterialIds != null && bechisel.MaterialIds.Length > 0 && bechisel.MaterialIds[0] == graniteBlockId)
                            {
                                Block matblock = null;
                                if (blocksByName.TryGetValue(bechisel.BlockName, out matblock))
                                {
                                    bechisel.MaterialIds[0] = matblock.Id;
                                    bechisel.MarkDirty(true);
                                }
                            }
                        }

                        if (block is BlockPlantContainer)
                        {
                            FixOldPlantContainers(pos);
                        }
                    }
                }
            }
        }