Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Apr 03, 2014 at 03:07 PM by Graham-Dunnett for the following reason:

Duplicate Question

avatar image
0
Question by Greggy · Apr 03, 2014 at 02:48 PM · mapgenerationminecraftinfiniteblock

map generation issues

ok so i have a infinite chunk map but i do not know how to limit the Z generation to 10?

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 [AddComponentMenu("VoxelEngine/Map")]
 public class Map : MonoBehaviour {
     
     [SerializeField] private BlockSet blockSet;
     private List3D<Chunk> chunks = new List3D<Chunk>();
     private SunLightMap sunLightmap = new SunLightMap();
     private LightMap lightmap = new LightMap();
     
     
     public void SetBlockAndRecompute(BlockData block, Vector3i pos) {
         SetBlock( block, pos );
         
         Vector3i chunkPos = Chunk.ToChunkPosition(pos);
         Vector3i localPos = Chunk.ToLocalPosition(pos);
         
         SetDirty( chunkPos );
         
         if(localPos.x == 0) SetDirty( chunkPos - Vector3i.right );
         if(localPos.y == 0) SetDirty( chunkPos - Vector3i.up );
         if(localPos.z == 0) SetDirty( chunkPos - Vector3i.forward );
         
         if(localPos.x == Chunk.SIZE_X-1) SetDirty( chunkPos + Vector3i.right );
         if(localPos.y == Chunk.SIZE_Y-1) SetDirty( chunkPos + Vector3i.up );
         if(localPos.z == Chunk.SIZE_Z-1) SetDirty( chunkPos + Vector3i.forward );
         
         SunLightComputer.RecomputeLightAtPosition(this, pos);
         LightComputer.RecomputeLightAtPosition(this, pos);
     }
     
     private void SetDirty(Vector3i chunkPos) {
         Chunk chunk = GetChunk( chunkPos );
         if(chunk != null) chunk.GetChunkRendererInstance().SetDirty();
     }
     
     public void SetBlock(Block block, Vector3i pos) {
         SetBlock(new BlockData(block), pos);
     }
     public void SetBlock(Block block, int x, int y, int z) {
         SetBlock(new BlockData(block), x, y, z);
     }
     
     public void SetBlock(BlockData block, Vector3i pos) {
         SetBlock(block, pos.x, pos.y, pos.z);
     }
     public void SetBlock(BlockData block, int x, int y, int z) {
         Chunk chunk = GetChunkInstance( Chunk.ToChunkPosition(x, y, z) );
         if(chunk != null) chunk.SetBlock( block, Chunk.ToLocalPosition(x, y, z) );
     }
     
     public BlockData GetBlock(Vector3i pos) {
         return GetBlock(pos.x, pos.y, pos.z);
     }
     public BlockData GetBlock(int x, int y, int z) {
         Chunk chunk = GetChunk( Chunk.ToChunkPosition(x, y, z) );
         if(chunk == null) return default(BlockData);
         return chunk.GetBlock( Chunk.ToLocalPosition(x, y, z) );
     }
     
     public int GetMaxY(int x, int z) {
         Vector3i chunkPos = Chunk.ToChunkPosition(x, 0, z);
         chunkPos.y = chunks.GetMax().y;
         Vector3i localPos = Chunk.ToLocalPosition(x, 0, z);
         
         for(;chunkPos.y >= 0; chunkPos.y--) {
             localPos.y = Chunk.SIZE_Y-1;
             for(;localPos.y >= 0; localPos.y--) {
                 Chunk chunk = chunks.SafeGet(chunkPos);
                 if(chunk == null) break;
                 BlockData block = chunk.GetBlock(localPos);
                 if(!block.IsEmpty()) return Chunk.ToWorldPosition(chunkPos, localPos).y;
             }
         }
         
         return 0;
     }
     
     private Chunk GetChunkInstance(Vector3i chunkPos) {
         if(chunkPos.y < 0) return null;
         Chunk chunk = GetChunk(chunkPos);
         if(chunk == null) {
             chunk = new Chunk(this, chunkPos);
             chunks.AddOrReplace(chunk, chunkPos);
         }
         return chunk;
     }
     public Chunk GetChunk(Vector3i chunkPos) {
         return chunks.SafeGet(chunkPos);
     }
     
     public List3D<Chunk> GetChunks() {
         return chunks;
     }
     
     public SunLightMap GetSunLightmap() {
         return sunLightmap;
     }
     
     public LightMap GetLightmap() {
         return lightmap;
     }
     
     public void SetBlockSet(BlockSet blockSet) {
         this.blockSet = blockSet;
     }
     public BlockSet GetBlockSet() {
         return blockSet;
     }
     
 }
Comment
Comments Locked
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

map generation issues 0 Answers

How can I rename an object without renaming every single one for block generation? 0 Answers

Infinite Forest Generation 1 Answer

This script really makes my game lag! 1 Answer

Minecraft block placing/ block building - how to? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges