-
Recently Browsing
No registered users viewing this page.
-
Posts
-
By gendeathrow · Posted
Just to give an updated on this. I did finally get the block to replace other blocks. This is more of a demo than what I'm actually doing. Replacing water with a new type of water does not have the intended effects that I would like. As I think it breaks some of the game mechanics now. I will still play around with it. But the code for anyone else that would like to try this for their projects. This doesn't feel like the most cleanest way of doing it. Seems a bit heavy scanning each block in a chunk again. But it works. public class FluidGenReplace extends Feature<NoFeatureConfig> { public FluidGenReplace(Function<Dynamic<?>, ? extends NoFeatureConfig> configFactoryIn) { super(configFactoryIn); } public static Block fromBlock = Blocks.WATER; // change this to suit your need public static Block toBlock = Blocks.SLIME_BLOCK; // change this to suit your need @Override public boolean place(IWorld worldIn, ChunkGenerator<? extends GenerationSettings> generator, Random rand, BlockPos pos, NoFeatureConfig config) { try { IChunk currentChunk = worldIn.getChunk(pos); // get Chunk int startX = currentChunk.getPos().getXStart(); // get starting X of chunk int startZ = currentChunk.getPos().getZStart(); // get starting Z of chunk int endX = currentChunk.getPos().getXEnd(); // get ending X of chunk int endZ = currentChunk.getPos().getZEnd(); // get ending Z of chunk int startY = 0; // get starting X of chunk (In this case 0) int endY = worldIn.getSeaLevel(); // get ending X of chunk (only replacing up to sea level to reduce amount of scaninng. ) for (int x = startX; x <= endX; ++x) { for (int z = startZ; z <= endZ; ++z) { for (int y = startY; y <= endY; ++y) { BlockState state = worldIn.getBlockState(new BlockPos(x, y, z)); Block block = state.getBlock(); if (block == fromBlock) { worldIn.setBlockState(new BlockPos(x, y, z), toBlock.getDefaultState(), 2); } } } } } catch (Exception e) { } return false; } }
-
-
Topics
-
Who's Online (See full list)