public override void StartServerSide(ICoreServerAPI api) { sapi = api; api.Event.SaveGameLoaded += OnSaveGameLoaded; }
public BackwardCompatHandler(ICoreServerAPI api) => api.Event.OnEntitySpawn += OnEntitySpawn;
public static MapLayerBase GetLandformMapGen(long seed, NoiseClimate climateNoise, ICoreServerAPI api) { MapLayerBase landforms = new MapLayerLandforms(seed + 12, climateNoise, api); landforms.DebugDrawBitmap(DebugDrawMode.LandformRGB, 0, 0, "Landforms 1 - Wobble Landforms"); return(landforms); }
private void OnGameTick(float dt) { if (Data.EntityCodes == null || Data.EntityCodes.Length == 0) { lastSpawnTotalHours = api.World.Calendar.TotalHours; return; } ICoreServerAPI sapi = api as ICoreServerAPI; int rnd = sapi.World.Rand.Next(Data.EntityCodes.Length); EntityProperties type = api.World.GetEntityType(new AssetLocation(Data.EntityCodes[rnd])); if (lastSpawnTotalHours + Data.InGameHourInterval > api.World.Calendar.TotalHours && Data.InitialSpawnQuantity <= 0) { return; } if (!IsAreaLoaded()) { return; } if (Data.SpawnOnlyAfterImport && !Data.WasImported) { return; } if (type == null) { return; } for (int i = 0; i < spawnedEntities.Count; i++) { if (!sapi.World.LoadedEntities.ContainsKey(spawnedEntities[i])) { spawnedEntities.RemoveAt(i); i--; } } if (spawnedEntities.Count >= Data.MaxCount) { lastSpawnTotalHours = api.World.Calendar.TotalHours; return; } Cuboidf collisionBox = new Cuboidf() { X1 = -type.HitBoxSize.X / 2, Z1 = -type.HitBoxSize.X / 2, X2 = type.HitBoxSize.X / 2, Z2 = type.HitBoxSize.X / 2, Y2 = type.HitBoxSize.Y }.OmniNotDownGrowBy(0.1f); int q = Data.GroupSize; while (q-- > 0) { Vec3d spawnPos = new Vec3d(); for (int tries = 0; tries < 15; tries++) { spawnPos.Set(pos).Add( 0.5 + Data.SpawnArea.MinX + api.World.Rand.NextDouble() * Data.SpawnArea.SizeX, Data.SpawnArea.MinY + api.World.Rand.NextDouble() * Data.SpawnArea.SizeY, 0.5 + Data.SpawnArea.MinZ + api.World.Rand.NextDouble() * Data.SpawnArea.SizeZ ); if (!collisionTester.IsColliding(api.World.BlockAccessor, collisionBox, spawnPos, false)) { long herdid = sapi.WorldManager.GetNextHerdId(); DoSpawn(type, spawnPos, herdid); lastSpawnTotalHours = api.World.Calendar.TotalHours; if (Data.InitialQuantitySpawned > 0) { Data.InitialQuantitySpawned--; } // Self destruct, if configured so if (Data.RemoveAfterSpawnCount > 0) { Data.RemoveAfterSpawnCount--; if (Data.RemoveAfterSpawnCount == 0) { api.World.BlockAccessor.SetBlock(0, pos); } } return; } } } }
public TreeGeneratorsUtil(ICoreServerAPI api) { sapi = api; }
internal void setApi(ICoreServerAPI api) { this.api = api; blockAccessor = api.World.BlockAccessor; }
public void Init(ICoreServerAPI api, BlockLayerConfig config, LCGRandom rand) { this.rand = rand; totalWeight = 0; for (int i = 0; i < Schematics.Length; i++) { List <BlockSchematicStructure> schematics = new List <BlockSchematicStructure>(); string error = ""; IAsset[] assets; VillageSchematic schem = Schematics[i]; totalWeight += schem.Weight; if (schem.Path.EndsWith("*")) { assets = api.Assets.GetMany("worldgen/schematics/" + schem.Path.Substring(0, schem.Path.Length - 1)).ToArray(); } else { assets = new IAsset[] { api.Assets.Get("worldgen/schematics/" + Schematics[i].Path + ".json") }; } for (int j = 0; j < assets.Length; j++) { IAsset asset = assets[j]; BlockSchematicStructure schematic = asset.ToObject <BlockSchematicStructure>(); if (schematic == null) { api.World.Logger.Warning("Could not load {0}: {1}", Schematics[i], error); continue; } schematic.FromFileName = asset.Name; BlockSchematicStructure[] rotations = new BlockSchematicStructure[4]; rotations[0] = schematic; for (int k = 0; k < 4; k++) { if (k > 0) { rotations[k] = rotations[0].Clone(); rotations[k].TransformWhilePacked(api.World, EnumOrigin.BottomCenter, k * 90); } rotations[k].blockLayerConfig = config; rotations[k].Init(api.World.BlockAccessor); rotations[k].LoadMetaInformationAndValidate(api.World.BlockAccessor, api.World, schematic.FromFileName); } schematics.AddRange(rotations); } schem.Structures = schematics.ToArray(); } if (ReplaceWithBlocklayers != null) { replaceblockids = new int[ReplaceWithBlocklayers.Length]; for (int i = 0; i < replaceblockids.Length; i++) { Block block = api.World.GetBlock(ReplaceWithBlocklayers[i]); if (block == null) { throw new Exception(string.Format("Schematic with code {0} has replace block layer {1} defined, but no such block found!", Code, ReplaceWithBlocklayers[i])); } else { replaceblockids[i] = (ushort)block.Id; } } } }
public override void StartServerSide(ICoreServerAPI api) { api.Server.Logger.EntryAdded += OnServerLogEntry; }
public override void StartServerSide(ICoreServerAPI api) { sapi = api; }
public AiTaskBellAlarm(EntityAgent entity) : base(entity) { sapi = entity.World.Api as ICoreServerAPI; }
public override void StartServerSide(ICoreServerAPI api) { api.Event.ServerRunPhase(EnumServerRunPhase.LoadGamePre, addReinforcementBehavior); }
public static void RegisterMetalAlloy(this ICoreServerAPI api, AlloyRecipe r) { api.ModLoader.GetModSystem <RecipeRegistrySystem>().RegisterMetalAlloy(r); }
public static void RegisterBarrelRecipe(this ICoreServerAPI api, BarrelRecipe r) { api.ModLoader.GetModSystem <RecipeRegistrySystem>().RegisterBarrelRecipe(r); }
public static void RegisterClayFormingRecipe(this ICoreServerAPI api, ClayFormingRecipe r) { api.ModLoader.GetModSystem <RecipeRegistrySystem>().RegisterClayFormingRecipe(r); }
public override void StartServerSide(ICoreServerAPI api) { base.StartServerSide(api); api.Event.PlayerJoin += Event_PlayerJoin; }
public CheckDecayThread(ICoreServerAPI sapi) { this.sapi = sapi; }
public override void StartServerSide(ICoreServerAPI Api) { sChannel = Api.Network.RegisterChannel("swapPairs").RegisterMessageType <SwapMessage>(); Api.Event.PlayerJoin += PlayerJoin; }
public void Init(ICoreServerAPI api, RockStrataConfig rockstrata, Random rnd) { ResolveBlockIds(api, rockstrata); }
public override void StartServerSide(ICoreServerAPI api) { this.sapi = api; api.Event.RegisterGameTickListener(OnServerTick, 32); }
public override void StartServerSide(ICoreServerAPI api) { this.api = api; worldProperties = new Dictionary <AssetLocation, StandardWorldProperty>(); foreach (var entry in api.Assets.GetMany <StandardWorldProperty>(api.Server.Logger, "worldproperties/")) { AssetLocation loc = entry.Key.Clone(); loc.Path = loc.Path.Replace("worldproperties/", ""); loc.RemoveEnding(); worldProperties.Add(loc, entry.Value); } blockShapes = api.Assets.GetMany <Shape>(api.Server.Logger, "shapes/block/"); blockTypes = new Dictionary <AssetLocation, BlockType>(); foreach (KeyValuePair <AssetLocation, JObject> entry in api.Assets.GetMany <JObject>(api.Server.Logger, "blocktypes/")) { JToken property = null; JObject blockTypeObject = entry.Value; AssetLocation location = null; try { location = blockTypeObject.GetValue("code").ToObject <AssetLocation>(); location.Domain = entry.Key.Domain; } catch (Exception e) { api.World.Logger.Error("Block type {0} has no valid code property. Will ignore. Exception thrown: {1}", entry.Key, e); continue; } blockTypes.Add(entry.Key, new BlockType() { Code = location, VariantGroups = blockTypeObject.TryGetValue("variantgroups", out property) ? property.ToObject <RegistryObjectVariantGroup[]>() : null, Enabled = blockTypeObject.TryGetValue("enabled", out property) ? property.ToObject <bool>() : true, jsonObject = blockTypeObject }); } itemTypes = new Dictionary <AssetLocation, ItemType>(); foreach (KeyValuePair <AssetLocation, JObject> entry in api.Assets.GetMany <JObject>(api.Server.Logger, "itemtypes/")) { JToken property = null; JObject itemTypeObject = entry.Value; AssetLocation location = itemTypeObject.GetValue("code").ToObject <AssetLocation>(); location.Domain = entry.Key.Domain; itemTypes.Add(entry.Key, new ItemType() { Code = location, VariantGroups = itemTypeObject.TryGetValue("variantgroups", out property) ? property.ToObject <RegistryObjectVariantGroup[]>() : null, Enabled = itemTypeObject.TryGetValue("enabled", out property) ? property.ToObject <bool>() : true, jsonObject = itemTypeObject }); } entityTypes = new Dictionary <AssetLocation, EntityType>(); foreach (KeyValuePair <AssetLocation, JObject> entry in api.Assets.GetMany <JObject>(api.Server.Logger, "entities/")) { JToken property = null; JObject blockTypeObject = entry.Value; AssetLocation location = null; try { location = blockTypeObject.GetValue("code").ToObject <AssetLocation>(); location.Domain = entry.Key.Domain; } catch (Exception e) { api.World.Logger.Error("Entity type {0} has no valid code property. Will ignore. Exception thrown: {1}", entry.Key, e); continue; } try { entityTypes.Add(entry.Key, new EntityType() { Code = location, VariantGroups = blockTypeObject.TryGetValue("variantgroups", out property) ? property.ToObject <RegistryObjectVariantGroup[]>() : null, Enabled = blockTypeObject.TryGetValue("enabled", out property) ? property.ToObject <bool>() : true, jsonObject = blockTypeObject }); } catch (Exception e) { api.World.Logger.Error("Entity type {0} could not be loaded. Will ignore. Exception thrown: {1}", entry.Key, e); continue; } } worldPropertiesVariants = new Dictionary <AssetLocation, BlockVariant[]>(); foreach (var val in worldProperties) { if (val.Value == null) { continue; } WorldPropertyVariant[] variants = val.Value.Variants; if (variants == null) { continue; } if (val.Value.Code == null) { api.Server.LogError("Error in worldproperties {0}, not code set", val.Key); return; } worldPropertiesVariants[val.Value.Code] = new BlockVariant[variants.Length]; for (int i = 0; i < variants.Length; i++) { worldPropertiesVariants[val.Value.Code][i] = new BlockVariant() { Code = variants[i].Code.Path }; } } LoadEntities(); LoadItems(); LoadBlocks(); api.Server.LogNotification("BlockLoader: Entities, Blocks and Items loaded"); }
protected AbstractTimerEvent(ICoreServerAPI api) { }
public override void StartServerSide(ICoreServerAPI api) { api.Network .RegisterChannel("loggerextensions") .RegisterMessageType(typeof(NetworkSendCurrentMessage)); }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { BlockPos blockPos = blockSel.Position; BEOmokTableTop beOmok = (BEOmokTableTop)api.World.BlockAccessor.GetBlockEntity(blockPos); // Continue if the clicked spot is an available space if (beOmok == null || !IsViableSpace(beOmok, blockSel, out int pieceX, out int pieceZ)) { return(true); } // Determine next piece to be placed bool whitesTurn = beOmok.WhitesTurn; int piecesPlayed = beOmok.PiecesPlayed(); // If two player, determine who's playing and whose turn it is before placing a piece if (beOmok.IsTwoPlayer) { // Assign ID if it's a player's first turn if (piecesPlayed == 0) // Assign first player { beOmok.FirstPlayerID = byPlayer.PlayerUID; } else if (piecesPlayed == 1) // Assign second player // If second player is a new player, assign second player, otherwise return { if (byPlayer.PlayerUID != beOmok.FirstPlayerID) { beOmok.SecondPlayerID = byPlayer.PlayerUID; } else { return(true); } } // Return if it's not the player's turn if (!whitesTurn && byPlayer.PlayerUID != beOmok.FirstPlayerID) { return(true); } if (whitesTurn && byPlayer.PlayerUID != beOmok.SecondPlayerID) { return(true); } } if (whitesTurn) { beOmok.PlaceWhitePiece(pieceX, pieceZ); } else { beOmok.PlaceBlackPiece(pieceX, pieceZ); } // Victory Condition Check string victoryText = ""; if (!beOmok.GameIsOver) { victoryText = beOmok.CheckVictoryConditions(); } // Play piece setting sound int random = new Random().Next(1, 3); AssetLocation placeSound = new AssetLocation("game:sounds/block/loosestone" + random); world.PlaySoundAt(placeSound, blockPos.X, blockPos.Y, blockPos.Z, byPlayer, true, 10, 1); if (world.Side == EnumAppSide.Server) { ICoreServerAPI sAPI = (ICoreServerAPI)api; if (victoryText != "") { foreach (IPlayer nearbyPlayer in api.World.GetPlayersAround(blockSel.Position.ToVec3d(), 10, 10)) { sAPI.SendMessage(nearbyPlayer, 0, victoryText, EnumChatType.OwnMessage); } } } beOmok.MarkDirty(true); beOmok.UpdateClients(); return(true); }
public DeathHandler(ICoreServerAPI api) => api.Event.PlayerDeath += OnPlayerDeath;
public override void StartServerSide(ICoreServerAPI Api) { sapi = Api; sChannel = sapi.Network.RegisterChannel("remapperchannel").RegisterMessageType(typeof(Message)); sapi.RegisterCommand("remapper", "Remapper", "", (p, g, a) => { string arg = a.PopWord(); NLMissing nLMissing = Api.ModLoader.GetModSystem <NLMissing>(); switch (arg) { case "exportmissing": ExportMissing(p, g); break; case "exportmatches": string dl1 = a.PopWord(); bool DL1 = dl1 == "dl" ? true : false; ExportMatches(p, DL1); break; case "tryremap": if (canExecuteRemap) { canExecuteRemap = false; string dl = a.PopWord(); bool DL = dl == "dl" ? true : false; TryRemapMissing(p, DL); } break; case "frombuild": sChannel.SendPacket(new Message() { Assets = nLMissing.@object }, p); p.SendMessage(GlobalConstants.GeneralChatGroup, "Remapping from built in list...", EnumChatType.CommandError); break; case "loadfrombuild": MostLikely = JsonConvert.DeserializeObject <Dictionary <AssetLocation, AssetLocation> >(nLMissing.@object); p.SendMessage(GlobalConstants.GeneralChatGroup, "Okay, loaded list from build.", EnumChatType.CommandError); break; case "loadfromfile": ImportMatches(); p.SendMessage(GlobalConstants.GeneralChatGroup, "Okay, loaded list from file.", EnumChatType.CommandError); break; case "finddupes": List <AssetLocation> dupes = new List <AssetLocation>(); var duplicates = MostLikely.GroupBy(x => x.Value).Where(x => x.Count() > 1); foreach (var val in duplicates) { dupes.Add(val.Key); } using (TextWriter tW = new StreamWriter("dupes.json")) { tW.Write(JsonConvert.SerializeObject(dupes, Formatting.Indented)); tW.Close(); } p.SendMessage(GlobalConstants.GeneralChatGroup, "Okay, exported list of duplicate entries.", EnumChatType.CommandError); break; default: break; } }, Privilege.controlserver); }
/// <summary> /// Minor convenience method to save yourself the check for/cast to ICoreServerAPI in Start() /// </summary> /// <param name="api"></param> public virtual void StartServerSide(ICoreServerAPI api) { }
public ChildDepositGenerator(ICoreServerAPI api, DepositVariant variant, LCGRandom depositRand, NormalizedSimplexNoise noiseGen) : base(api, variant, depositRand, noiseGen) { }
public override void OnLoaded(ICoreAPI api) { ICoreServerAPI sapi = api as ICoreServerAPI; }
public override void StartServerSide(ICoreServerAPI api) { api.Server.Logger.AddListener(OnServerLogEntry); }
public override void StartServerSide(ICoreServerAPI api) { api.RegisterCommand("exptempplot", "Export a 1 year long temperatures at a 6 hour interval at this location", "", onPlot, Privilege.controlserver); }