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 /
avatar image
0
Question by CursedScripter · Dec 29, 2011 at 11:55 PM · errorrandomminecraftgenerator

Minecraft In Unity, Coal and Iron

I have a terrain generator that i got off of this site.

http://sourceforge.net/projects/minepackage/

I have textures and stuff, and im not using there svn download since its messed up so I download there older one which is available here

http://sourceforge.net/projects/minepackage/files/WhereToGetTheStuff.txt/download

Well that txt file has the download link in it. I understand alot of it but im still confused on how to add stuff like coal into it. I have the textures and i set the texture options to what is required.

In the WorldData.cs I have this for the specific coal texture SetBlockUVCoordinates(BlockType.Coal, 9,9,9);

The 9th element in the WorldGameObject Script/Prefab is set to look like this

World_Textures(Variable)

  • Size 10
  • Element 0 - Grass
  • Element 1 - Grass
  • Element 2 - Grass
  • I think you get the picture
  • Element 9 - Coal

In the Block.cs Script I Have this, plus more but this is all thats needed

 public enum BlockType : byte
 
 {
 
     TopSoil=0,
 
     Dirt=1,
 
     Light = 2,
 
     Lava = 3,
 
     Leaves=4,
 
     Stone = 5,
 
     Bark = 6,
 
     Water = 7,
 
     Coal = 8,
 
     Air = 255
 
 
 
 }

For the DualLayerTerrainWithMediumValleys.cs How could i implement coal being placed at random? I was looking at the TreeScript that have and I noticed how they did the Random and in the DualLayerTerrainWithMediumValleys.cs I found this

 if (sunlit)
 
                             {
 
                                 blockType = BlockType.TopSoil;
 
                                 chunk.TopSoilBlocks.Add(new IntVect(blockX, blockY, z));
 
                                 sunlit = false;
 
                             }
 
                             else
 
                             {
 
                                 blockType = BlockType.Dirt;
 
                                 if (caveNoise < 0.2f)
 
                                 {
 
                                     
 
                                     
 
                                         
 
                                             blockType = BlockType.Stone;    
 
                                         
 
                                 }
 
                             }


Which would explain how it generates stone... I think, but i played around with that script for hours on end so how would i set up coal with it?

This is what i tried (FOR THAT SECTION OF CODE!)

 if (sunlit)
 
                             {
 
                                 blockType = BlockType.TopSoil;
 
                                 chunk.TopSoilBlocks.Add(new IntVect(blockX, blockY, z));
 
                                 sunlit = false;
 
                             }
 
                             else
 
                             {
 
                                 blockType = BlockType.Dirt;
 
                                 if (caveNoise < 0.2f)
 
                                 {
 
                                     
 
                                     
 
                                     if (random.RandomRange(1, 100) < 99)
 
                                         {
 
                                             blockType = BlockType.Coal;    
 
                                             
 
                                         }
 
                                     else
 
                                     {
 
                                         blockType = BlockType.Stone;
 
                                     }
 
                                         
 
                                 }
 
                             }


Which was basically a copy a paste from the terrain generation and i got this error

 Assets/MineCraft/Scripts/TerrainGenerationMethods/DualLayerTerrainWithMediumValleys.cs(61,77): error CS0103: The name `random' does not exist in the current context

So where that function began I put Random random, in between the parameters so it looked like this

 public void GenerateTerrain(WorldData worldData, Random random, Chunk chunk, int noiseBlockOffset)

Which sadly resulted in another error

 Assets/MineCraft/Scripts/TerrainGenerationMethods/DualLayerTerrainWithMediumValleys.cs(3,16): error CS0535: `DualLayerTerrainWithMediumValleys' does not implement interface member `ITerrainGenerationMethod.GenerateTerrain(WorldData, Chunk, int)'

After I put the random code in, before i added it to the parameters in when i started going with my gut so i have no idea if i was even doing it somewhat right.

Thanks in Advanced

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Rod-Green · Dec 30, 2011 at 12:52 AM

The tool is looking for a 'Random' class to generate the random values. Parsing in unity's random isn't going to work if they use different methods.

You could create a wrapper that wraps unity's Random class with a class of your own to translate their method calls into methods that exist in Unity's Random Class..

i.e.

 public class MC_Random()
 {
     private int m_seed = 1337;
 
     public MC_Random()
     {
         Random.seed = m_seed;
     }
     // not sure this is what they are requesting
     public float forRange(float p_min, float p_max)
     {
         float result = UnityEngine.Random.Range(p_min, p_max);
         // do other random code
         return result;
     }
 }
Comment
Add comment · Share
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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

ArgumentException: RandomRangeInt can only be called from the main thread. 1 Answer

Object reference not set to an instance of an object. 2 Answers

Script not working (Java script) 2 Answers

pre generated world 0 Answers

Index out of range for no reason? 1 Answer


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