// TODO: EFficiency needed so much! public override void Execute(PlayerCommandEntry entry) { if (entry.InputArguments.Count < 1) { entry.Player.SendMessage(TextChannel.COMMAND_RESPONSE, "/blockship <convex/perfect> [scale]"); return; } BGETraceMode tm = BGETraceMode.CONVEX; if (entry.InputArguments[0].ToLowerFast() == "perfect") { tm = BGETraceMode.PERFECT; } double maxRad = 20; // TODO: Config! Location start = (entry.Player.GetPosition() + new Location(0, 0, -0.1)).GetBlockLocation(); List <KeyValuePair <Location, BlockInternal> > blocks = new List <KeyValuePair <Location, BlockInternal> >(); AABB extent = new AABB() { Min = start, Max = start }; if (!FloodFrom(entry.Player.TheRegion, start, blocks, maxRad, extent) || blocks.Count == 0) { entry.Player.SendMessage(TextChannel.COMMAND_RESPONSE, "Invalid flood-search!"); return; } Location size = extent.Max - extent.Min; int xwidth = (int)size.X + 1; int ywidth = (int)size.Y + 1; int zwidth = (int)size.Z + 1; int xsub = (int)extent.Min.X; int ysub = (int)extent.Min.Y; int zsub = (int)extent.Min.Z; BlockInternal[] blocksin = new BlockInternal[xwidth * ywidth * zwidth]; foreach (KeyValuePair <Location, BlockInternal> block in blocks) { entry.Player.TheRegion.SetBlockMaterial(block.Key, Material.AIR, 0, 0, 1, 0, true, true); blocksin[(int)(block.Key.Z - zsub) * ywidth * xwidth + (int)(block.Key.Y - ysub) * xwidth + (int)(block.Key.X - xsub)] = block.Value; } BlockGroupEntity bge = new BlockGroupEntity(extent.Min, tm, entry.Player.TheRegion, blocksin, xwidth, ywidth, zwidth) { scale = entry.InputArguments.Count < 2 ? Location.One : Location.FromString(entry.InputArguments[1]) }; entry.Player.TheRegion.SpawnEntity(bge); }
public BlockGroupEntity(Region tregion, BGETraceMode mode, BlockInternal[] blocks, int xwidth, int ywidth, int zwidth, Location sOffs) : base(tregion, true, true) { SetMass(blocks.Length); XWidth = xwidth; YWidth = ywidth; ZWidth = zwidth; Blocks = blocks; TraceMode = mode; if (TraceMode == BGETraceMode.PERFECT) { Shape = new MobileChunkShape(new Vector3i(xwidth, ywidth, zwidth), blocks, out Vector3 shoffs); } else { Shape = CalculateHullShape(out shapeOffs); } SysConsole.Output(OutputType.INFO, "Shape offs : " + shapeOffs + " vs " + sOffs); shapeOffs = sOffs; }
public BlockGroupEntity(Location baseloc, BGETraceMode mode, Region tregion, BlockInternal[] blocks, int xwidth, int ywidth, int zwidth, Location torigin = default(Location)) : base(tregion) { SetMass(blocks.Length * 10f); XWidth = xwidth; YWidth = ywidth; ZWidth = zwidth; Blocks = blocks; TraceMode = mode; Origin = torigin; if (TraceMode == BGETraceMode.PERFECT) { Shape = new MobileChunkShape(new Vector3i(xwidth, ywidth, zwidth), blocks, out Vector3 shoffs); // TODO: Anything offset related needed here? shapeOffs = -new Location(shoffs); } else { Shape = CalculateHullShape(out shapeOffs); shapeOffs = -shapeOffs; } SetPosition(baseloc - shapeOffs); }
public BlockGroupEntity(Region tregion, BGETraceMode mode, BlockInternal[] blocks, int xwidth, int ywidth, int zwidth, Location sOffs) : base(tregion, true, true) { SetMass(blocks.Length); XWidth = xwidth; YWidth = ywidth; ZWidth = zwidth; Blocks = blocks; TraceMode = mode; if (TraceMode == BGETraceMode.PERFECT) { Vector3 shoffs; Shape = new MobileChunkShape(new Vector3i(xwidth, ywidth, zwidth), blocks, out shoffs); } else { Shape = CalculateHullShape(out shapeOffs); } SysConsole.Output(OutputType.INFO, "Shape offs : " + shapeOffs + " vs " + sOffs); shapeOffs = sOffs; }
public override Entity Create(Region tregion, byte[] data) { int xwidth = (int)Utilities.BytesToInt(Utilities.BytesPartial(data, PhysicsEntity.PhysicsNetworkDataLength, 4)); int ywidth = (int)Utilities.BytesToInt(Utilities.BytesPartial(data, PhysicsEntity.PhysicsNetworkDataLength + 4, 4)); int zwidth = (int)Utilities.BytesToInt(Utilities.BytesPartial(data, PhysicsEntity.PhysicsNetworkDataLength + 4 + 4, 4)); BlockInternal[] bi = new BlockInternal[xwidth * ywidth * zwidth]; for (int i = 0; i < bi.Length; i++) { bi[i]._BlockMaterialInternal = Utilities.BytesToUshort(Utilities.BytesPartial(data, PhysicsEntity.PhysicsNetworkDataLength + (4 + 4 + 4) + i * 2, 2)); bi[i].BlockData = data[PhysicsEntity.PhysicsNetworkDataLength + (4 + 4 + 4) + bi.Length * 2 + i]; bi[i].BlockPaint = data[PhysicsEntity.PhysicsNetworkDataLength + (4 + 4 + 4) + bi.Length * 3 + i]; } BGETraceMode tm = (BGETraceMode)data[PhysicsEntity.PhysicsNetworkDataLength + (4 + 4 + 4) + bi.Length * 4]; BlockGroupEntity bge = new BlockGroupEntity(tregion, tm, bi, xwidth, ywidth, zwidth, Location.FromDoubleBytes(data, PhysicsEntity.PhysicsNetworkDataLength + (4 + 4 + 4) + bi.Length * 4 + 1 + 4)); bge.Color = System.Drawing.Color.FromArgb(Utilities.BytesToInt(Utilities.BytesPartial(data, PhysicsEntity.PhysicsNetworkDataLength + (4 + 4 + 4) + bi.Length * 4 + 1, 4))); bge.scale = Location.FromDoubleBytes(data, PhysicsEntity.PhysicsNetworkDataLength + (4 + 4 + 4) + bi.Length * 4 + 1 + 4 + 24); bge.ApplyPhysicsNetworkData(data); return(bge); }
public BlockGroupEntity(Location baseloc, BGETraceMode mode, Region tregion, BlockInternal[] blocks, int xwidth, int ywidth, int zwidth, Location torigin = default(Location)) : base(tregion) { SetMass(blocks.Length * 10f); XWidth = xwidth; YWidth = ywidth; ZWidth = zwidth; Blocks = blocks; TraceMode = mode; Origin = torigin; if (TraceMode == BGETraceMode.PERFECT) { Vector3 shoffs; Shape = new MobileChunkShape(new Vector3i(xwidth, ywidth, zwidth), blocks, out shoffs); // TODO: Anything offset related needed here? shapeOffs = -new Location(shoffs); } else { Shape = CalculateHullShape(out shapeOffs); shapeOffs = -shapeOffs; } SetPosition(baseloc - shapeOffs); }