Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/09/18 in all areas

  1. I have two properties in my block, LEVEL and FACING. I need to store the meta in order to save the properties. I have this code public int getMetaFromState(IBlockState state) { return ((Integer)state.getValue(LEVEL)).intValue(); } which saves LEVEL property. I need a way to save FACING property too.
    1 point
  2. Just ran across this example after reading this.
    1 point
  3. While developing the structure generation system for my mod I had the same problem. I solved it with a pretty complex system involving a chunk cache. It is not really completed yet, but maybe it helps you anyway. My mod replaces the vanilla (overworld) ChunkProvider with a modified one. Source on github (my mod changes some other worldgen related things too, sorry if it is hard to read or understand the code) How it works: - Structure data is saved in NBT format (similiar to vanilla structures) and loaded on server start - When a chunk is generated, it checks for suitable positions based on the conditions saved in the NBT data, for example a block at a specific position in the structure needs to be grass or dirt. If all conditions match, it adds the position to my StructurePositionMap and generates it in the world later during chunk population, chunk by chunk. StructurePositionMap source The problem: What happens when the condition block that needs to be checked is in a chunk that is not generated yet? My solution: If the chunk that needs to be checked has not been generated yet, the ChunkProvider just 'pre-generates' it and stores it in a cache, like this (ChunkProviderDoomed.getChunk) : public Chunk getChunk(int x, int z) { // called when checking structure conditions if (world.getChunkProvider().isChunkGeneratedAt(x, z)) { // if chunk is already generated, just retrieve it (vanilla) return world.getChunkFromChunkCoords(x, z); } else { long c = ChunkPos.asLong(x, z); // if not, try to get it from our own chunk cache if (chunkCache.containsKey(c)) { return chunkCache.get(c); // if it is cached, return it } else { return this.preGenerate(x, z); // if not, pre-generate it and put it into the cache } } } Then it performs the checks, and later when the chunk is actually generated by minecraft it just retrieves the chunk from the cache instead of generating it again: public Chunk generateChunk(int x, int z) { // (override: ChunkProvider) Chunk cached = getChunkFromCache(x, z, true); if (cached!=null) { // if chunk has been pre-generated, we dont need to generate it again this.createVanillaStructures(x, z, null); //create vanilla structure data, everything else is already done this.createStructures(x, z); return cached; } return this.generateChunk(x, z, false); // if not, generate it normally } However, I cant tell if this causes problems with vanilla structure generation (not tested yet) But so far, it worked for me without any problems or lag. I hope it helps
    1 point
  4. As far as I am concerned, any block variant that might exist gets an item, for the purposes of creative inventories and silk touch. The standard drop might be different and that's fine, but the variant should probably still have an Item version of itself. Again, whatever item that is supposed to be, you need to register a model for it. I can't tell you much more because your post is confusing as all get out.
    1 point
  5. You need to register the item model for all of your block variants. I do it like this: https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/hardlib/client/ClientEasyRegistry.java#L45-L54
    1 point
  6. Okay so after many frustrating attempts to make the previous code work, I gave up and decided to rewrite my class and came up with the code below. Unfortunately, this is causing some horrible tick-lag and I'm not quite sure what I can do about it. WorldGenModMinable.java package com.tehseph.sephsmod.worldgen; import com.tehseph.sephsmod.block.BlockMeta; import cpw.mods.fml.common.IWorldGenerator; import net.minecraft.block.Block; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.feature.WorldGenMinable; import java.util.Random; public class WorldGenModMinable implements IWorldGenerator { private int dimensionID; private Block replaceTarget; private Block oreBlock; private int veinSize, veinCount; private int minY, maxY; public WorldGenModMinable(int dimensionID, Block replaceTarget, Block oreBlock, int veinSize, int veinCount, int minY, int maxY) { this.dimensionID = dimensionID; this.replaceTarget = replaceTarget; this.oreBlock = oreBlock; this.veinSize = veinSize; this.veinCount = veinCount; this.minY = minY; this.maxY = maxY; } @Override public void generate(Random random, int chunkX, int chunkZ, World worldObj, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { if (worldObj.provider.dimensionId == this.dimensionID) { if (this.oreBlock instanceof BlockMeta) { for (int metadata = 0; metadata < ((BlockMeta) this.oreBlock).metaNames.length; metadata++) { for (int i = 0; i < this.veinCount; i++) { int randX = (chunkX * 16) + random.nextInt(16); int randZ = (chunkZ * 16) + random.nextInt(16); int randY = this.minY + random.nextInt(this.maxY - this.minY); (new WorldGenMinable(this.oreBlock, metadata, this.veinSize, this.replaceTarget)).generate(worldObj, random, randX, randY, randZ); } } } else { for (int i = 0; i < this.veinCount; i++) { int randX = (chunkX * 16) + random.nextInt(16); int randZ = (chunkZ * 16) + random.nextInt(16); int randY = this.minY + random.nextInt(this.maxY - this.minY); (new WorldGenMinable(this.oreBlock, this.veinSize, this.replaceTarget)).generate(worldObj, random, randX, randY, randZ); } } } } } So, my new problem is this: How can I optimize this to lower the ticking times? EDIT: So it appears after doing some research, the tick-lag is not my fault and is actually poor vanilla code changes made in 1.7.10. This post on the FTB forums has a few JVM arguments that can help combat the lag as well as a mention to FastCraft, a WIP mod written by IC2's Player that helps to greatly improve the ridiculous 1.7.10 chunk loading issues. I've left my metadata block generation code above just in case it helps anyone out who might have come across this thread, but all problems are (kind of) solved now. At least, everything in my code is solved.
    1 point
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.