public override void StartExecute() { base.StartExecute(); nowStuck = false; animStart = false; mineTimeNow = 0; pathTraverser.NavigateTo(targetPos.AddCopy(0, 1, 0), moveSpeed, 1.5f, OnGoalReached, OnStuck, false, 1000); }
public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { if (byEntity.World is IClientWorldAccessor) { ModelTransform tf = new ModelTransform(); tf.EnsureDefaultValues(); tf.Origin.Set(0, -0.1f, 0); tf.Rotation.Z = Math.Min(30, secondsUsed * 40); byEntity.Controls.UsingHeldItemTransformAfter = tf; if (secondsUsed > 0.6) { Vec3d pos = byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight, 0) .Ahead(1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw) ; Vec3f speedVec = new Vec3d(0, 0, 0).Ahead(5, byEntity.Pos.Pitch, byEntity.Pos.Yaw).ToVec3f(); particles.MinVelocity = speedVec; Random rand = new Random(); particles.Color = ColorUtil.ToRgba(255, 176, 176, 176); particles.MinPos = pos.AddCopy(-0.05, -0.05, -0.05); particles.AddPos.Set(0.1, 0.1, 0.1); particles.MinSize = 0.1F; particles.MaxSize = 0.5f; particles.SizeEvolve = EvolvingNatFloat.create(EnumTransformFunction.QUADRATIC, 1); byEntity.World.SpawnParticles(particles); } } return(true); }
private void onCmdRiftTest(IServerPlayer player, int groupId, CmdArgs args) { Vec3d pos = player.Entity.Pos.XYZ; string cmd = args.PopWord(); if (cmd == null) { player.SendMessage(groupId, rifts.Count + " rifts loaded", EnumChatType.Notification); return; } if (cmd == "clear") { rifts.Clear(); } if (cmd == "fade") { foreach (var rift in rifts) { rift.DieAtTotalHours = Math.Min(rift.DieAtTotalHours, api.World.Calendar.TotalHours + 0.2); } } if (cmd == "spawn") { for (int i = 0; i < 200; i++) { double distance = spawnMinDistance + api.World.Rand.NextDouble() * spawnAddDistance; double angle = api.World.Rand.NextDouble() * GameMath.TWOPI; double dz = distance * Math.Sin(angle); double dx = distance * Math.Cos(angle); Vec3d riftPos = pos.AddCopy(dx, 0, dz); BlockPos bpos = new BlockPos((int)riftPos.X, 0, (int)riftPos.Z); bpos.Y = api.World.BlockAccessor.GetTerrainMapheightAt(bpos); var block = api.World.BlockAccessor.GetBlock(bpos); if (block.IsLiquid() && api.World.Rand.NextDouble() > 0.1) { continue; } float size = 2 + (float)api.World.Rand.NextDouble() * 4f; riftPos.Y = bpos.Y + size / 2f + 1; rifts.Add(new Rift() { Position = riftPos, Size = size, SpawnedTotalHours = api.World.Calendar.TotalHours, DieAtTotalHours = api.World.Calendar.TotalHours + 8 + api.World.Rand.NextDouble() * 48 }); } } BroadCastRifts(); }
public override void OnHeldIdle(ItemSlot slot, EntityAgent byEntity) { if (byEntity.World is IClientWorldAccessor && byEntity.World.Rand.NextDouble() < 0.02) { KeyValuePair <ItemStack, int> contents = GetContents(byEntity.World, slot.Itemstack); if (contents.Key != null && !HasSolidifed(slot.Itemstack, contents.Key, byEntity.World)) { Vec3d pos = byEntity.Pos.XYZ.Add(byEntity.LocalEyePos.X, byEntity.LocalEyePos.Y - 0.5f, byEntity.LocalEyePos.Z) .Ahead(0.3f, byEntity.Pos.Pitch, byEntity.Pos.Yaw) .Ahead(0.47f, 0, byEntity.Pos.Yaw + GameMath.PIHALF) ; smokeHeld.MinPos = pos.AddCopy(-0.05, -0.05, -0.05); byEntity.World.SpawnParticles(smokeHeld); } } }
private void SpawnParticle(int amount, EntityAgent entity) { for (int i = 0; i < amount; i++) { Vec3d pos = entity.Pos.XYZ.Add(0, entity.LocalEyePos.Y, 0) .Ahead(1f, entity.Pos.Pitch, entity.Pos.Yaw) ; Vec3f speedVec = new Vec3d(0, 0, 0).Ahead(5, entity.Pos.Pitch, entity.Pos.Yaw).ToVec3f(); particles.MinVelocity = speedVec; Random rand = new Random(); particles.Color = ColorUtil.ToRgba(255, rand.Next(50, 150), rand.Next(50, 150), rand.Next(150, 255)); particles.MinPos = pos.AddCopy(-0.05, -0.05, -0.05); particles.AddPos.Set(0.1, 0.1, 0.1); particles.MinSize = 0.1F; particles.SizeEvolve = EvolvingNatFloat.create(EnumTransformFunction.SINUS, 10); entity.World.SpawnParticles(particles); } }
public override void OnHeldIdle(IItemSlot slot, IEntityAgent byEntity) { if (byEntity.World.Side == EnumAppSide.Client && GetTemperature(byEntity.World, slot.Itemstack) > 50 && byEntity.World.Rand.NextDouble() < 0.07) { float sideWays = 0.35f; IClientWorldAccessor world = byEntity.World as IClientWorldAccessor; if (world.Player.Entity == byEntity && world.Player.CameraMode != EnumCameraMode.FirstPerson) { sideWays = 0f; } Vec3d pos = byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight - 0.5f, 0) .Ahead(0.33f, byEntity.Pos.Pitch, byEntity.Pos.Yaw) .Ahead(sideWays, 0, byEntity.Pos.Yaw + GameMath.PIHALF) ; smokeHeld.minPos = pos.AddCopy(-0.05, 0.1, -0.05); byEntity.World.SpawnParticles(smokeHeld); } }
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); }
public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { if (blockSel == null) { return(false); } ILiquidMetalSink be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position) as ILiquidMetalSink; if (be == null) { return(false); } if (!be.CanReceiveAny) { return(false); } KeyValuePair <ItemStack, int> contents = GetContents(byEntity.World, slot.Itemstack); if (!be.CanReceive(contents.Key)) { return(false); } float speed = 1.5f; float temp = GetTemperature(byEntity.World, slot.Itemstack); if (byEntity.World is IClientWorldAccessor) { ModelTransform tf = new ModelTransform(); tf.EnsureDefaultValues(); tf.Origin.Set(0.5f, 0.2f, 0.5f); tf.Translation.Set(0, 0, -Math.Min(0.25f, speed * secondsUsed / 4)); tf.Scale = 1f + Math.Min(0.25f, speed * secondsUsed / 4); tf.Rotation.X = Math.Max(-110, -secondsUsed * 90 * speed); byEntity.Controls.UsingHeldItemTransformBefore = tf; } IPlayer byPlayer = null; if (byEntity is EntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); } if (secondsUsed > 1 / speed) { if ((int)(30 * secondsUsed) % 3 == 1) { Vec3d pos = byEntity.Pos.XYZ .Ahead(0.1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw) .Ahead(1.0f, byEntity.Pos.Pitch, byEntity.Pos.Yaw - GameMath.PIHALF) ; pos.Y += byEntity.LocalEyePos.Y - 0.4f; smokePouring.MinPos = pos.AddCopy(-0.15, -0.15, -0.15); Vec3d blockpos = blockSel.Position.ToVec3d().Add(0.5, 0.2, 0.5); bigMetalSparks.MinQuantity = Math.Max(0.2f, 1 - (secondsUsed - 1) / 4); if ((int)(30 * secondsUsed) % 7 == 1) { bigMetalSparks.MinPos = pos; bigMetalSparks.MinVelocity.Set(-2, -1, -2); bigMetalSparks.AddVelocity.Set(4, 1, 4); byEntity.World.SpawnParticles(bigMetalSparks, byPlayer); byEntity.World.SpawnParticles(smokePouring, byPlayer); } float y2 = 0; Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position); Cuboidf[] collboxs = block.GetCollisionBoxes(byEntity.World.BlockAccessor, blockSel.Position); for (int i = 0; collboxs != null && i < collboxs.Length; i++) { y2 = Math.Max(y2, collboxs[i].Y2); } // Metal Spark on the mold bigMetalSparks.MinVelocity.Set(-2, 1, -2); bigMetalSparks.AddVelocity.Set(4, 5, 4); bigMetalSparks.MinPos = blockpos.AddCopy(-0.25, y2 - 2 / 16f, -0.25); bigMetalSparks.AddPos.Set(0.5, 0, 0.5); bigMetalSparks.VertexFlags = (byte)GameMath.Clamp((int)temp - 770, 48, 128); byEntity.World.SpawnParticles(bigMetalSparks, byPlayer); // Smoke on the mold byEntity.World.SpawnParticles( Math.Max(1, 12 - (secondsUsed - 1) * 6), ColorUtil.ToRgba(50, 220, 220, 220), blockpos.AddCopy(-0.5, y2 - 2 / 16f, -0.5), blockpos.Add(0.5, y2 - 2 / 16f + 0.15, 0.5), new Vec3f(-0.5f, 0f, -0.5f), new Vec3f(0.5f, 0f, 0.5f), 1.5f, -0.05f, 0.75f, EnumParticleModel.Quad, byPlayer ); } int transferedAmount = Math.Min(2, contents.Value); be.ReceiveLiquidMetal(contents.Key, ref transferedAmount, temp); int newAmount = Math.Max(0, contents.Value - (2 - transferedAmount)); slot.Itemstack.Attributes.SetInt("units", newAmount); if (newAmount <= 0 && byEntity.World is IServerWorldAccessor) { string emptiedCode = Attributes["emptiedBlockCode"].AsString(); slot.Itemstack = new ItemStack(byEntity.World.GetBlock(AssetLocation.Create(emptiedCode, Code.Domain))); slot.MarkDirty(); // Since we change the item stack we have to call this ourselves OnHeldInteractStop(secondsUsed, slot, byEntity, blockSel, entitySel); return(false); } return(true); } return(true); }
public override void OnInteract(EntityAgent byEntity, ItemSlot slot, Vec3d hitPosition, EnumInteractMode mode) { EnumHandling handled = EnumHandling.PassThrough; foreach (EntityBehavior behavior in SidedProperties.Behaviors) { behavior.OnInteract(byEntity, slot, hitPosition, mode, ref handled); if (handled == EnumHandling.PreventSubsequent) { break; } } if (handled == EnumHandling.PreventDefault || handled == EnumHandling.PreventSubsequent) { return; } if (mode == EnumInteractMode.Attack) { float damage = slot.Itemstack == null ? 0.5f : slot.Itemstack.Collectible.GetAttackPower(slot.Itemstack); int damagetier = slot.Itemstack == null ? 0 : slot.Itemstack.Collectible.ToolTier; damage *= byEntity.Stats.GetBlended("meleeWeaponsDamage"); if (Attributes.GetBool("isMechanical", false)) { damage *= byEntity.Stats.GetBlended("mechanicalsDamage"); } IPlayer byPlayer = null; if (byEntity is EntityPlayer && !IsActivityRunning("invulnerable")) { byPlayer = (byEntity as EntityPlayer).Player; World.PlaySoundAt(new AssetLocation("sounds/player/slap"), ServerPos.X, ServerPos.Y, ServerPos.Z, byPlayer); slot?.Itemstack?.Collectible.OnAttackingWith(byEntity.World, byEntity, this, slot); } if (Api.Side == EnumAppSide.Client && damage > 1 && !IsActivityRunning("invulnerable") && Properties.Attributes?["spawnDamageParticles"].AsBool() == true) { Vec3d pos = SidedPos.XYZ + hitPosition; Vec3d minPos = pos.AddCopy(-0.15, -0.15, -0.15); Vec3d maxPos = pos.AddCopy(0.15, 0.15, 0.15); int textureSubId = this.Properties.Client.FirstTexture.Baked.TextureSubId; Vec3f tmp = new Vec3f(); for (int i = 0; i < 10; i++) { int color = (Api as ICoreClientAPI).EntityTextureAtlas.GetRandomColor(textureSubId); tmp.Set( 1f - 2 * (float)World.Rand.NextDouble(), 2 * (float)World.Rand.NextDouble(), 1f - 2 * (float)World.Rand.NextDouble() ); World.SpawnParticles( 1, color, minPos, maxPos, tmp, tmp, 1.5f, 1f, 0.25f + (float)World.Rand.NextDouble() * 0.25f, EnumParticleModel.Cube, byPlayer ); } } DamageSource dmgSource = new DamageSource() { Source = (byEntity as EntityPlayer).Player == null ? EnumDamageSource.Entity : EnumDamageSource.Player, SourceEntity = byEntity, Type = EnumDamageType.BluntAttack, HitPosition = hitPosition, DamageTier = damagetier }; if (ReceiveDamage(dmgSource, damage)) { byEntity.DidAttack(dmgSource, this); } } }
public override void StartExecute() { base.StartExecute(); stopNow = false; siegeMode = false; bool giveUpWhenNoPath = targetPos.SquareDistanceTo(entity.Pos.XYZ) < 12 * 12; int searchDepth = 3500; // 1 in 20 times we do an expensive search if (world.Rand.NextDouble() < 0.05) { searchDepth = 10000; } if (!pathTraverser.NavigateTo(targetPos.Clone(), moveSpeed, MinDistanceToTarget(), OnGoalReached, OnStuck, giveUpWhenNoPath, searchDepth, true)) { // If we cannot find a path to the target, let's circle it! float angle = (float)Math.Atan2(entity.ServerPos.X - targetPos.X, entity.ServerPos.Z - targetPos.Z); double randAngle = angle + 0.5 + world.Rand.NextDouble() / 2; double distance = 4 + world.Rand.NextDouble() * 6; double dx = GameMath.Sin(randAngle) * distance; double dz = GameMath.Cos(randAngle) * distance; targetPos = targetPos.AddCopy(dx, 0, dz); int tries = 0; bool ok = false; BlockPos tmp = new BlockPos((int)targetPos.X, (int)targetPos.Y, (int)targetPos.Z); int dy = 0; while (tries < 5) { // Down ok? if (world.BlockAccessor.GetBlock(tmp.X, tmp.Y - dy, tmp.Z).SideSolid[BlockFacing.UP.Index] && !world.CollisionTester.IsColliding(world.BlockAccessor, entity.CollisionBox, new Vec3d(tmp.X + 0.5, tmp.Y - dy + 1, tmp.Z + 0.5), false)) { ok = true; targetPos.Y -= dy; targetPos.Y++; siegeMode = true; break; } // Down ok? if (world.BlockAccessor.GetBlock(tmp.X, tmp.Y + dy, tmp.Z).SideSolid[BlockFacing.UP.Index] && !world.CollisionTester.IsColliding(world.BlockAccessor, entity.CollisionBox, new Vec3d(tmp.X + 0.5, tmp.Y + dy + 1, tmp.Z + 0.5), false)) { ok = true; targetPos.Y += dy; targetPos.Y++; siegeMode = true; break; } tries++; dy++; } ok = ok && pathTraverser.NavigateTo(targetPos.Clone(), moveSpeed, MinDistanceToTarget(), OnGoalReached, OnStuck, giveUpWhenNoPath, searchDepth, true); stopNow = !ok; } currentFollowTime = 0; }
public void Render(float dt) { GameTick(dt); capi.Render.CurrentActiveShader.Uniform("color", color); capi.Render.CurrentActiveShader.Uniform("lineWidth", linewidth); var plr = capi.World.Player; Vec3d camPos = plr.Entity.CameraPos; capi.Render.CurrentActiveShader.Uniform("origin", new Vec3f((float)(origin.X - camPos.X), (float)(origin.Y - camPos.Y), (float)(origin.Z - camPos.Z))); double cntRel = GameMath.Clamp(secondsAlive * 10, 0, 1); int instanceCount = (int)(cntRel * points.Count) - 1; if (instanceCount > 0) { capi.Render.RenderMeshInstanced(quadRef, instanceCount); } if (cntRel >= 0.9 && !soundPlayed) { soundPlayed = true; var lp = points[points.Count - 1]; Vec3d pos = origin + lp; float dist = (float)plr.Entity.Pos.DistanceTo(pos); if (dist < 150) { var loc = new AssetLocation("sounds/weather/lightning-nodistance.ogg"); capi.World.PlaySoundAt(loc, 0, 0, 0, null, EnumSoundType.Weather, 1, 32, Math.Max(0.1f, 1 - dist / 70)); } if (dist < 100) { (weatherSys as WeatherSystemClient).simLightning.lightningTime = 0.3f + (float)rand.NextDouble() * 0.17f; (weatherSys as WeatherSystemClient).simLightning.lightningIntensity = 1.5f + (float)rand.NextDouble() * 0.4f; int sub = Math.Max(0, (int)dist - 5) * 3; int color = ColorUtil.ToRgba(255, 255, 255, 200); SimpleParticleProperties props = new SimpleParticleProperties(500 / 2 - sub, 600 / 2 - sub, color, pos.AddCopy(-0.5f, 0, -0.5f), pos.AddCopy(0.5f, 1f, 0.5f), new Vec3f(-5, 0, -5), new Vec3f(5, 10, 5), 3, 0.3f, 0.4f, 2f); props.VertexFlags = 255; props.ShouldDieInLiquid = true; props.SizeEvolve = EvolvingNatFloat.create(EnumTransformFunction.LINEARREDUCE, 1f); capi.World.SpawnParticles(props); props.ParticleModel = EnumParticleModel.Quad; props.MinSize /= 2f; props.MaxSize /= 2f; capi.World.SpawnParticles(props); } } flashAccum += dt; if (flashAccum > rndVal) { rndVal = (float)rand.NextDouble() / 10; flashAccum = 0; float bnorm = (float)rand.NextDouble(); float b = 50 + bnorm * 150; pointLights[0].Color.Set(b, b, b); linewidth = (0.4f + 0.6f * bnorm) / 3f; if (cntRel < 1) { b = 0; } pointLights[1].Color.Set(b, b, b); } }
private void OnEvery250Ms(float dt) { // Random checks for breaking this block if heavy entity above and unsupported below IWorldAccessor world = Api.World; Vec3d pos3d = center.AddCopy(Pos); BlockPos down = Pos.DownCopy(); // If this block is unsupported, do an entity weight + block breaking check if (!CheckSupport(world.BlockAccessor, down)) { Entity[] entities = world.GetEntitiesAround(pos3d, 1.0f, 1.5f, (e) => (e?.Properties.Weight > WEIGHTLIMIT)); for (int i = 0; i < entities.Length; i++) { Entity entity = entities[i]; Cuboidd eBox = new Cuboidd(); EntityPos pos = entity.Pos; eBox.Set(entity.SelectionBox).Translate(pos.X, pos.Y, pos.Z); Cuboidf bBox = new Cuboidf(); bBox.Set(this.Block.CollisionBoxes[0]); bBox.Translate(Pos.X, Pos.Y, Pos.Z); // Check entity yPos actually intersects with this block (approximately) if (eBox.MinY <= bBox.MaxY + 0.01 && eBox.MinY >= bBox.MinY - 0.01) { // Check whether supported enough on any surrounding side bool checkSouth = eBox.MaxZ > bBox.Z2; bool checkNorth = eBox.MinZ < bBox.Z1; bool checkWest = eBox.MinX < bBox.X1; bool checkEast = eBox.MinZ > bBox.X2; bool supported = false; IBlockAccessor access = world.BlockAccessor; if (checkEast) { supported |= CheckSupport(access, down.EastCopy()); } if (checkEast && checkNorth) { supported |= CheckSupport(access, down.EastCopy().North()); } if (checkEast && checkSouth) { supported |= CheckSupport(access, down.EastCopy().South()); } if (checkWest) { supported |= CheckSupport(access, down.WestCopy()); } if (checkWest && checkNorth) { supported |= CheckSupport(access, down.WestCopy().North()); } if (checkWest && checkSouth) { supported |= CheckSupport(access, down.WestCopy().South()); } if (checkNorth) { supported |= CheckSupport(access, down.NorthCopy()); } if (checkSouth) { supported |= CheckSupport(access, down.SouthCopy()); } if (!supported) { // Break the block and the entity will fall :) // ## TODO } } } } return; }