protected override void InitializeMeteorParticles() { #region Meteor Particles Options MeteorParticles.GravityEffect = -0.01f; MeteorParticles.WindAffected = true; MeteorParticles.MinSize = 1.0f; MeteorParticles.MaxSize = 5.0f; MeteorParticles.SizeEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEAR, -2); MeteorParticles.MinQuantity = 4; MeteorParticles.AddQuantity = 25; MeteorParticles.LifeLength = 1.5f; MeteorParticles.addLifeLength = 0.5f; MeteorParticles.ShouldDieInLiquid = true; MeteorParticles.Color = ColorUtil.ColorFromRgba(255, 255, 255, Rand.Next(100, 255)); MeteorParticles.OpacityEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 255); MeteorParticles.BlueEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, Rand.Next(0, 150)); MeteorParticles.GreenEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, Rand.Next(150, 255)); MeteorParticles.RedEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 255); MeteorParticles.VertexFlags = Rand.Next(150, 255); MeteorParticles.ParticleModel = EnumParticleModel.Quad; #endregion UpdateMeteorParticles(); }
public void HighlightIncompleteParts(IWorldAccessor world, IPlayer player, BlockPos centerPos) { List <BlockPos> blocks = new List <BlockPos>(); List <int> colors = new List <int>(); for (int i = 0; i < TransformedOffsets.Count; i++) { Vec4i offset = TransformedOffsets[i]; Block block = world.BlockAccessor.GetBlock(centerPos.X + offset.X, centerPos.Y + offset.Y, centerPos.Z + offset.Z); AssetLocation desireBlockLoc = BlockCodes[offset.W]; if (!WildcardUtil.Match(BlockCodes[offset.W], block.Code)) { blocks.Add(new BlockPos(offset.X, offset.Y, offset.Z).Add(centerPos)); if (block.Id != 0) { colors.Add(ColorUtil.ColorFromRgba(215, 94, 94, 64)); } else { int col = world.SearchBlocks(desireBlockLoc)[0].GetColor(world.Api as ICoreClientAPI, centerPos); col &= ~(255 << 24); col |= 96 << 24; colors.Add(col); } } } world.HighlightBlocks(player, HighlightSlotId, blocks, colors); }
public override void OnHeldAttackStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { if (!byEntity.Controls.Sneak) { return; } handling = EnumHandHandling.PreventDefault; ITreeAttribute box = slot.Itemstack.Attributes.GetTreeAttribute("workArea"); //ITreeAttribute chest = slot.Itemstack.Attributes.GetTreeAttribute("workChest"); //ITreeAttribute barrel = slot.Itemstack.Attributes.GetTreeAttribute("workBarrel"); if (box != null) { BlockPos min = new Vec3d(box.GetDouble("x1"), box.GetDouble("y1"), box.GetDouble("z1")).AsBlockPos; BlockPos max = new Vec3d(box.GetDouble("x2"), box.GetDouble("y2") + 1, box.GetDouble("z2")).AsBlockPos; List <BlockPos> blocks = new List <BlockPos>() { min, max }; List <int> colors = new List <int>() { ColorUtil.ColorFromRgba(215, 94, 94, 64), ColorUtil.ColorFromRgba(215, 94, 94, 64) }; api.World.HighlightBlocks((byEntity as EntityPlayer)?.Player, 56, blocks, colors, EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Cube); api.World.RegisterCallback((dt) => api.World.HighlightBlocks((byEntity as EntityPlayer)?.Player, 56, new List <BlockPos>(), new List <int>()), 3000); } }
public void DebugParticles(Vec3d position, byte r, byte g, byte b, int quantity = 5) { #if DEBUG SimpleParticleProperties particles = new SimpleParticleProperties( quantity, quantity, ColorUtil.ColorFromRgba(b, g, r, 50), position, new Vec3d(position.X, position.Y + 1, position.Z), new Vec3f(-1, -1, -1), new Vec3f(1, 1, 1)); entity.World.SpawnParticles(particles); #endif }
static BECheeseCurdsBundle() { props = new SimpleParticleProperties( 0.3f, 1.3f, ColorUtil.ColorFromRgba(248, 243, 227, 255), new Vec3d(), new Vec3d(), new Vec3f(), new Vec3f(), 2f, 1f, 0.05f, 0.2f, EnumParticleModel.Quad ); }
private void OnEvery50Ms(float dt) { resistance = GameMath.Clamp(resistance + dt / (bebrake.Engaged ? 20 : -10), 0, 3); if (bebrake.Engaged && network != null && network.Speed > 0.1) { Api.World.SpawnParticles( network.Speed * 1.7f, ColorUtil.ColorFromRgba(60, 60, 60, 100), Position.ToVec3d().Add(0.1f, 0.5f, 0.1f), Position.ToVec3d().Add(0.8f, 0.3f, 0.8f), new Vec3f(-0.1f, 0.1f, -0.1f), new Vec3f(0.2f, 0.2f, 0.2f), 2, 0, 0.3f); } UpdateBreakSounds(); }
public override void StartServerSide(ICoreServerAPI api) { base.StartServerSide(api); AssetLocation sound = new AssetLocation("here", "sounds/partyhorn"); api.RegisterCommand("here", "spawns particles around the player", "", (IServerPlayer player, int groupId, CmdArgs args) => { EntityPlayer byEntity = player.Entity; byEntity.World.PlaySoundAt(sound, byEntity); Vec3d pos = byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight, 0); Random rand = new Random(); for (int i = 0; i < 100; i++) { Vec3d realPos = pos.AddCopy(-0.1 + rand.NextDouble() * 0.2, 0, -0.1 + rand.NextDouble() * 0.2); Vec3f velocity = new Vec3f(-0.2F + (float)rand.NextDouble() * 0.4F, 0.4F + (float)rand.NextDouble() * 2F, -0.2F + (float)rand.NextDouble() * 0.4F); byEntity.World.SpawnParticles(1, ColorUtil.ColorFromRgba(255, rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)), realPos, realPos, velocity, velocity, (float)rand.NextDouble() * 1 + 1, 0.01F, 1, EnumParticleModel.Cube); } }, Privilege.chat); }
private void SpawnMeteorParticles() { #region Meteor Particles Options meteorParticles.MinPos = this.entity.Pos.XYZ + new Vec3d(-this.entity.Properties.Client.Size / 2, -this.entity.Properties.Client.Size / 2, -this.entity.Properties.Client.Size / 2); meteorParticles.AddPos = new Vec3d(this.entity.Properties.Client.Size, this.entity.Properties.Client.Size, this.entity.Properties.Client.Size); meteorParticles.MinVelocity = new Vec3f(randTranslation.X * 0.1f, 0, randTranslation.Z * 0.1f); meteorParticles.GravityEffect = -0.01f; meteorParticles.WindAffected = true; meteorParticles.MinSize = 1.0f; meteorParticles.MaxSize = 5.0f; meteorParticles.SizeEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEAR, -2); meteorParticles.MinQuantity = 4; meteorParticles.AddQuantity = 25; meteorParticles.LifeLength = 1.5f; meteorParticles.addLifeLength = 0.5f; meteorParticles.ShouldDieInLiquid = true; meteorParticles.Color = ColorUtil.ColorFromRgba(255, 255, 255, rand.Next(100, 255)); meteorParticles.OpacityEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 255); meteorParticles.BlueEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, rand.Next(0, 150)); meteorParticles.GreenEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, rand.Next(150, 255)); meteorParticles.RedEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 255); meteorParticles.VertexFlags = rand.Next(150, 255); meteorParticles.ParticleModel = EnumParticleModel.Quad; #endregion this.entity.World.SpawnParticles(meteorParticles); }
private void InitializeSmokeParticles() { smokeParticles = new SimpleParticleProperties { MinPos = new Vec3d(Pos.X, Pos.Y, Pos.Z), AddPos = new Vec3d(1, 1, 1), MinSize = 0.3f, MaxSize = 1.5f, SizeEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARINCREASE, 0.5f), MinQuantity = 0.15f, LifeLength = 0.6f, addLifeLength = 2.5f, ShouldDieInLiquid = true, WithTerrainCollision = true, Color = ColorUtil.ColorFromRgba(10, 10, 12, 255), RedEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARINCREASE, 50), GreenEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARINCREASE, 50), BlueEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARINCREASE, 52), OpacityEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 255), GravityEffect = -0.1f, WindAffected = true, WindAffectednes = 0.7f, RandomVelocityChange = true, ParticleModel = EnumParticleModel.Quad, Async = true }; }
private void InitializeFireParticles() { fireCubeParticles = new SimpleParticleProperties { MinPos = new Vec3d(Pos.X, Pos.Y, Pos.Z), AddPos = new Vec3d(1, 1, 1), MinSize = 0.2f, MaxSize = 0.5f, SizeEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 0.2f), Color = ColorUtil.ColorFromRgba(255, 255, 255, 255), OpacityEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 255), BlueEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, rand.Next(0, 150)), GreenEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, rand.Next(150, 255)), RedEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 255), MinQuantity = 0.05f, LifeLength = 0.4f, addLifeLength = 1.0f, ShouldDieInLiquid = true, WithTerrainCollision = true, MinVelocity = new Vec3f(-2.5f, -1.5f, -2.5f), AddVelocity = new Vec3f(5f, 5f, 5f), GravityEffect = 0.4f, VertexFlags = rand.Next(100, 150), ParticleModel = EnumParticleModel.Cube, Async = true }; }
public override int GetColor(ICoreClientAPI capi, BlockPos pos) { int gray = ColorUtil.ColorFromRgba(127, 127, 127, 255); return(this.FirstCodePart() == "palmfrond" ? capi.ApplyColorTintOnRgba(1, gray, pos.X, pos.Y, pos.Z, false) : GetColorWithoutTint(capi, pos)); }
public override void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled) { base.OnInteract(byEntity, itemslot, hitPosition, mode, ref handled); IPlayer byPlayer = byEntity.World.PlayerByUid((byEntity as EntityPlayer).PlayerUID); if (owner != null && owner != byPlayer) { return; } if (mode == EnumInteractMode.Interact) { if (byEntity.Controls.Sneak && byEntity.Controls.Sprint && !invLocked) { workInv[0].TryFlipWith(itemslot); return; } if (itemslot.Itemstack?.Collectible is ItemHammer) { if (entity.GetBehavior <EntityBehaviorHealth>()?.Health < entity.GetBehavior <EntityBehaviorHealth>()?.MaxHealth) { itemslot.Itemstack.Collectible.DamageItem(entity.World, byEntity, itemslot, 5); entity.World.PlaySoundAt(new AssetLocation("game:sounds/effect/anvilhit3.ogg"), entity, byPlayer); entity.ReceiveDamage(new DamageSource() { Type = EnumDamageType.Heal }, 1); return; } } if (byEntity.Controls.Sprint && !restricted && itemslot?.Itemstack?.Collectible is ItemProgCard) { ItemStack stack = itemslot.Itemstack.Attributes.GetItemstack("workStack"); if (stack == null) { return; } stack.ResolveBlockOrItem(entity.World); if (stack != null) { workInv.DropAll(entity.ServerPos.XYZ); workStack = stack; maintree.SetItemstack("workStack", workStack); (byPlayer as IServerPlayer)?.SendMessage(GlobalConstants.InfoLogChatGroup, Lang.Get("temporalhack:work-itemprogram"), EnumChatType.Notification); } return; } else if (byEntity.Controls.Sprint && itemslot.Empty && byPlayer != null && workArea != null) { BlockPos min = workArea.Start.AsBlockPos; BlockPos max = workArea.End.AsBlockPos; max.Y += 1; List <BlockPos> blocks = new List <BlockPos>() { min, max }; List <int> colors = new List <int>() { ColorUtil.ColorFromRgba(215, 94, 94, 64), ColorUtil.ColorFromRgba(215, 94, 94, 64) }; entity.Api.World.HighlightBlocks(byPlayer, 56, blocks, colors, EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Cube); entity.Api.World.RegisterCallback((dt) => entity.Api.World.HighlightBlocks(byPlayer, 56, new List <BlockPos>(), new List <int>()), 3000); } if (byEntity.Controls.Sneak && itemslot?.Itemstack?.Collectible is ItemProgCard) { ITreeAttribute area = itemslot.Itemstack.Attributes.GetTreeAttribute("workArea"); ITreeAttribute box = null; ITreeAttribute barrel = null; if (!nochest) { box = itemslot.Itemstack.Attributes.GetTreeAttribute("workChest"); } if (!nobarrel) { barrel = itemslot.Itemstack.Attributes.GetTreeAttribute("workBarrel"); } StopAll(); if (area != null) { maintree["workArea"] = area.Clone(); workArea = cuboiddFromTree(area); } if (box != null) { maintree["workChest"] = box.Clone(); workChest = new BlockPos(box.GetInt("x"), box.GetInt("y"), box.GetInt("z")); } if (barrel != null) { maintree["workBarrel"] = barrel.Clone(); workBarrel = new BlockPos(barrel.GetInt("x"), barrel.GetInt("y"), barrel.GetInt("z")); } if (area != null || box != null || barrel != null) { (byPlayer as IServerPlayer)?.SendMessage(GlobalConstants.InfoLogChatGroup, Lang.Get("temporalhack:work-program"), EnumChatType.Notification); } } else if (byEntity.Controls.Sneak && itemslot.Empty) { AssetLocation item = new AssetLocation(entity.Code.Domain, "deploybot-" + entity.Code.Path); if (item != null) { EntityBehaviorHealth bh = entity.GetBehavior <EntityBehaviorHealth>(); ItemStack stack = new ItemStack(entity.World.GetItem(item)); stack.Attributes.SetInt("workEnergy", energy); if (bh != null) { stack.Attributes.SetFloat("workHealth", bh.MaxHealth - bh.Health); } byEntity.World.SpawnItemEntity(stack, entity.SidedPos.XYZ); workInv.DropAll(entity.ServerPos.XYZ); entity.Die(EnumDespawnReason.Removed); } } else if (byEntity.Controls.Sneak && itemslot?.Itemstack?.Collectible?.CombustibleProps?.BurnDuration != null) { if (itemslot.Itemstack.Collectible.CombustibleProps.BurnTemperature >= 200) { AddEnergy((itemslot.Itemstack.Collectible.CombustibleProps.BurnTemperature / 100) * (int)itemslot.Itemstack.Collectible.CombustibleProps.BurnDuration); itemslot.TakeOut(1); entity.World.PlaySoundAt(new AssetLocation("game:sounds/effect/extinguish2.ogg"), entity, byPlayer); } } } else { if (byEntity.Controls.Sneak) { StopAll(); workStack = null; workInv.DropAll(entity.ServerPos.XYZ); RemoveArea(); RemoveBarrel(); RemoveChest(); (byPlayer as IServerPlayer)?.SendMessage(GlobalConstants.InfoLogChatGroup, Lang.Get("temporalhack:work-memoryloss"), EnumChatType.Notification); } } }
private void onCmdAStar(IServerPlayer player, int groupId, CmdArgs args) { string subcmd = args.PopWord(); BlockPos plrPos = player.Entity.ServerPos.XYZ.AsBlockPos; PathfindSystem pfs = sapi.ModLoader.GetModSystem <PathfindSystem>(); Cuboidf narrow = new Cuboidf(-0.4f, 0, -0.4f, 0.4f, 1.5f, 0.4f); Cuboidf narrower = new Cuboidf(-0.2f, 0, -0.2f, 0.2f, 1.5f, 0.2f); Cuboidf wide = new Cuboidf(-0.6f, 0, -0.6f, 0.6f, 1.5f, 0.6f); Cuboidf collbox = narrow; int maxFallHeight = 3; float stepHeight = 1.01f; switch (subcmd) { case "start": start = plrPos.Copy(); sapi.World.HighlightBlocks(player, 26, new List <BlockPos>() { start }, new List <int>() { ColorUtil.ColorFromRgba(255, 255, 0, 128) }, EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary); break; case "end": end = plrPos.Copy(); sapi.World.HighlightBlocks(player, 27, new List <BlockPos>() { end }, new List <int>() { ColorUtil.ColorFromRgba(255, 0, 255, 128) }, EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary); break; case "bench": if (start == null || end == null) { return; } Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 15; i++) { List <PathNode> nodes = pfs.FindPath(start, end, maxFallHeight, stepHeight, collbox); } sw.Stop(); float timeMs = (float)sw.ElapsedMilliseconds / 15f; player.SendMessage(groupId, string.Format("15 searches average: {0} ms", (int)timeMs), EnumChatType.Notification); return; case "clear": start = null; end = null; sapi.World.HighlightBlocks(player, 2, new List <BlockPos>(), EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary); sapi.World.HighlightBlocks(player, 26, new List <BlockPos>(), EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary); sapi.World.HighlightBlocks(player, 27, new List <BlockPos>(), EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary); break; } if (start == null || end == null) { sapi.World.HighlightBlocks(player, 2, new List <BlockPos>(), EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary); } if (start != null && end != null) { Stopwatch sw = new Stopwatch(); sw.Start(); List <PathNode> nodes = pfs.FindPath(start, end, maxFallHeight, stepHeight, collbox); sw.Stop(); int timeMs = (int)sw.ElapsedMilliseconds; player.SendMessage(groupId, string.Format("Search took {0} ms, {1} nodes checked", timeMs, pfs.astar.NodesChecked), EnumChatType.Notification); if (nodes == null) { player.SendMessage(groupId, "No path found", EnumChatType.CommandError); sapi.World.HighlightBlocks(player, 2, new List <BlockPos>(), EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary); sapi.World.HighlightBlocks(player, 3, new List <BlockPos>(), EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary); return; } List <BlockPos> poses = new List <BlockPos>(); foreach (var node in nodes) { poses.Add(node); } sapi.World.HighlightBlocks(player, 2, poses, new List <int>() { ColorUtil.ColorFromRgba(128, 128, 128, 30) }, EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary); List <Vec3d> wps = pfs.ToWaypoints(nodes); poses = new List <BlockPos>(); foreach (var node in wps) { poses.Add(node.AsBlockPos); } sapi.World.HighlightBlocks(player, 3, poses, new List <int>() { ColorUtil.ColorFromRgba(128, 0, 0, 100) }, EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary); } }
public override int GetColorWithoutTint(ICoreClientAPI capi, BlockPos pos) { return(ColorUtil.ColorFromRgba(90, 84, 67, 255)); //base.GetColorWithoutTint(capi, pos); }
private void cmdPrecTestServer(IServerPlayer player, int groupId, CmdArgs args) { WeatherSystemServer wsys = api.ModLoader.GetModSystem <WeatherSystemServer>(); EntityPos pos = player.Entity.Pos; int wdt = 400; float hourStep = 4f; float days = 1f; float posStep = 2f; double totaldays = api.World.Calendar.TotalDays; string subarg = args.PopWord(); bool climateTest = subarg == "climate"; if (subarg == "pos") { float precip = wsys.GetPrecipitation(pos.X, pos.Y, pos.Z, totaldays); player.SendMessage(groupId, "Prec here: " + precip, EnumChatType.CommandSuccess); return; } ClimateCondition conds = api.World.BlockAccessor.GetClimateAt(new BlockPos((int)pos.X, (int)pos.Y, (int)pos.Z), EnumGetClimateMode.WorldGenValues, totaldays); int offset = wdt / 2; Bitmap bmp; int[] pixels; if (subarg == "here") { wdt = 400; bmp = new Bitmap(wdt, wdt, PixelFormat.Format32bppArgb); pixels = new int[wdt * wdt]; posStep = 3f; offset = wdt / 2; for (int dx = 0; dx < wdt; dx++) { for (int dz = 0; dz < wdt; dz++) { float x = dx * posStep - offset; float z = dz * posStep - offset; if ((int)x == 0 && (int)z == 0) { pixels[dz * wdt + dx] = ColorUtil.ColorFromRgba(255, 0, 0, 255); continue; } float precip = wsys.GetPrecipitation(pos.X + x, pos.Y, pos.Z + z, totaldays); int precipi = (int)GameMath.Clamp(255 * precip, 0, 254); pixels[dz * wdt + dx] = ColorUtil.ColorFromRgba(precipi, precipi, precipi, 255); } } bmp.SetPixels(pixels); bmp.Save("preciphere.png"); player.SendMessage(groupId, "Ok exported", EnumChatType.CommandSuccess); return; } bmp = new Bitmap(wdt, wdt, PixelFormat.Format32bppArgb); pixels = new int[wdt * wdt]; using (var gif = AnimatedGif.AnimatedGif.Create("precip.gif", 100, -1)) { for (int i = 0; i < days * 24f; i++) { if (climateTest) { for (int dx = 0; dx < wdt; dx++) { for (int dz = 0; dz < wdt; dz++) { conds.Rainfall = (float)i / (days * 24f); float precip = wsys.GetRainCloudness(conds, pos.X + dx * posStep - offset, pos.Z + dz * posStep - offset, api.World.Calendar.TotalDays); int precipi = (int)GameMath.Clamp(255 * precip, 0, 254); pixels[dz * wdt + dx] = ColorUtil.ColorFromRgba(precipi, precipi, precipi, 255); } } } else { for (int dx = 0; dx < wdt; dx++) { for (int dz = 0; dz < wdt; dz++) { float precip = wsys.GetPrecipitation(pos.X + dx * posStep - offset, pos.Y, pos.Z + dz * posStep - offset, totaldays); int precipi = (int)GameMath.Clamp(255 * precip, 0, 254); pixels[dz * wdt + dx] = ColorUtil.ColorFromRgba(precipi, precipi, precipi, 255); } } } totaldays += hourStep / 24f; bmp.SetPixels(pixels); gif.AddFrame(bmp, 100, GifQuality.Grayscale); } } player.SendMessage(groupId, "Ok exported", EnumChatType.CommandSuccess); }
private void onRoomRegDbgCmd(IServerPlayer player, int groupId, CmdArgs args) { string cmd = args.PopWord(); BlockPos pos = player.Entity.Pos.XYZ.AsBlockPos; long index3d = MapUtil.Index3dL(pos.X / chunksize, pos.Y / chunksize, pos.Z / chunksize, chunkMapSizeX, chunkMapSizeZ); ChunkRooms chunkrooms; lock (roomsByChunkIndexLock) { roomsByChunkIndex.TryGetValue(index3d, out chunkrooms); } if (chunkrooms == null || chunkrooms.Rooms.Count == 0) { player.SendMessage(groupId, "No rooms here", EnumChatType.Notification); return; } switch (cmd) { case "list": player.SendMessage(groupId, chunkrooms.Rooms.Count + " Rooms here ", EnumChatType.Notification); lock (chunkrooms.roomsLock) { for (int i = 0; i < chunkrooms.Rooms.Count; i++) { Room room = chunkrooms.Rooms[i]; int sizex = room.Location.X2 - room.Location.X1 + 1; int sizey = room.Location.Y2 - room.Location.Y1 + 1; int sizez = room.Location.Z2 - room.Location.Z1 + 1; string str = string.Format("{0} - bbox dim: {1}/{2}/{3}, mid: {4}/{5}/{6}", i, sizex, sizey, sizez, room.Location.X1 + sizex / 2f, room.Location.Y1 + sizey / 2f, room.Location.Z1 + sizez / 2f); player.SendMessage(groupId, str, EnumChatType.Notification); } } break; case "hi": { int rindex = (int)args.PopInt(0); if (chunkrooms.Rooms.Count - 1 < rindex || rindex < 0) { if (rindex == 0) { player.SendMessage(groupId, "No room here", EnumChatType.Notification); } else { player.SendMessage(groupId, "Wrong index, select a number between 0 and " + (chunkrooms.Rooms.Count - 1), EnumChatType.Notification); } } else { Room room = chunkrooms.Rooms[rindex]; // Debug visualization List <BlockPos> poses = new List <BlockPos>(); List <int> colors = new List <int>(); int sizex = room.Location.X2 - room.Location.X1 + 1; int sizey = room.Location.Y2 - room.Location.Y1 + 1; int sizez = room.Location.Z2 - room.Location.Z1 + 1; for (int dx = 0; dx < sizex; dx++) { for (int dy = 0; dy < sizey; dy++) { for (int dz = 0; dz < sizez; dz++) { int pindex = (dy * sizez + dz) * sizex + dx; if ((room.PosInRoom[pindex / 8] & (1 << (pindex % 8))) > 0) { poses.Add(new BlockPos(room.Location.X1 + dx, room.Location.Y1 + dy, room.Location.Z1 + dz)); colors.Add(ColorUtil.ColorFromRgba(room.ExitCount == 0 ? 0 : 100, room.ExitCount == 0 ? 100 : 0, Math.Min(255, rindex * 30), 150)); } } } } api.World.HighlightBlocks(player, 50, poses, colors, EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary ); } break; } case "unhi": api.World.HighlightBlocks(player, 50, new List <BlockPos>(), new List <int>(), EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary); break; } }
private void SpawnExplosionParticles() { #region Cuboid Particle Options Vec3f velocityRand = new Vec3f((float)(explosionRand.Next(0, 5) + explosionRand.NextDouble()), (float)(explosionRand.Next(0, 5) + explosionRand.NextDouble()), (float)(explosionRand.Next(0, 5) + explosionRand.NextDouble())); solidExplosionParticles.MinPos = this.entity.Pos.XYZ + new Vec3d(-this.entity.Properties.Client.Size / 2, -this.entity.Properties.Client.Size / 2, -this.entity.Properties.Client.Size / 2); solidExplosionParticles.AddPos = new Vec3d(this.entity.Properties.Client.Size, this.entity.Properties.Client.Size, this.entity.Properties.Client.Size); solidExplosionParticles.MinVelocity = new Vec3f(-velocityRand.X, -velocityRand.Y, -velocityRand.Z); solidExplosionParticles.AddVelocity = velocityRand * 2; solidExplosionParticles.GravityEffect = 0.1f; solidExplosionParticles.MinSize = 1.0f; solidExplosionParticles.MaxSize = 5.0f; solidExplosionParticles.SizeEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEAR, -2); solidExplosionParticles.MinQuantity = 100; solidExplosionParticles.AddQuantity = 50; solidExplosionParticles.LifeLength = 5.0f; solidExplosionParticles.addLifeLength = 5.0f; solidExplosionParticles.ShouldDieInLiquid = true; solidExplosionParticles.WithTerrainCollision = true; solidExplosionParticles.Color = ColorUtil.ColorFromRgba(255, 255, 255, explosionRand.Next(100, 255)); solidExplosionParticles.OpacityEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 255); solidExplosionParticles.BlueEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, explosionRand.Next(0, 150)); solidExplosionParticles.GreenEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, explosionRand.Next(150, 255)); solidExplosionParticles.RedEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 250); solidExplosionParticles.VertexFlags = explosionRand.Next(150, 255); #endregion #region Quad Particle Options Vec3f quadVelocityRand = new Vec3f((float)(explosionRand.Next(0, 2) + explosionRand.NextDouble()), (float)(explosionRand.Next(0, 2) + explosionRand.NextDouble()), (float)(explosionRand.Next(0, 2) + explosionRand.NextDouble())); quadExplosionParticles.MinPos = this.entity.ServerPos.XYZ + new Vec3d(-this.entity.Properties.Client.Size / 2, -this.entity.Properties.Client.Size / 2, -this.entity.Properties.Client.Size / 2); quadExplosionParticles.AddPos = new Vec3d(this.entity.Properties.Client.Size, this.entity.Properties.Client.Size, this.entity.Properties.Client.Size); quadExplosionParticles.MinVelocity = new Vec3f(-quadVelocityRand.X, -quadVelocityRand.Y, -quadVelocityRand.Z); quadExplosionParticles.AddVelocity = quadVelocityRand * 2; quadExplosionParticles.GravityEffect = 0.0f; quadExplosionParticles.MinSize = 1.0f; quadExplosionParticles.MaxSize = 10.0f; quadExplosionParticles.SizeEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEAR, -2); quadExplosionParticles.MinQuantity = 20; quadExplosionParticles.AddQuantity = 25; quadExplosionParticles.LifeLength = 1.5f; quadExplosionParticles.addLifeLength = .5f; quadExplosionParticles.ShouldDieInLiquid = true; quadExplosionParticles.Color = ColorUtil.ColorFromRgba(255, 255, 255, explosionRand.Next(100, 255)); quadExplosionParticles.OpacityEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 255); quadExplosionParticles.BlueEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, explosionRand.Next(0, 150)); quadExplosionParticles.GreenEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, explosionRand.Next(150, 255)); quadExplosionParticles.RedEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 255); quadExplosionParticles.VertexFlags = explosionRand.Next(150, 255); quadExplosionParticles.ParticleModel = EnumParticleModel.Quad; #endregion this.entity.World.SpawnParticles(solidExplosionParticles); this.entity.World.SpawnParticles(quadExplosionParticles); }
public override void Initialize(EntityProperties properties, JsonObject attributes) { base.Initialize(properties, attributes); skintree = entity.WatchedAttributes.GetTreeAttribute("skinConfig"); if (skintree == null) { entity.WatchedAttributes["skinConfig"] = skintree = new TreeAttribute(); } entity.WatchedAttributes.RegisterModifiedListener("skinConfig", onSkinConfigChanged); AvailableSkinParts = properties.Attributes["skinnableParts"].AsObject <SkinnablePart[]>(); foreach (var val in AvailableSkinParts) { string partCode = val.Code; val.VariantsByCode = new Dictionary <string, SkinnablePartVariant>(); AvailableSkinPartsByCode[val.Code] = val; if (val.Type == EnumSkinnableType.Texture && entity.Api.Side == EnumAppSide.Client) { ICoreClientAPI capi = entity.Api as ICoreClientAPI; LoadedTexture texture = new LoadedTexture(capi); foreach (var variant in val.Variants) { AssetLocation textureLoc; if (val.TextureTemplate != null) { textureLoc = val.TextureTemplate.Clone(); textureLoc.Path = textureLoc.Path.Replace("{code}", variant.Code); } else { textureLoc = variant.Texture; } IAsset asset = capi.Assets.TryGet(textureLoc.Clone().WithPathAppendixOnce(".png").WithPathPrefixOnce("textures/"), true); int r = 0, g = 0, b = 0; float c = 0; BitmapRef bmp = asset.ToBitmap(capi); for (int i = 0; i < 8; i++) { Vec2d vec = GameMath.R2Sequence2D(i); Color col2 = bmp.GetPixelRel((float)vec.X, (float)vec.Y); if (col2.A > 0.5) { r += col2.R; g += col2.G; b += col2.B; c++; } } bmp.Dispose(); c = Math.Max(1, c); variant.Color = ColorUtil.ColorFromRgba((int)(r / c), (int)(g / c), (int)(b / c), 255); val.VariantsByCode[variant.Code] = variant; } } else { foreach (var variant in val.Variants) { val.VariantsByCode[variant.Code] = variant; } } } if (entity.Api.Side == EnumAppSide.Server && AppliedSkinParts.Count == 0) { foreach (var val in AvailableSkinParts) { string partCode = val.Code; string variantCode = val.Variants[entity.World.Rand.Next(val.Variants.Length)].Code; selectSkinPart(partCode, variantCode, false); } } }
public void OnRenderFrame(float deltaTime, EnumRenderStage stage) { var plrPos = capi.World.Player.Entity.Pos; var bh = capi.World.Player.Entity.GetBehavior <EntityBehaviorTemporalStabilityAffected>(); if (bh != null) { bh.stabilityOffset = 0; } if (modsys.nearestRifts.Length > 0) { Rift rift = modsys.nearestRifts[0]; float dist = Math.Max(0, GameMath.Sqrt(plrPos.SquareDistanceTo(rift.Position)) - 1 - rift.Size / 2f); float f = Math.Max(0, 1 - dist / 3f); float jitter = capi.World.Rand.NextDouble() < 0.25 ? f * ((float)capi.World.Rand.NextDouble() - 0.5f) / 1f : 0; GlobalConstants.GuiGearRotJitter = jitter; capi.ModLoader.GetModSystem <SystemTemporalStability>().modGlitchStrength = Math.Min(1, f * 1.3f); if (bh != null) { bh.stabilityOffset = -Math.Pow(Math.Max(0, 1 - dist / 3), 2) * 20; } } else { capi.ModLoader.GetModSystem <SystemTemporalStability>().modGlitchStrength = 0; } counter += deltaTime; if (capi.World.Rand.NextDouble() < 0.012) { counter += 20 * (float)capi.World.Rand.NextDouble(); } capi.Render.GLDepthMask(false); prog.Use(); prog.BindTexture2D("primaryFb", capi.Render.FrameBuffers[(int)EnumFrameBuffer.Primary].ColorTextureIds[0], 0); prog.BindTexture2D("depthTex", capi.Render.FrameBuffers[(int)EnumFrameBuffer.Primary].DepthTextureId, 1); prog.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix); int width = capi.Render.FrameWidth; int height = capi.Render.FrameHeight; prog.Uniform("counter", counter); float bf = 200 + (float)GameMath.Sin(capi.InWorldEllapsedMilliseconds / 24000.0) * 100; prog.Uniform("counterSmooth", bf); prog.Uniform("invFrameSize", new Vec2f(1f / width, 1f / height)); int riftIndex = 0; cnt = (cnt + 1) % 3; foreach (var rift in rifts) { if (cnt == 0) { rift.Visible = capi.World.BlockAccessor.GetChunkAtBlockPos((int)rift.Position.X, (int)rift.Position.Y, (int)rift.Position.Z) != null; } riftIndex++; matrixf.Identity(); float dx = (float)(rift.Position.X - plrPos.X); float dy = (float)(rift.Position.Y - plrPos.Y); float dz = (float)(rift.Position.Z - plrPos.Z); matrixf.Translate(dx, dy, dz); matrixf.ReverseMul(capi.Render.CameraMatrixOriginf); matrixf.Values[0] = 1f; matrixf.Values[1] = 0f; matrixf.Values[2] = 0f; //matrixf.Values[4] = 0f; //matrixf.Values[5] = 1f; //matrixf.Values[6] = 0f; matrixf.Values[8] = 0f; matrixf.Values[9] = 0f; matrixf.Values[10] = 1f; float size = rift.GetNowSize(capi); matrixf.Scale(size, size, size); prog.UniformMatrix("modelViewMatrix", matrixf.Values); prog.Uniform("riftIndex", riftIndex); capi.Render.RenderMesh(meshref); if (dx * dx + dy * dy + dz * dz < 40 * 40) { Vec3d ppos = rift.Position; capi.World.SpawnParticles(0.1f, ColorUtil.ColorFromRgba(21 / 2, 70 / 2, 116 / 2, 128), ppos, ppos, new Vec3f(-0.125f, -0.125f, -0.125f), new Vec3f(0.125f, 0.125f, 0.125f), 5, 0, (0.125f / 2 + (float)capi.World.Rand.NextDouble() * 0.25f) / 2); } } counter = GameMath.Mod(counter + deltaTime, GameMath.TWOPI * 100f); prog.Stop(); capi.Render.GLDepthMask(true); }
private void DetermineTrailColour() { MeteorParticles.OpacityEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 255); switch (entity.LastCodePart()) { //-- Bright Yellow --// case "sodium": MeteorParticles.Color = ColorUtil.ColorFromRgba(25, 255, 255, Rand.Next(100, 255)); MeteorParticles.BlueEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 5); MeteorParticles.GreenEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 5); MeteorParticles.RedEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 20); break; //-- Gold/Orange --// case "iron": MeteorParticles.Color = ColorUtil.ColorFromRgba(30, 200, 255, Rand.Next(100, 255)); MeteorParticles.BlueEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 20); MeteorParticles.GreenEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 20); MeteorParticles.RedEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 5); break; //-- White --// case "magnesium": MeteorParticles.Color = ColorUtil.ColorFromRgba(255, 255, 255, Rand.Next(100, 255)); break; //-- Red --// case "nitrogen": MeteorParticles.Color = ColorUtil.ColorFromRgba(155, 155, 255, Rand.Next(100, 255)); MeteorParticles.BlueEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 30); MeteorParticles.GreenEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 30); MeteorParticles.RedEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 0); break; //-- Violet --// case "potassium": MeteorParticles.Color = ColorUtil.ColorFromRgba(255, 200, 255, Rand.Next(100, 255)); MeteorParticles.BlueEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 255); MeteorParticles.GreenEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 150); MeteorParticles.RedEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, Rand.Next(0, 150)); break; //-- Green --// case "copper": MeteorParticles.Color = ColorUtil.ColorFromRgba(165, 255, 165, Rand.Next(100, 255)); MeteorParticles.BlueEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 50); MeteorParticles.GreenEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, Rand.Next(0, 150)); MeteorParticles.RedEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 50); break; //-- Blue --// case "lead": MeteorParticles.Color = ColorUtil.ColorFromRgba(255, 50, 50, Rand.Next(100, 255)); MeteorParticles.BlueEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 5); MeteorParticles.GreenEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 5); MeteorParticles.RedEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 20); break; default: MeteorParticles.Color = ColorUtil.ColorFromRgba(255, 255, 255, Rand.Next(100, 255)); MeteorParticles.BlueEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, Rand.Next(0, 150)); MeteorParticles.GreenEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, Rand.Next(150, 255)); MeteorParticles.RedEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARREDUCE, 255); break; } }