本文整理汇总了C#中Location.GetBlockLocation方法的典型用法代码示例。如果您正苦于以下问题:C# Location.GetBlockLocation方法的具体用法?C# Location.GetBlockLocation怎么用?C# Location.GetBlockLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Location
的用法示例。
在下文中一共展示了Location.GetBlockLocation方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BreakNaturally
public void BreakNaturally(Location pos, bool regentrans = true)
{
pos = pos.GetBlockLocation();
Chunk ch = LoadChunk(ChunkLocFor(pos));
lock (ch.EditSessionLock)
{
int x = (int)Math.Floor(pos.X) - (int)ch.WorldPosition.X * Chunk.CHUNK_SIZE;
int y = (int)Math.Floor(pos.Y) - (int)ch.WorldPosition.Y * Chunk.CHUNK_SIZE;
int z = (int)Math.Floor(pos.Z) - (int)ch.WorldPosition.Z * Chunk.CHUNK_SIZE;
BlockInternal bi = ch.GetBlockAt(x, y, z);
if (((BlockFlags)bi.BlockLocalData).HasFlag(BlockFlags.PROTECTED))
{
return;
}
Material mat = (Material)bi.BlockMaterial;
ch.BlocksInternal[ch.BlockIndex(x, y, z)].BlockLocalData |= (byte)BlockFlags.PROTECTED;
if (mat != (ushort)Material.AIR)
{
ch.SetBlockAt(x, y, z, new BlockInternal((ushort)Material.AIR, 0, 0, (byte)BlockFlags.EDITED));
ch.LastEdited = GlobalTickTime;
SurroundRunPhysics(pos);
if (regentrans)
{
ChunkSendToAll(new BlockEditPacketOut(new Location[] { pos }, new ushort[] { 0 }, new byte[] { 0 }, new byte[] { 0 }), ch.WorldPosition);
}
bi.Material = mat.GetBreaksInto();
BlockItemEntity bie = new BlockItemEntity(this, new BlockInternal((ushort)bi._BlockMaterialInternal, bi.BlockData, bi._BlockPaintInternal, 0), pos);
SpawnEntity(bie);
}
}
}
示例2: MusicBlockEntity
// TODO: Heal with time?
public MusicBlockEntity(Region tregion, ItemStack orig, Location pos)
: base("mapobjects/customblocks/musicblock", tregion)
{
Original = orig;
SetMass(0);
SetPosition(pos.GetBlockLocation() + new Location(0.5));
SetOrientation(Quaternion.Identity);
}
示例3: ApplyLiquidForcesTo
void ApplyLiquidForcesTo(Entity e, double dt)
{
if (e.Mass <= 0)
{
return;
}
RigidTransform ert = new RigidTransform(e.Position, e.Orientation);
BoundingBox entbb;
e.CollisionInformation.Shape.GetBoundingBox(ref ert, out entbb);
Location min = new Location(entbb.Min);
Location max = new Location(entbb.Max);
min = min.GetBlockLocation();
max = max.GetUpperBlockBorder();
for (int x = (int)min.X; x < max.X; x++)
{
for (int y = (int)min.Y; y < max.Y; y++)
{
for (int z = (int)min.Z; z < max.Z; z++)
{
Location c = new Location(x, y, z);
Material mat = (Material)TheRegion.GetBlockInternal_NoLoad(c).BlockMaterial;
if (mat.GetSolidity() != MaterialSolidity.LIQUID)
{
continue;
}
// TODO: Account for block shape?
double vol = e.CollisionInformation.Shape.Volume;
double dens = (e.Mass / vol);
double WaterDens = 5; // TODO: Read from material. // TODO: Sanity of values.
double modifier = (double)(WaterDens / dens);
double submod = 0.125f;
// TODO: Tracing accuracy!
Vector3 impulse = -(TheRegion.PhysicsWorld.ForceUpdater.Gravity + TheRegion.GravityNormal.ToBVector() * 0.4f) * e.Mass * dt * modifier * submod;
// TODO: Don't apply smaller logic this if scale is big!
for (double x2 = 0.25f; x2 < 1; x2 += 0.5f)
{
for (double y2 = 0.25f; y2 < 1; y2 += 0.5f)
{
for (double z2 = 0.25f; z2 < 1; z2 += 0.5f)
{
Location lc = c + new Location(x2, y2, z2);
RayHit rh;
if (e.CollisionInformation.RayCast(new Ray(lc.ToBVector(), new Vector3(0, 0, 1)), 0.01f, out rh)) // TODO: Efficiency!
{
Vector3 center = lc.ToBVector();
e.ApplyImpulse(ref center, ref impulse);
e.ModifyLinearDamping(mat.GetSpeedMod());
e.ModifyAngularDamping(mat.GetSpeedMod());
}
}
}
}
}
}
}
}
示例4: BlockItemEntity
public BlockItemEntity(Region tregion, BlockInternal orig, Location pos)
: base(tregion)
{
SetMass(20);
CGroup = CollisionUtil.Item;
Original = orig;
Location offset;
Shape = BlockShapeRegistry.BSD[orig.BlockData].GetShape(orig.Damage, out offset, true);
SetPosition(pos.GetBlockLocation() + offset);
}
示例5: StaticBlockEntity
public StaticBlockEntity(Region tregion, ItemStack orig, Location pos)
: base(tregion)
{
SetMass(0);
CGroup = CollisionUtil.Item;
Original = orig;
Location offset;
Shape = BlockShapeRegistry.BSD[0].GetShape(BlockDamage.NONE, out offset, false);
SetPosition(pos.GetBlockLocation() + offset);
SetOrientation(Quaternion.Identity);
}
示例6: Structure
// TODO: Optimize tracing!
public Structure(Region tregion, Location startOfTrace, int maxrad)
{
startOfTrace = startOfTrace.GetBlockLocation();
Queue<Location> locs = new Queue<Location>();
HashSet<Location> found = new HashSet<Location>();
List<Location> resultLocs = new List<Location>();
locs.Enqueue(startOfTrace);
int maxradsq = maxrad * maxrad;
AABB box = new AABB() { Max = startOfTrace, Min = startOfTrace };
while (locs.Count > 0)
{
Location loc = locs.Dequeue();
if (found.Contains(loc))
{
continue;
}
if (loc.DistanceSquared(startOfTrace) > maxradsq)
{
throw new Exception("Escaped radius!");
}
BlockInternal bi = tregion.GetBlockInternal(loc);
if ((Material)bi.BlockMaterial == Material.AIR)
{
continue;
}
if (!((BlockFlags)bi.BlockLocalData).HasFlag(BlockFlags.EDITED))
{
throw new Exception("Found natural block!");
}
if (((BlockFlags)bi.BlockLocalData).HasFlag(BlockFlags.PROTECTED))
{
throw new Exception("Found protected block!");
}
found.Add(loc);
resultLocs.Add(loc);
box.Include(loc);
foreach (Location dir in FloodDirs)
{
locs.Enqueue(loc + dir);
}
}
Location ext = box.Max - box.Min;
Size = new Vector3i((int)ext.X + 1, (int)ext.Y + 1, (int)ext.Z + 1);
Origin = new Vector3i((int)Math.Floor(startOfTrace.X - box.Min.X), (int)Math.Floor(startOfTrace.Y - box.Min.Y), (int)Math.Floor(startOfTrace.Z - box.Min.Z));
Blocks = new BlockInternal[Size.X * Size.Y * Size.Z];
foreach (Location loc in resultLocs)
{
Blocks[BlockIndex((int)(loc.X - box.Min.X), (int)(loc.Y - box.Min.Y), (int)(loc.Z - box.Min.Z))] = tregion.GetBlockInternal(loc);
}
}
示例7: AltClick
public override void AltClick(Entity entity, ItemStack item)
{
if (!(entity is PlayerEntity))
{
// TODO: non-player support
return;
}
PlayerEntity player = (PlayerEntity)entity;
Location eye = player.GetEyePosition();
Location forw = player.ForwardVector();
RayCastResult rcr;
bool h = player.TheRegion.SpecialCaseRayTrace(eye, forw, 5, MaterialSolidity.ANY, player.IgnoreThis, out rcr);
if (h)
{
if (rcr.HitObject != null && rcr.HitObject is EntityCollidable && ((EntityCollidable)rcr.HitObject).Entity != null)
{
// TODO: ???
}
else if (player.Mode.GetDetails().CanPlace && player.TheRegion.GlobalTickTime - player.LastBlockPlace >= 0.2)
{
Location block = new Location(rcr.HitData.Location) + new Location(rcr.HitData.Normal).Normalize() * 0.9f;
block = block.GetBlockLocation();
Material mat = player.TheRegion.GetBlockMaterial(block);
if (player.TheRegion.IsAllowedToPlaceIn(player, block, mat))
{
CollisionResult hit = player.TheRegion.Collision.CuboidLineTrace(new Location(0.45, 0.45, 0.45), block + new Location(0.5),
block + new Location(0.5, 0.5, 0.501), player.TheRegion.Collision.ShouldCollide);
if (!hit.Hit)
{
BlockInternal bi = BlockInternal.FromItemDatum(item.Datum);
MusicBlockEntity mbe = new MusicBlockEntity(player.TheRegion, item, block); // TODO: Vary based on material!
player.TheRegion.SpawnEntity(mbe);
player.Network.SendPacket(new DefaultSoundPacketOut(block, DefaultSound.PLACE, (byte)((Material)bi.BlockMaterial).Sound()));
item.Count = item.Count - 1;
if (item.Count <= 0)
{
player.Items.RemoveItem(player.Items.cItem);
}
else
{
player.Items.SetSlot(player.Items.cItem - 1, item);
}
player.LastBlockPlace = player.TheRegion.GlobalTickTime;
}
}
}
}
}
示例8: InWater
public bool InWater(Location min, Location max)
{
// TODO: Efficiency!
min = min.GetBlockLocation();
max = max.GetUpperBlockBorder();
for (int x = (int)min.X; x < max.X; x++)
{
for (int y = (int)min.Y; y < max.Y; y++)
{
for (int z = (int)min.Z; z < max.Z; z++)
{
if (GetBlockMaterial(min + new Location(x, y, z)).GetSolidity() == MaterialSolidity.LIQUID)
{
return true;
}
}
}
}
return false;
}
示例9: SurroundRunPhysics
public void SurroundRunPhysics(Location start)
{
start = start.GetBlockLocation();
for (int x = -1; x <= 1; x++)
{
for (int y = -1; y <= 1; y++)
{
for (int z = -1; z <= 1; z++)
{
RunBlockPhysics(start + new Location(x, y, z));
}
}
}
foreach (Entity e in GetEntitiesInRadius(start + new Location(0.5), 3f))
{
e.PotentialActivate();
}
}
示例10: RunBlockPhysics
public void RunBlockPhysics(Location block)
{
block = block.GetBlockLocation();
BlockInternal c = GetBlockInternal(block);
if (((BlockFlags)c.BlockLocalData).HasFlag(BlockFlags.NEEDS_RECALC))
{
c.BlockLocalData = (byte)(c.BlockLocalData & ~((byte)BlockFlags.NEEDS_RECALC));
SetBlockMaterial(block, c, false, false, true);
}
LiquidPhysics(block, c);
}