bool TryAttachTo(IBlockAccessor blockAccessor, BlockPos blockpos, BlockFacing onBlockFace) { BlockPos attachingBlockPos = blockpos.AddCopy(onBlockFace.Opposite); Block block = blockAccessor.GetBlock(blockAccessor.GetBlockId(attachingBlockPos)); if (block.CanAttachBlockAt(blockAccessor, this, attachingBlockPos, onBlockFace)) { int blockId = blockAccessor.GetBlock(CodeWithParts(onBlockFace.Code)).BlockId; blockAccessor.SetBlock(blockId, blockpos); return(true); } return(false); }
public override Cuboidf[] GetSelectionBoxes(IBlockAccessor blockAccessor, BlockPos pos) { BlockEntityAnvil bea = blockAccessor.GetBlockEntity(pos) as BlockEntityAnvil; if (bea != null) { Cuboidf[] selectionBoxes = bea.GetSelectionBoxes(blockAccessor, pos); float angledeg = Math.Abs(bea.MeshAngle * GameMath.RAD2DEG); selectionBoxes[0] = angledeg == 0 || angledeg == 180 ? SelectionBoxes[0] : SelectionBoxes[1]; return(selectionBoxes); } return(base.GetSelectionBoxes(blockAccessor, pos)); }
private void generateSideGrowingMushrooms(IBlockAccessor blockAccessor, IRandom rnd) { int cnt = 1 + rnd.NextInt(5); BlockPos mpos = new BlockPos(); List <Vec3i> offsets = new List <Vec3i>(); while (cnt-- > 0) { int dx = 0; int dy = rnd.NextInt(5) - 2; int dz = 0; mpos.Set(Pos.X + dx, Pos.Y + dy, Pos.Z + dz); var block = blockAccessor.GetBlock(mpos); if (!(block is BlockLog) || block.Variant["type"] == "resin") { continue; } BlockFacing facing = null; int rndside = rnd.NextInt(4); for (int j = 0; j < 4; j++) { var f = BlockFacing.HORIZONTALS[(j + rndside) % 4]; mpos.Set(Pos.X + dx, Pos.Y + dy, Pos.Z + dz).Add(f); var nblock = blockAccessor.GetBlock(mpos); if (nblock.Id != 0) { continue; } facing = f.Opposite; break; } if (facing == null) { continue; } var mblock = blockAccessor.GetBlock(mushroomBlock.CodeWithVariant("side", facing.Code)); blockAccessor.SetBlock(mblock.Id, mpos); offsets.Add(new Vec3i(mpos.X - Pos.X, mpos.Y - Pos.Y, mpos.Z - Pos.Z)); } this.grownMushroomOffsets = offsets.ToArray(); }
public override bool CanPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection bs, ref string failureCode) { BlockPos pos = bs.Position; BlockPos down = pos.DownCopy(); IBlockAccessor blockAccess = world.BlockAccessor; //TODO: in future wattle walls directly below can also support this if (!CanSupportThis(blockAccess, down, null)) { // Can always place against other Layers of sticks bool oneSolid = blockAccess.GetBlock(pos.WestCopy()) is BlockSticksLayer; if (!oneSolid) { oneSolid = blockAccess.GetBlock(pos.EastCopy()) is BlockSticksLayer; } if (!oneSolid) { oneSolid = blockAccess.GetBlock(pos.NorthCopy()) is BlockSticksLayer; } if (!oneSolid) { oneSolid = blockAccess.GetBlock(pos.SouthCopy()) is BlockSticksLayer; } // Can place if any of the 4 surrounding supporting blocks has a solid top face or a shape which supports this if (!oneSolid) { oneSolid = CanSupportThis(blockAccess, down.WestCopy(), BlockFacing.EAST); } if (!oneSolid) { oneSolid = CanSupportThis(blockAccess, down.EastCopy(), BlockFacing.WEST); } if (!oneSolid) { oneSolid = CanSupportThis(blockAccess, down.NorthCopy(), BlockFacing.SOUTH); } if (!oneSolid) { oneSolid = CanSupportThis(blockAccess, down.SouthCopy(), BlockFacing.NORTH); } if (!oneSolid) { failureCode = "requiresolidground"; return(false); } } return(base.CanPlaceBlock(world, byPlayer, bs, ref failureCode)); }
public void GrowTree(IBlockAccessor api, BlockPos pos, bool isShrubLayer, float sizeModifier = 1f, float vineGrowthChance = 0, float otherBlockChance = 1f, int treesInChunkGenerated = 0) { Random rnd = rand.Value; lcgrandTL.Value.InitPositionSeed(pos.X, pos.Z); this.api = api; this.size = sizeModifier * config.sizeMultiplier + config.sizeVar.nextFloat(1, rnd); this.vineGrowthChance = vineGrowthChance; this.otherBlockChance = otherBlockChance; pos.Up(config.yOffset); TreeGenTrunk[] trunks = config.trunks; branchesByDepth.Clear(); branchesByDepth.Add(null); branchesByDepth.AddRange(config.branches); forestFloor.ClearOutline(); TreeGenTrunk trunk = config.trunks[0]; float trunkHeight = Math.Max(0, trunk.dieAt.nextFloat(1, rnd)); float trunkWidthLoss = trunk.WidthLoss(rnd); for (int i = 0; i < trunks.Length; i++) { trunk = config.trunks[i]; if (rnd.NextDouble() <= trunk.probability) { branchesByDepth[0] = trunk; growBranch( rnd, 0, pos, trunk.dx, 0f, trunk.dz, trunk.angleVert.nextFloat(1, rnd), trunk.angleHori.nextFloat(1, rnd), size * trunk.widthMultiplier, trunkHeight, trunkWidthLoss, trunks.Length > 1 ); } } if (!isShrubLayer) { forestFloor.CreateForestFloor(api, config, pos, lcgrandTL.Value, treesInChunkGenerated); } }
private bool TryGenStalag(IBlockAccessor blockAccessor, BlockPos pos, int thickOff, Random worldGenRand) { bool didplace = false; for (int dy = 0; dy < 5; dy++) { Block block = blockAccessor.GetBlock(pos.X, pos.Y + dy, pos.Z); if (block.SideSolid[BlockFacing.DOWN.Index] && block.BlockMaterial == EnumBlockMaterial.Stone) { string rocktype; if (block.Variant.TryGetValue("rock", out rocktype)) { GrowDownFrom(blockAccessor, pos.AddCopy(0, dy - 1, 0), rocktype, thickOff, worldGenRand); didplace = true; } break; } else if (block.Id != 0) { break; } } if (!didplace) { return(false); } for (int dy = 0; dy < 12; dy++) { Block block = blockAccessor.GetBlock(pos.X, pos.Y - dy, pos.Z); if (block.SideSolid[BlockFacing.UP.Index] && block.BlockMaterial == EnumBlockMaterial.Stone) { string rocktype; if (block.Variant.TryGetValue("rock", out rocktype)) { GrowUpFrom(blockAccessor, pos.AddCopy(0, -dy + 1, 0), rocktype, thickOff); didplace = true; } break; } else if (block.Id != 0 && !(block is BlockStalagSection)) { break; } } return(didplace); }
public override bool CanAttachBlockAt(IBlockAccessor world, Block block, BlockPos pos, BlockFacing blockFace, ref EnumHandling handling, Cuboidi attachmentArea = null) { if (Rot == "down") { handling = EnumHandling.PreventDefault; return(blockFace == BlockFacing.DOWN || (attachmentArea != null && attachmentArea.Y2 < 8)); } if (Rot == "up") { handling = EnumHandling.PreventDefault; return(blockFace == BlockFacing.UP || (attachmentArea != null && attachmentArea.Y1 > 7)); } return(base.CanAttachBlockAt(world, block, pos, blockFace, ref handling, attachmentArea)); }
public bool HasSupport(Block forBlock, IBlockAccessor blockAccess, BlockPos pos) { BlockFacing ownFacing = BlockFacing.FromCode(forBlock.LastCodePart()); BlockPos downPos = pos.DownCopy(); BlockPos upPos = pos.UpCopy(); return (SideSolid(blockAccess, pos, ownFacing) || (!isFlexible && SideSolid(blockAccess, downPos, BlockFacing.DOWN)) || SideSolid(blockAccess, upPos, BlockFacing.UP) || (pos.Y < blockAccess.MapSizeY - 1 && blockAccess.GetBlock(upPos) == forBlock && HasSupportUp(forBlock, blockAccess, upPos)) || (!isFlexible && pos.Y > 0 && blockAccess.GetBlock(downPos) == forBlock && HasSupportDown(forBlock, blockAccess, downPos)) ); }
public override Cuboidf[] GetSelectionBoxes(IBlockAccessor blockAccessor, BlockPos pos) { if (Variant["attachment"] == "wall") { return(base.GetCollisionBoxes(blockAccessor, pos)); } BlockEntitySign besign = blockAccessor.GetBlockEntity(pos) as BlockEntitySign; if (besign != null) { return(besign.colSelBox); } return(base.GetSelectionBoxes(blockAccessor, pos)); }
private void growMushrooms(IBlockAccessor blockAccessor, IRandom rnd) { bool sidegrowing = mushroomBlock.Variant.ContainsKey("side"); if (sidegrowing) { generateSideGrowingMushrooms(blockAccessor, rnd); } else { generateUpGrowingMushrooms(blockAccessor, rnd); } mushroomsGrownTotalDays = (mushroomBlock as BlockMushroom).Api.World.Calendar.TotalDays - rnd.NextDouble() * fruitingDays; }
public override void OnLoaded(ICoreAPI api) { base.OnLoaded(api); ICoreServerAPI sapi = api as ICoreServerAPI; if (sapi != null) { if (Code.Path.Equals("bamboo-grown-green-segment1")) { sapi.RegisterTreeGenerator(new AssetLocation("bamboo-grown-green"), this); } if (Code.Path.Equals("bamboo-grown-brown-segment1")) { sapi.RegisterTreeGenerator(new AssetLocation("bamboo-grown-brown"), this); } } if (greenSeg1 == null) { IBlockAccessor blockAccess = api.World.BlockAccessor; greenSeg1 = blockAccess.GetBlock(new AssetLocation("bamboo-grown-green-segment1")); greenSeg2 = blockAccess.GetBlock(new AssetLocation("bamboo-grown-green-segment2")); greenSeg3 = blockAccess.GetBlock(new AssetLocation("bamboo-grown-green-segment3")); brownSeg1 = blockAccess.GetBlock(new AssetLocation("bamboo-grown-brown-segment1")); brownSeg2 = blockAccess.GetBlock(new AssetLocation("bamboo-grown-brown-segment2")); brownSeg3 = blockAccess.GetBlock(new AssetLocation("bamboo-grown-brown-segment3")); brownLeaves = blockAccess.GetBlock(new AssetLocation("bambooleaves-brown-grown")); greenLeaves = blockAccess.GetBlock(new AssetLocation("bambooleaves-green-grown")); greenShootBlock = blockAccess.GetBlock(new AssetLocation("sapling-greenbambooshoots-free")); brownShootBlock = blockAccess.GetBlock(new AssetLocation("sapling-brownbambooshoots-free")); } if (RandomDrawOffset > 0) { JsonObject overrider = Attributes?["overrideRandomDrawOffset"]; if (overrider?.Exists == true) { this.RandomDrawOffset = overrider.AsInt(1); } } isSegmentWithLeaves = LastCodePart() == "segment2" || LastCodePart() == "segment3"; }
private bool OutsideMap(IBlockAccessor blockAccessor, BlockPos exitPos) { if (exitPos.X < 0 || exitPos.X >= blockAccessor.MapSizeX) { return(true); } if (exitPos.Y < 0 || exitPos.Y >= blockAccessor.MapSizeY) { return(true); } if (exitPos.Z < 0 || exitPos.Z >= blockAccessor.MapSizeZ) { return(true); } return(false); }
public override SkillItem[] GetToolModes(ItemSlot slot, IClientPlayer forPlayer, BlockSelection blockSel) { if (blockSel == null) { return(null); } IBlockAccessor blockAccessor = forPlayer.Entity.World.BlockAccessor; if (!SuitablePosition(blockAccessor, blockSel)) { return(null); } return(toolModes); }
public override byte[] GetLightHsv(IBlockAccessor blockAccessor, BlockPos pos, ItemStack stack = null) { if (pos == null) { return(base.GetLightHsv(blockAccessor, pos, stack)); } BlockEntityBoiler be = blockAccessor.GetBlockEntity(pos) as BlockEntityBoiler; if (be != null && be.firepitStage == 6) { return(firepitBlock.LightHsv); } return(base.GetLightHsv(blockAccessor, pos, stack)); }
public string getSolidFacesAtPos(IBlockAccessor blockAccessor, BlockPos pos) { string facings = ""; foreach (BlockFacing facing in BlockFacing.ALLFACES) { Block block = blockAccessor.GetBlock(pos.X + facing.Normali.X, pos.Y + facing.Normali.Y, pos.Z + facing.Normali.Z); if (block.SideSolid[facing.Opposite.Index]) { facings += facing.Code.Substring(0, 1); } } return(facings); }
internal 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)); if (block.CanAttachBlockAt(blockAccessor, this.block, pos.AddCopy(face), face.GetOpposite())) { return(true); } } return(false); }
public Block GetCollidingBlock(IBlockAccessor blockAccessor, Cuboidf entityBoxRel, Vec3d pos, bool alsoCheckTouch = true) { Cuboidd entityBox = tmpBox.SetAndTranslate(entityBoxRel, pos); int minX = (int)(entityBox.X1); int minY = (int)(entityBox.Y1) - 1; // -1 for the extra high collision box of fences int minZ = (int)(entityBox.Z1); int maxX = (int)(entityBox.X2); int maxY = (int)(entityBox.Y2); int maxZ = (int)(entityBox.Z2); for (int y = minY; y <= maxY; y++) { for (int x = minX; x <= maxX; x++) { for (int z = minZ; z <= maxZ; z++) { Block block = blockAccessor.GetBlock(x, y, z); blockPos.Set(x, y, z); Cuboidf[] collisionBoxes = block.GetCollisionBoxes(blockAccessor, blockPos); if (collisionBoxes == null || collisionBoxes.Length == 0) { continue; } blockPosVec.Set(x, y, z); for (int i = 0; i < collisionBoxes.Length; i++) { Cuboidf collBox = collisionBoxes[i]; if (collBox == null) { continue; } if (alsoCheckTouch ? entityBox.IntersectsOrTouches(collBox, blockPosVec) : entityBox.Intersects(collBox, blockPosVec)) { return(block); } } } } } return(null); }
/// <summary> /// Tests given cuboidf collides with the terrain. By default also checks if the cuboid is merely touching the terrain, set alsoCheckTouch to disable that. /// </summary> /// <param name="blockAccessor"></param> /// <param name="entityBoxRel"></param> /// <param name="pos"></param> /// <param name="alsoCheckTouch"></param> /// <returns></returns> public Cuboidd GetCollidingCollisionBox(IBlockAccessor blockAccessor, Cuboidf entityBoxRel, Vec3d pos, bool alsoCheckTouch = true) { BlockPos blockPos = new BlockPos(); Vec3d blockPosVec = new Vec3d(); Cuboidd entityBox = entityBoxRel.ToDouble().Translate(pos); entityBox.Y1 = Math.Round(entityBox.Y1, 5); // Fix float/double rounding errors. Only need to fix the vertical because gravity. int minX = (int)(entityBoxRel.X1 + pos.X); int minY = (int)(entityBoxRel.Y1 + pos.Y - 1); // -1 for the extra high collision box of fences int minZ = (int)(entityBoxRel.Z1 + pos.Z); int maxX = (int)Math.Ceiling(entityBoxRel.X2 + pos.X); int maxY = (int)Math.Ceiling(entityBoxRel.Y2 + pos.Y); int maxZ = (int)Math.Ceiling(entityBoxRel.Z2 + pos.Z); for (int y = minY; y <= maxY; y++) { for (int x = minX; x <= maxX; x++) { for (int z = minZ; z <= maxZ; z++) { Block block = blockAccessor.GetBlock(x, y, z); blockPos.Set(x, y, z); blockPosVec.Set(x, y, z); Cuboidf[] collisionBoxes = block.GetCollisionBoxes(blockAccessor, blockPos); for (int i = 0; collisionBoxes != null && i < collisionBoxes.Length; i++) { Cuboidf collBox = collisionBoxes[i]; if (collBox == null) { continue; } bool colliding = alsoCheckTouch ? entityBox.IntersectsOrTouches(collBox, blockPosVec) : entityBox.Intersects(collBox, blockPosVec); if (colliding) { return(collBox.ToDouble().Translate(blockPos)); } } } } } return(null); }
/// <summary> /// Get all blocks colliding with entityBoxRel /// </summary> /// <param name="blockAccessor"></param> /// <param name="entityBoxRel"></param> /// <param name="pos"></param> /// <param name="blocks">The found blocks</param> /// <param name="alsoCheckTouch"></param> /// <returns>If any blocks have been found</returns> public bool GetCollidingCollisionBox(IBlockAccessor blockAccessor, Cuboidf entityBoxRel, Vec3d pos, out CachedCuboidList blocks, bool alsoCheckTouch = true) { blocks = new CachedCuboidList(); BlockPos blockPos = new BlockPos(); Vec3d blockPosVec = new Vec3d(); Cuboidd entityBox = entityBoxRel.ToDouble().Translate(pos); int minX = (int)(entityBoxRel.MinX + pos.X); int minY = (int)(entityBoxRel.MinY + pos.Y - 1); // -1 for the extra high collision box of fences int minZ = (int)(entityBoxRel.MinZ + pos.Z); int maxX = (int)Math.Ceiling(entityBoxRel.MaxX + pos.X); int maxY = (int)Math.Ceiling(entityBoxRel.MaxY + pos.Y); int maxZ = (int)Math.Ceiling(entityBoxRel.MaxZ + pos.Z); for (int y = minY; y <= maxY; y++) { for (int x = minX; x <= maxX; x++) { for (int z = minZ; z <= maxZ; z++) { Block block = blockAccessor.GetBlock(x, y, z); blockPos.Set(x, y, z); blockPosVec.Set(x, y, z); Cuboidf[] collisionBoxes = block.GetCollisionBoxes(blockAccessor, blockPos); for (int i = 0; collisionBoxes != null && i < collisionBoxes.Length; i++) { Cuboidf collBox = collisionBoxes[i]; if (collBox == null) { continue; } bool colliding = alsoCheckTouch ? entityBox.IntersectsOrTouches(collBox, blockPosVec) : entityBox.Intersects(collBox, blockPosVec); if (colliding) { blocks.Add(collBox, x, y, z, block); } } } } } return(blocks.Count > 0); }
public void GenPalmTree(IBlockAccessor bA, BlockPos pos, double?sizeRnd1 = null, double?fruitRnd1 = null, double?frondRnd1 = null, int?fruitNum = null) { double sizeRnd = sizeRnd1 ?? api.World.Rand.NextDouble(); double fruitRnd = fruitRnd1 ?? api.World.Rand.NextDouble(); double frondRnd = frondRnd1 ?? api.World.Rand.NextDouble(); int fruiti = fruitNum ?? (int)Math.Round(fruitRnd * 2.0); while (!CanGenPalm(bA, pos.UpCopy(), sizeRnd)) { sizeRnd -= 0.01; if (sizeRnd < 0) { bA.SetBlock(saplings[fruiti], pos.UpCopy()); return; } } int[] stretched = trunk.Stretch((int)(sizeRnd * maxTreeSize)); for (int i = 0; i < stretched.Length; i++) { if (bA.GetBlock(pos).IsReplacableBy(bA.GetBlock(tip))) { bA.SetBlock(stretched[i], pos); } pos.Y++; } bA.SetBlock(tip, pos); int frondi = (int)Math.Round(frondRnd * 3.0); for (int i = 0; i < cardinaloffsets.Length; i++) { var c = cardinaloffsets[i]; BlockPos offset = pos.AddCopy(c.X, c.Y, c.Z); if (bA.GetBlock(offset).Id != 0) { continue; } int frondID = bA.GetBlock(bA.GetBlock(frond[i]).CodeWithPart(frondi.ToString(), 1)).Id; bA.SetBlock(frondID, offset); if (fruits[fruiti] != null) { bA.SetBlock(fruits[fruiti][i], offset.Add(0, -1, 0)); } } }
internal Cuboidf[] GetSelectionBoxes(IBlockAccessor blockAccessor, BlockPos pos, ItemStack holdingItemStack = null) { ICoreClientAPI capi = Api as ICoreClientAPI; if (capi == null) { return(null); } VoxelCircuit.EnumCircuitSelectionType selType; Item heldItem = holdingItemStack?.Item; Vec3i compSize = SignalsUtils.GetCircuitComponentSizeFromItem(capi, heldItem); if (heldItem?.Code?.ToString() == "signals:el_wire") { selType = VoxelCircuit.EnumCircuitSelectionType.PlaceWire; } else if (compSize != null) { selType = VoxelCircuit.EnumCircuitSelectionType.PlaceComponent; } else { selType = VoxelCircuit.EnumCircuitSelectionType.PlaceNothing; } Cuboidf[] boxes = Circuit?.GetSelectionBoxes(compSize, selType); if (selType == VoxelCircuit.EnumCircuitSelectionType.PlaceNothing) { Array.Resize(ref boxes, boxes.Length + 1); boxes[boxes.Length - 1] = new Cuboidf(0, 0, 0, 1, 1f / 16, 1); } //----------- Cuboidf[] rotatedBoxes = new Cuboidf[boxes.Length]; Vec3f rotation = SignalsUtils.FacingToRotation(orientation, facing); for (int i = 0; i < boxes.Length; i++) { rotatedBoxes[i] = boxes[i].RotatedCopy(rotation.X, rotation.Y, rotation.Z, new Vec3d(0.5d, 0.5, 0.5)); } return(rotatedBoxes); }
private void TrySpreadIntoBlock(Block ourblock, BlockPos npos, IWorldAccessor world) { IBlockAccessor blockAccess = world.BulkBlockAccessor; Block neighborBlock = world.BlockAccessor.GetBlock(npos); if (CanSpreadIntoBlock(ourblock, neighborBlock, world)) { if (IsDifferentCollidableLiquid(block, neighborBlock)) { ReplaceLiquidBlock(neighborBlock, npos, world); } else { SpreadLiquid(GetLessLiquidBlockId(world, ourblock), npos, world); } } }
/// <summary> /// This is our starting point. This method will be called by the server. /// </summary> public override void StartServerSide(ICoreServerAPI api) { _api = api; _worldBlockAccessor = api.World.BlockAccessor; _chunkSize = _worldBlockAccessor.ChunkSize; _treeTypes = new HashSet <string>(); LoadTreeTypes(_treeTypes); //Registers our command with the system's command registry. _api.RegisterCommand("treasure", "Place a treasure chest with random items", "", PlaceTreasureChestInFrontOfPlayer, Privilege.controlserver); //Registers a delegate to be called so we can get a reference to the chunk gen block accessor _api.Event.GetWorldgenBlockAccessor(OnWorldGenBlockAccessor); //Registers a delegate to be called when a chunk column is generating in the Vegetation phase of generation _api.Event.ChunkColumnGeneration(OnChunkColumnGeneration, EnumWorldGenPass.PreDone, "standard"); }
/// <summary> /// Tests given cuboidf collides with the terrain. By default also checks if the cuboid is merely touching the terrain, set alsoCheckTouch to disable that. /// </summary> /// <param name="blockAccessor"></param> /// <param name="entityBoxRel"></param> /// <param name="pos"></param> /// <param name="alsoCheckTouch"></param> /// <returns></returns> public bool GetCollidingCollisionBox(IBlockAccessor blockAccessor, Cuboidf entityBoxRel, Vec3d pos, ref Cuboidd intoCubuid, bool alsoCheckTouch = true) { BlockPos blockPos = new BlockPos(); Vec3d blockPosVec = new Vec3d(); Cuboidd entityBox = entityBoxRel.ToDouble().Translate(pos); int minX = (int)(entityBoxRel.X1 + pos.X); int minY = (int)(entityBoxRel.Y1 + pos.Y - 1); // -1 for the extra high collision box of fences int minZ = (int)(entityBoxRel.Z1 + pos.Z); int maxX = (int)Math.Ceiling(entityBoxRel.X2 + pos.X); int maxY = (int)Math.Ceiling(entityBoxRel.Y2 + pos.Y); int maxZ = (int)Math.Ceiling(entityBoxRel.Z2 + pos.Z); for (int y = minY; y <= maxY; y++) { for (int x = minX; x <= maxX; x++) { for (int z = minZ; z <= maxZ; z++) { Block block = blockAccessor.GetBlock(x, y, z); blockPos.Set(x, y, z); blockPosVec.Set(x, y, z); Cuboidf[] collisionBoxes = block.GetCollisionBoxes(blockAccessor, blockPos); for (int i = 0; collisionBoxes != null && i < collisionBoxes.Length; i++) { Cuboidf collBox = collisionBoxes[i]; if (collBox == null) { continue; } bool colliding = alsoCheckTouch ? entityBox.IntersectsOrTouches(collBox, blockPosVec) : entityBox.Intersects(collBox, blockPosVec); if (colliding) { intoCubuid.Set(collBox).Translate(blockPos); return(true); } } } } } return(false); }
private bool TestUndergroundCheckPositions(IBlockAccessor blockAccessor, BlockPos pos, BlockPos[] testPositionsDelta) { for (int i = 0; i < testPositionsDelta.Length; i++) { BlockPos deltapos = testPositionsDelta[i]; utestPos.Set(pos.X + deltapos.X, pos.Y + deltapos.Y, pos.Z + deltapos.Z); Block block = blockAccessor.GetBlock(utestPos); if (block.BlockMaterial != EnumBlockMaterial.Stone) { return(false); } } return(true); }
public override byte[] GetLightHsv(IBlockAccessor blockAccessor, BlockPos pos, ItemStack stack = null) { if (pos == null) { return(base.GetLightHsv(blockAccessor, pos, stack)); } BlockEntityCoalPile bea = blockAccessor.GetBlockEntity(pos) as BlockEntityCoalPile; if (bea?.IsBurning == true) { return new byte[] { 0, 7, 8 } } ; return(base.GetLightHsv(blockAccessor, pos, stack)); }
public override bool CanPlantStay(IBlockAccessor blockAccessor, BlockPos pos) { Block belowBlock = blockAccessor.GetBlock(pos.DownCopy()); if (belowBlock.Fertility > 0) { return(true); } if (!(belowBlock is BlockBerryBush)) { return(false); } Block belowbelowBlock = blockAccessor.GetBlock(pos.DownCopy(2)); return(belowbelowBlock.Fertility > 0 && this.Attributes?.IsTrue("stackable") == true && belowBlock.Attributes?.IsTrue("stackable") == true); }
public void Generate(IBlockAccessor blockAccessor, Random rnd, int posX, int posY, int posZ, ushort firstBlockId) { float quantity = Quantity.nextFloat() + 1; int chunkSize = blockAccessor.ChunkSize; Block[] blocks = getBlocks(firstBlockId); while (quantity-- > 0) { if (quantity < 1 && rnd.NextDouble() > quantity) { break; } pos.X = posX + (int)OffsetX.nextFloat(); pos.Z = posZ + (int)OffsetZ.nextFloat(); int index = GameMath.Mod((int)BlockCodeIndex.nextFloat(), blocks.Length); IServerChunk chunk = (IServerChunk)blockAccessor.GetChunk(pos.X / chunkSize, 0, pos.Z / chunkSize); if (chunk == null) { break; } int lx = GameMath.Mod(pos.X, chunkSize); int lz = GameMath.Mod(pos.Z, chunkSize); pos.Y = chunk.MapChunk.RainHeightMap[lz * blockAccessor.ChunkSize + lx] + 1; if (Math.Abs(pos.Y - posY) > 8 || pos.Y >= blockAccessor.MapSizeY - 1) { continue; } if (Placement == EnumBlockPatchPlacement.UnderWater) { tempPos.Set(pos.X, pos.Y - GameMath.Max(1, MinWaterDepth), pos.Z); Block downBlock = blockAccessor.GetBlock(tempPos); if (downBlock == null || !downBlock.IsWater()) { continue; } } blocks[index].TryPlaceBlockForWorldGen(blockAccessor, pos, BlockFacing.UP); } }
private bool SuitablePosition(IBlockAccessor blockAccessor, BlockSelection blockSel) { Block attachingBlock = blockAccessor.GetBlock(blockSel.Position); if (attachingBlock.SideSolid[blockSel.Face.Index] || (attachingBlock is BlockMicroBlock && (blockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityMicroBlock).sideAlmostSolid[blockSel.Face.Index])) { EnumBlockMaterial targetMaterial = attachingBlock.GetBlockMaterial(blockAccessor, blockSel.Position); for (int i = 0; i < paintableOnBlockMaterials.Length; i++) { if (targetMaterial == paintableOnBlockMaterials[i]) { return(true); } } } return(false); }
public override void Init(IBlockAccessor blockAccessor) { base.Init(blockAccessor); mapheight = blockAccessor.MapSizeY; blocksByPos = new Block[SizeX + 1, SizeY + 1, SizeZ + 1]; for (int i = 0; i < Indices.Count; i++) { uint index = Indices[i]; int storedBlockid = BlockIds[i]; int dx = (int)(index & 0x1ff); int dy = (int)((index >> 20) & 0x1ff); int dz = (int)((index >> 10) & 0x1ff); Block block = blockAccessor.GetBlock(BlockCodes[storedBlockid]); if (block == null) { continue; } blocksByPos[dx, dy, dz] = block; } handler = null; switch (ReplaceMode) { case EnumReplaceMode.ReplaceAll: handler = PlaceReplaceAllReplaceMeta; break; case EnumReplaceMode.Replaceable: handler = PlaceReplaceableReplaceMeta; break; case EnumReplaceMode.ReplaceAllNoAir: handler = PlaceReplaceAllNoAirReplaceMeta; break; case EnumReplaceMode.ReplaceOnlyAir: handler = PlaceReplaceOnlyAirReplaceMeta; break; } }