private bool TryGrowZ(Cuboidi selection, bool positive) { bool shouldInclude = false; for (int y = selection.Y1; !shouldInclude && y < selection.Y2; y++) { for (int x = selection.X1; !shouldInclude && x < selection.X2; x++) { int z = positive ? (selection.Z2) : (selection.Z1 - 1); Block block = blockAccess.GetBlock(x, y, z); shouldInclude |= !edgeBlocksCache.Contains(block); } } if (shouldInclude) { if (positive) { selection.Z2++; } else { selection.Z1--; } return(true); } return(false); }
protected void RotateModel(IPlayer byPlayer, bool clockwise) { List <uint> rotatedCuboids = new List <uint>(); CuboidWithMaterial cwm = tmpCuboid; foreach (var val in VoxelCuboids) { FromUint(val, cwm); Cuboidi rotated = cwm.RotatedCopy(0, clockwise ? 90 : -90, 0, new Vec3d(8, 8, 8)); cwm.Set(rotated.X1, rotated.Y1, rotated.Z1, rotated.X2, rotated.Y2, rotated.Z2); rotatedCuboids.Add(ToCuboid(cwm)); } VoxelCuboids = rotatedCuboids; rotatedCuboids = new List <uint>(); foreach (var val in SnowCuboids) { FromUint(val, cwm); Cuboidi rotated = cwm.RotatedCopy(0, clockwise ? 90 : -90, 0, new Vec3d(8, 8, 8)); cwm.Set(rotated.X1, rotated.Y1, rotated.Z1, rotated.X2, rotated.Y2, rotated.Z2); rotatedCuboids.Add(ToCuboid(cwm)); } SnowCuboids = rotatedCuboids; }
public EnumClaimError AddArea(Cuboidi cuboidi) { // Require to be adjacent other claims if (Areas.Count == 0) { Areas.Add(cuboidi); return(EnumClaimError.NoError); } for (int i = 0; i < Areas.Count; i++) { if (Areas[i].Intersects(cuboidi)) { return(EnumClaimError.Overlapping); } } for (int i = 0; i < Areas.Count; i++) { if (Areas[i].IsAdjacent(cuboidi)) { Areas.Add(cuboidi); return(EnumClaimError.NoError); } } return(EnumClaimError.NotAdjacent); }
private BlockPos HasExitPoint(BlockPos nearpos) { IServerChunk chunk = api.World.BlockAccessor.GetChunkAtBlockPos(nearpos) as IServerChunk; List <GeneratedStructure> structures = chunk?.MapChunk?.MapRegion?.GeneratedStructures; if (structures == null) { return(null); } foreach (var structure in structures) { if (structure.Code.Contains("gates")) { Cuboidi loc = structure.Location; BlockPos foundPos = null; api.World.BlockAccessor.WalkBlocks(loc.Start.AsBlockPos, loc.End.AsBlockPos, (block, pos) => { BlockStaticTranslocator transBlock = block as BlockStaticTranslocator; if (transBlock != null && !transBlock.Repaired) { foundPos = pos.Copy(); } }); if (foundPos != null) { return(foundPos); } } } return(null); }
bool TryAttachTo(IWorldAccessor world, IPlayer byPlayer, BlockPos blockpos, Vec3d hitPosition, BlockFacing onBlockFace, ItemStack itemstack) { BlockPos attachingBlockPos = blockpos.AddCopy(onBlockFace.Opposite); Block attachingBlock = world.BlockAccessor.GetBlock(world.BlockAccessor.GetBlockId(attachingBlockPos)); BlockFacing onFace = onBlockFace; Block hereBlock = world.BlockAccessor.GetBlock(blockpos); Cuboidi attachmentArea = null; attachmentAreas?.TryGetValue(onBlockFace.Code, out attachmentArea); if (hereBlock.Replaceable >= 6000 && attachingBlock.CanAttachBlockAt(world.BlockAccessor, block, attachingBlockPos, onFace, attachmentArea)) { Block orientedBlock = world.BlockAccessor.GetBlock(block.CodeWithVariant(facingCode, onBlockFace.Code)); orientedBlock.DoPlaceBlock(world, byPlayer, new BlockSelection() { Position = blockpos, HitPosition = hitPosition, Face = onFace }, itemstack); return(true); } return(false); }
public void EnsureMapFullyLoaded() { int chunksize = api.World.BlockAccessor.ChunkSize; nowVisible.Clear(); nowHidden.Clear(); Cuboidi chunkviewBounds = CurrentBlockViewBounds.ToCuboidi(); chunkviewBounds.Div(chunksize); BlockPos cur = new BlockPos().Set(chunkviewBounds.X1, 0, chunkviewBounds.Z1); bool beforeBoundsEmpty = chunkViewBoundsBefore.SizeX == 0 && chunkViewBoundsBefore.SizeZ == 0; while (cur.X <= chunkviewBounds.X2) { cur.Z = chunkviewBounds.Z1; while (cur.Z <= chunkviewBounds.Z2) { if (beforeBoundsEmpty || !chunkViewBoundsBefore.ContainsOrTouches(cur)) { nowVisible.Add(new Vec2i(cur.X, cur.Z)); } cur.Z++; } cur.X++; } cur.Set(chunkViewBoundsBefore.X1, 0, chunkViewBoundsBefore.Z1); while (cur.X <= chunkViewBoundsBefore.X2) { cur.Z = chunkViewBoundsBefore.Z1; while (cur.Z <= chunkViewBoundsBefore.Z2) { if (!chunkviewBounds.ContainsOrTouches(cur)) { nowHidden.Add(new Vec2i(cur.X, cur.Z)); } cur.Z++; } cur.X++; } chunkViewBoundsBefore = chunkviewBounds.Clone(); if (nowHidden.Count > 0 || nowVisible.Count > 0) { viewChanged(nowVisible, nowHidden); } }
public BESpawnerData initDefaults() { if (SpawnArea == null) { SpawnArea = new Cuboidi(-3, 0, -3, 3, 3, 3); } return(this); }
public override void OnLoaded(ICoreAPI api) { base.OnLoaded(api); attachmentArea = Attributes?["attachmentArea"].AsObject <Cuboidi>(null); MaxServingSize = Attributes?["maxServingSize"].AsInt(6) ?? 6; }
public bool Intersects(Cuboidi cuboidi) { for (int i = 0; i < Areas.Count; i++) { if (Areas[i].Intersects(cuboidi)) { return(true); } } return(false); }
public bool InBounds(Vec3i voxelPos, int layer) { if (layer < 0 || layer >= 16) { return(false); } Cuboidi bounds = LayerBounds(layer); return(voxelPos.X >= bounds.X1 && voxelPos.X <= bounds.X2 && voxelPos.Y >= 0 && voxelPos.Y < 16 && voxelPos.Z >= bounds.Z1 && voxelPos.Z <= bounds.Z2); }
public override bool CanAttachBlockAt(IBlockAccessor world, Block block, BlockPos pos, BlockFacing blockFace, ref EnumHandling handling, Cuboidi attachmentArea) { if (BlockFacing.VERTICALS.Contains(blockFace)) { handling = EnumHandling.PreventDefault; return(true); } handling = EnumHandling.PassThrough; return(false); }
public override void ComposeElements(Context ctxStatic, ImageSurface surface) { Bounds.CalcWorldBounds(); chunkViewBoundsBefore = new Cuboidi(); BlockPos start = api.World.Player.Entity.Pos.AsBlockPos; CurrentBlockViewBounds = new Cuboidd( start.X - Bounds.InnerWidth / 2 / ZoomLevel, 0, start.Z - Bounds.InnerHeight / 2 / ZoomLevel, start.X + Bounds.InnerWidth / 2 / ZoomLevel, 0, start.Z + Bounds.InnerHeight / 2 / ZoomLevel ); }
bool CanStay(IBlockAccessor blockAccessor, BlockPos pos) { BlockFacing facing = BlockFacing.FromCode(Variant["orientation"]); BlockPos attachingBlockPos = pos.AddCopy(facing.Opposite); Block block = blockAccessor.GetBlock(attachingBlockPos); Cuboidi attachmentArea = null; attachmentAreas?.TryGetValue(facing.Opposite.Code, out attachmentArea); return(block.CanAttachBlockAt(blockAccessor, this, attachingBlockPos, facing, attachmentArea)); }
bool CanStay(IWorldAccessor world, BlockPos pos) { BlockFacing facing = BlockFacing.FromCode(block.Variant[facingCode]); BlockPos attachingBlockPos = pos.AddCopy(facing.Opposite); Block attachedblock = world.BlockAccessor.GetBlock(world.BlockAccessor.GetBlockId(attachingBlockPos)); BlockFacing onFace = facing; Cuboidi attachmentArea = null; attachmentAreas?.TryGetValue(facing.Code, out attachmentArea); return(attachedblock.CanAttachBlockAt(world.BlockAccessor, block, attachingBlockPos, onFace, attachmentArea)); }
private void RotateModel(IPlayer byPlayer, bool clockwise) { List <uint> rotatedCuboids = new List <uint>(); foreach (var val in this.VoxelCuboids) { FromUint(val, ref tmpCuboid); Cuboidi rotated = tmpCuboid.RotatedCopy(0, clockwise ? 90 : -90, 0, new Vec3d(8, 8, 8)); tmpCuboid.Set(rotated.X1, rotated.Y1, rotated.Z1, rotated.X2, rotated.Y2, rotated.Z2); rotatedCuboids.Add(ToCuboid(tmpCuboid)); } VoxelCuboids = rotatedCuboids; }
public bool nearToClaimedLand() { int rad = (int)Math.Ceiling(BlastRadius); Cuboidi exploArea = new Cuboidi(Pos.AddCopy(-rad, -rad, -rad), Pos.AddCopy(rad, rad, rad)); List <LandClaim> claims = (Api as ICoreServerAPI).WorldManager.SaveGame.LandClaims; for (int i = 0; i < claims.Count; i++) { if (claims[i].Intersects(exploArea)) { return(true); } } return(false); }
Cuboidi LayerBounds() { Cuboidi bounds = new Cuboidi(8, 8, 8, 8, 8, 8); for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { if (SelectedRecipe.Voxels[x, z]) { bounds.X1 = Math.Min(bounds.X1, x); bounds.X2 = Math.Max(bounds.X2, x); bounds.Z1 = Math.Min(bounds.Z1, z); bounds.Z2 = Math.Max(bounds.Z2, z); } } } return(bounds); }
public virtual bool IsAttached(IBlockAccessor blockAccessor, BlockPos pos) { for (int i = 0; i < AttachedToFaces.Length; i++) { BlockFacing face = AttachedToFaces[i]; Block block = blockAccessor.GetBlock(pos.AddCopy(face)); Cuboidi attachmentArea = null; attachmentAreas?.TryGetValue(face.Code, out attachmentArea); if (block.CanAttachBlockAt(blockAccessor, this.block, pos.AddCopy(face), face.Opposite, attachmentArea)) { return(true); } } return(false); }
public override void Initialize(JsonObject properties) { base.Initialize(properties); ignorePlaceTest = properties["ignorePlaceTest"].AsBool(false); exceptions = properties["exceptions"].AsObject(new AssetLocation[0], block.Code.Domain); fallSideways = properties["fallSideways"].AsBool(false); dustIntensity = properties["dustIntensity"].AsFloat(0); attachmentArea = properties["attachmentArea"].AsObject <Cuboidi>(null); fallSidewaysChance = properties["fallSidewaysChance"].AsFloat(0.25f); string sound = properties["fallSound"].AsString(null); if (sound != null) { fallSound = AssetLocation.Create(sound, block.Code.Domain); } impactDamageMul = properties["impactDamageMul"].AsFloat(1f); }
public override void OnInteractStart(WorldEdit worldEdit, BlockSelection blockSelection) { if (blockSelection == null) { return; } blockAccess = worldEdit.sapi.World.BlockAccessor; if (MagicSelect) { Cuboidi sele = MagiSelect(blockSelection); worldEdit.SetStartPos(sele.Start.AsBlockPos); worldEdit.SetEndPos(sele.End.AsBlockPos); workspace.revertableBlockAccess.StoreHistoryState(new List <BlockUpdate>()); } else { BlockPos endpos = blockSelection.Position.AddCopy(blockSelection.Face); if (workspace.StartMarker != null) { if (workspace.StartMarker.X <= endpos.X) { endpos.X++; } if (workspace.StartMarker.Y <= endpos.Y) { endpos.Y++; } if (workspace.StartMarker.Z <= endpos.Z) { endpos.Z++; } } worldEdit.SetEndPos(endpos); workspace.revertableBlockAccess.StoreHistoryState(new List <BlockUpdate>()); } base.OnInteractStart(worldEdit, blockSelection); }
bool TryAttachTo(IWorldAccessor world, BlockPos blockpos, BlockFacing onBlockFace) { BlockFacing onFace = onBlockFace; BlockPos attachingBlockPos = blockpos.AddCopy(onBlockFace.Opposite); Block block = world.BlockAccessor.GetBlock(attachingBlockPos); Cuboidi attachmentArea = null; attachmentAreas?.TryGetValue(onBlockFace.Opposite.Code, out attachmentArea); if (block.CanAttachBlockAt(world.BlockAccessor, this, attachingBlockPos, onFace, attachmentArea)) { int blockId = world.BlockAccessor.GetBlock(CodeWithVariant("orientation", onBlockFace.Code)).BlockId; world.BlockAccessor.SetBlock(blockId, blockpos); return(true); } return(false); }
public bool SideSolid(IBlockAccessor blockAccess, BlockPos pos, BlockFacing facing) { //public static readonly BlockFacing[] HORIZONTALS_ANGLEORDER = new BlockFacing[] { EAST, NORTH, WEST, SOUTH }; /// North: Negative Z /// East: Positive X /// South: Positive Z /// West: Negative X /// Up: Positive Y /// Down: Negative Y Block block = blockAccess.GetBlock(pos.X + facing.Normali.X, pos.Y, pos.Z + facing.Normali.Z); Cuboidi upHalf = new Cuboidi(14, 0, 0, 15, 7, 15).RotatedCopy(0, 90 * facing.HorizontalAngleIndex, 0, new Vec3d(7.5, 0, 7.5)); Cuboidi downHalf = new Cuboidi(14, 8, 0, 15, 15, 15).RotatedCopy(0, 90 * facing.HorizontalAngleIndex, 0, new Vec3d(7.5, 0, 7.5)); return (block.CanAttachBlockAt(blockAccess, block, pos.AddCopy(facing), facing.Opposite, upHalf) || block.CanAttachBlockAt(blockAccess, block, pos.AddCopy(facing), facing.Opposite, downHalf) ); }
bool TryAttachTo(IWorldAccessor world, BlockPos blockpos, BlockFacing onBlockFace) { BlockFacing onFace = onBlockFace; //if (onFace.IsHorizontal) onFace = onFace.GetOpposite(); - why is this here? Breaks attachment BlockPos attachingBlockPos = blockpos.AddCopy(onBlockFace.Opposite); Block block = world.BlockAccessor.GetBlock(attachingBlockPos); Cuboidi attachmentArea = null; attachmentAreas?.TryGetValue(onBlockFace.Opposite.Code, out attachmentArea); if (block.CanAttachBlockAt(world.BlockAccessor, this, attachingBlockPos, onFace, attachmentArea)) { int blockId = world.BlockAccessor.GetBlock(CodeWithParts(onBlockFace.Code)).BlockId; world.BlockAccessor.SetBlock(blockId, blockpos); return(true); } return(false); }
private BlockPos FindTranslocator(Cuboidi location, Dictionary <Vec2i, IServerChunk[]> columnsByChunkCoordinate, int centerCx, int centerCz) { int chunksize = Api.World.BlockAccessor.ChunkSize; for (int x = location.X1; x < location.X2; x++) { for (int y = location.Y1; y < location.Y2; y++) { for (int z = location.Z1; z < location.Z2; z++) { int cx = x / chunksize; int cy = y / chunksize; int cz = z / chunksize; IServerChunk[] chunks = null; if (!columnsByChunkCoordinate.TryGetValue(new Vec2i(cx, cz), out chunks)) { continue; } IServerChunk chunk = chunks[y / chunksize]; int lx = x % chunksize; int ly = y % chunksize; int lz = z % chunksize; int index3d = (ly * chunksize + lz) * chunksize + lx; Block block = Api.World.Blocks[chunk.Blocks[index3d]]; BlockStaticTranslocator transBlock = block as BlockStaticTranslocator; if (transBlock != null && !transBlock.Repaired) { return(new BlockPos(x, y, z)); } } } } return(null); }
public bool canPlaceWireAt(Vec3i voxelPos) { if (voxelPos.Y == 0) { return(false); } if (wiring.gotWireAtPos(voxelPos.X, voxelPos.Y, voxelPos.Z)) { return(false); } Cuboidi voxelBox = new Cuboidi(voxelPos, voxelPos.AddCopy(1, 1, 1)); foreach (CircuitComponent comp in components) { if (comp.doesIntersect(voxelBox)) { return(false); } } return(true); }
private Cuboidi MagiSelect(BlockSelection blockSelection) { BlockPos pos = blockSelection.Position; Cuboidi selection = new Cuboidi(pos, pos.AddCopy(1, 1, 1)); bool didGrowAny = true; int i = 0; while (didGrowAny && i < 600) { didGrowAny = TryGrowX(selection, true) || TryGrowX(selection, false) || TryGrowY(selection, true) || TryGrowY(selection, false) || TryGrowZ(selection, true) || TryGrowZ(selection, false) ; i++; } return(selection); }
public void OnTransformed(ITreeAttribute tree, int byDegrees, EnumAxis?aroundAxis) { List <uint> rotatedCuboids = new List <uint>(); VoxelCuboids = new List <uint>((tree["cuboids"] as IntArrayAttribute).AsUint); CuboidWithMaterial cwm = tmpCuboid; foreach (var val in VoxelCuboids) { FromUint(val, cwm); Cuboidi rotated = cwm.Clone(); if (aroundAxis == EnumAxis.X) { rotated.X1 = 16 - rotated.X1; rotated.X2 = 16 - rotated.X2; } if (aroundAxis == EnumAxis.Y) { rotated.Y1 = 16 - rotated.Y1; rotated.Y2 = 16 - rotated.Y2; } if (aroundAxis == EnumAxis.Z) { rotated.Z1 = 16 - rotated.Z1; rotated.Z2 = 16 - rotated.Z2; } rotated = rotated.RotatedCopy(0, byDegrees, 0, new Vec3d(8, 8, 8)); cwm.Set(rotated.X1, rotated.Y1, rotated.Z1, rotated.X2, rotated.Y2, rotated.Z2); rotatedCuboids.Add(ToCuboid(cwm)); } tree["cuboids"] = new IntArrayAttribute(rotatedCuboids.ToArray()); }
public override bool CanPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling, ref string failureCode) { handling = EnumHandling.PassThrough; if (ignorePlaceTest) { return(true); } Cuboidi attachmentArea = null; attachmentAreas?.TryGetValue(BlockFacing.UP.Code, out attachmentArea); BlockPos pos = blockSel.Position.DownCopy(); Block onBlock = world.BlockAccessor.GetBlock(pos); if (blockSel != null && !IsAttached(world.BlockAccessor, blockSel.Position) && !onBlock.CanAttachBlockAt(world.BlockAccessor, block, pos, BlockFacing.UP, attachmentArea) && block.Attributes?["allowUnstablePlacement"].AsBool() != true && !exceptions.Contains(onBlock.Code)) { handling = EnumHandling.PreventSubsequent; failureCode = "requiresolidground"; return(false); } return(TryFalling(world, blockSel.Position, ref handling, ref failureCode)); }
public bool InBounds(Vec3i voxelPos) { Cuboidi bounds = LayerBounds(); return(voxelPos.X >= bounds.X1 && voxelPos.X <= bounds.X2 && voxelPos.Y >= 0 && voxelPos.Y < 16 && voxelPos.Z >= bounds.Z1 && voxelPos.Z <= bounds.Z2); }
public override bool CanAttachBlockAt(IBlockAccessor blockAccessor, Block block, BlockPos pos, BlockFacing blockFace, Cuboidi attachmentArea = null) { return(block is BlockConnector); }