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); } }
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; }
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); }
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); } }
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); } }
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); } } } } }