Skip to content

Commit

Permalink
Fix deepslate AGAIN?
Browse files Browse the repository at this point in the history
  • Loading branch information
Roadhog360 committed Nov 16, 2021
1 parent 412b3af commit d5f00d0
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 158 deletions.
4 changes: 4 additions & 0 deletions src/main/java/ganymedes01/etfuturum/EtFuturum.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ else if(block == Blocks.quartz_ore || (namespace.contains("nether") && (block in
return ModSounds.soundNetherOre;
}

else if(namespace.contains("deepslate")) {
return namespace.contains("brick") ? ModSounds.soundDeepslateBricks : ModSounds.soundDeepslate;
}

else if(block instanceof BlockNetherWart || (namespace.contains("nether") && namespace.contains("wart"))) {
return ModSounds.soundCropWarts;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ganymedes01.etfuturum.blocks;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

Expand All @@ -13,7 +12,7 @@
import ganymedes01.etfuturum.configuration.configs.ConfigWorld;
import ganymedes01.etfuturum.core.utils.Utils;
import ganymedes01.etfuturum.entities.ai.BlockPos;
import ganymedes01.etfuturum.world.EtFuturumChunkPopulateGenerator;
import ganymedes01.etfuturum.world.EtFuturumLateWorldGenerator;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRotatedPillar;
import net.minecraft.block.material.Material;
Expand Down Expand Up @@ -75,12 +74,10 @@ public boolean isReplaceableOreGen(World world, int x, int y, int z, Block targe
return flag;
}

private static List<BlockPos> tempcache = new ArrayList<BlockPos>();

public static void doDeepslateRedoCheck(World world, int x, int y, int z) {
if(!EtFuturumChunkPopulateGenerator.INSTANCE.stopRecording && world.checkChunksExist(x, 0, z, x, 0, z) && world.getChunkFromBlockCoords(x, z).lastSaveTime == 0) {
if(!EtFuturumLateWorldGenerator.stopRecording && world.checkChunksExist(x, 0, z, x, 0, z) && world.getChunkFromBlockCoords(x, z).lastSaveTime == 0) {
BlockPos pos = new BlockPos(x, y, z);
List<BlockPos> redo = EtFuturumChunkPopulateGenerator.INSTANCE.getRedoList(world.provider.dimensionId);
List<BlockPos> redo = EtFuturumLateWorldGenerator.getRedoList(world.provider.dimensionId);
if(!redo.contains(pos)) {
redo.add(pos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import ganymedes01.etfuturum.network.BlackHeartParticlesMessage;
import ganymedes01.etfuturum.recipes.ModRecipes;
import ganymedes01.etfuturum.tileentities.TileEntityGateway;
import ganymedes01.etfuturum.world.EtFuturumChunkPopulateGenerator;
import ganymedes01.etfuturum.world.EtFuturumLateWorldGenerator;
import ganymedes01.etfuturum.world.generate.BlockAndMetadataMapping;
import ganymedes01.etfuturum.world.generate.RawOreDropMapping;
import net.minecraft.block.Block;
Expand Down Expand Up @@ -1123,11 +1123,6 @@ public void onDrops(BlockEvent.HarvestDropsEvent event) {
}
}

@SubscribeEvent
public void onUnload(WorldEvent.Unload event) {
EtFuturumChunkPopulateGenerator.INSTANCE.clearRedos();
}

// UNUSED FUNCTIONS
//private boolean playerHasItem(final EntityPlayer player, final ItemStack ist, final boolean checkEnabled) {
// for (int slot = 0; slot < player.inventory.mainInventory.length; ++slot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import ganymedes01.etfuturum.EtFuturum;
import ganymedes01.etfuturum.EtFuturumMixinPlugin;
import ganymedes01.etfuturum.client.gui.inventory.GuiAnvil;
import ganymedes01.etfuturum.client.gui.inventory.GuiBlastFurnace;
import ganymedes01.etfuturum.client.gui.inventory.GuiEnchantment;
Expand All @@ -18,7 +17,6 @@
import ganymedes01.etfuturum.configuration.configs.ConfigBlocksItems;
import ganymedes01.etfuturum.configuration.configs.ConfigEntities;
import ganymedes01.etfuturum.configuration.configs.ConfigTweaks;
import ganymedes01.etfuturum.core.handlers.ClientEventHandler;
import ganymedes01.etfuturum.core.handlers.ServerEventHandler;
import ganymedes01.etfuturum.core.handlers.WorldEventHandler;
import ganymedes01.etfuturum.core.utils.Utils;
Expand Down Expand Up @@ -57,7 +55,6 @@
import ganymedes01.etfuturum.tileentities.TileEntityShulkerBox;
import ganymedes01.etfuturum.tileentities.TileEntitySmoker;
import ganymedes01.etfuturum.tileentities.TileEntityWoodSign;
import ganymedes01.etfuturum.world.EtFuturumChunkPopulateGenerator;
import net.minecraft.client.gui.inventory.GuiChest;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.monster.EntityEnderman;
Expand All @@ -82,9 +79,6 @@ public void registerEvents() {
MinecraftForge.EVENT_BUS.register(ServerEventHandler.INSTANCE);

FMLCommonHandler.instance().bus().register(WorldEventHandler.INSTANCE);

MinecraftForge.ORE_GEN_BUS.register(EtFuturumChunkPopulateGenerator.INSTANCE);
MinecraftForge.EVENT_BUS.register(EtFuturumChunkPopulateGenerator.INSTANCE);
}

public void registerEntities() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
package ganymedes01.etfuturum.world;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.apache.commons.lang3.ArrayUtils;

import ganymedes01.etfuturum.ModBlocks;
import ganymedes01.etfuturum.configuration.configs.ConfigBlocksItems;
import ganymedes01.etfuturum.configuration.configs.ConfigTweaks;
import ganymedes01.etfuturum.configuration.configs.ConfigWorld;
import ganymedes01.etfuturum.core.utils.DeepslateOreRegistry;
import ganymedes01.etfuturum.entities.ai.BlockPos;
import ganymedes01.etfuturum.world.generate.BlockAndMetadataMapping;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraft.world.WorldType;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;

public class EtFuturumLateWorldGenerator extends EtFuturumWorldGenerator {

@Override
public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
int worldX = chunkX * 16;
int worldZ = chunkZ * 16;
if (world.getWorldInfo().getTerrainType() != WorldType.FLAT && ConfigBlocksItems.enableCoarseDirt && world.provider.dimensionId != -1 && world.provider.dimensionId != 1) {
//TODO Add checks so it doesn't run this code in biomes that don't generate coarse dirt
for (int x = chunkX * 16; x < (chunkX * 16) + 16; x++) {
Expand All @@ -35,5 +51,102 @@ public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkPro
generateOre(tuffGen, world, rand, chunkX, chunkZ, 1, 6, ConfigWorld.deepslateMaxY);
}
}

//Because the variables are misnamed and these are world coords, not chunk coords...
if(doesChunkSupportLayerDeepslate(world.getWorldInfo().getTerrainType(), world.provider.dimensionId)) {
stopRecording = true;
final List<BlockPos> redo = getRedoList(world.provider.dimensionId);
if(!redo.isEmpty()) {
//Turn off recording here so the world gen isn't an infinite recursion loop of constantly checking the same blocks
Chunk newChunk = null;
//Iterate this way to avoid ConcurrentModificationException
for(int i = redo.size() - 1; i >= 0; i--) {
BlockPos pos = redo.get(i);
int chunkPosX = pos.getX() >> 4;
int chunkPosZ = pos.getZ() >> 4;
if(newChunk == null || newChunk.xPosition != chunkPosX || newChunk.zPosition != chunkPosZ) {
newChunk = world.getChunkFromChunkCoords(chunkPosX, chunkPosZ);
}
this.replaceBlockInChunk(newChunk, pos.getX() & 15, pos.getZ() & 15, pos.getX(), pos.getY(), pos.getZ());
}
redo.clear();
}

Chunk chunk = world.getChunkFromChunkCoords(chunkX, chunkZ);
doDeepslateGen(chunk);
stopRecording = false;
}
}


private void doDeepslateGen(Chunk chunk) {

Block block;

int worldX;
int worldZ;
final int chunkMultiplier = chunk.xPosition * 16;

for (int y = 0; y <= ConfigWorld.deepslateMaxY; y++) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
if(y < ConfigWorld.deepslateMaxY - 4 || y <= ConfigWorld.deepslateMaxY - chunk.worldObj.rand.nextInt(4)) {

block = chunk.getBlock(x, y, z);

worldX = x + chunkMultiplier;
worldZ = z + chunkMultiplier;

this.replaceBlockInChunk(chunk, block, x, z, worldX, y, worldZ);
}
}
}
}
}

private void replaceBlockInChunk(Chunk chunk, int x, int z, int worldX, int worldY, int worldZ) {
this.replaceBlockInChunk(chunk, chunk.getBlock(x, worldY, z), x, z, worldX, worldY, worldZ);
}

private void replaceBlockInChunk(Chunk chunk, Block block, int x, int z, int worldX, int worldY, int worldZ) {
if(block.getMaterial() != Material.air && block != ModBlocks.deepslate && block != ModBlocks.tuff && block != ModBlocks.cobbled_deepslate) {
if((block.isReplaceableOreGen(chunk.worldObj, worldX , worldY, worldZ, Blocks.stone) && (ConfigWorld.deepslateReplacesStones || block != ModBlocks.stone))
|| (ConfigWorld.deepslateReplacesDirt && block == Blocks.dirt)) {
chunk.func_150807_a(x, worldY, z, ModBlocks.deepslate, 0);
} else if(ConfigTweaks.deepslateReplacesCobblestone && block.isReplaceableOreGen(chunk.worldObj, worldX, worldY, worldZ, Blocks.cobblestone)) {
chunk.func_150807_a(x, worldY, z, ModBlocks.cobbled_deepslate, 0);
} else if(!DeepslateOreRegistry.getOreMap().isEmpty()) {
BlockAndMetadataMapping mapping;
if((mapping = DeepslateOreRegistry.getOre(block, chunk.getBlockMetadata(x, worldY, z))) != null) {
chunk.func_150807_a(x, worldY, z, mapping.getBlock(), mapping.getMeta());
}
}
}
}

private static final Map<Integer, List<BlockPos>> redos = new HashMap<Integer, List<BlockPos>>();
public static boolean stopRecording;

public static void clearRedos() {
redos.clear();
}

public static List<BlockPos> getRedoList(int dim) {
if(redos.get(dim) == null) {
redos.put(dim, new ArrayList<BlockPos>());
}
return redos.get(dim);
}

private boolean doesChunkSupportLayerDeepslate(WorldType terrain, int dimId) {
if(ConfigBlocksItems.enableDeepslate) {
if (ConfigWorld.deepslateGenerationMode == 0 && ConfigWorld.deepslateMaxY > 0) {
if(terrain != WorldType.FLAT && !ArrayUtils.contains(ConfigWorld.deepslateLayerDimensionBlacklist, dimId)) {
return true;
}
}
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ public class EtFuturumWorldGenerator implements IWorldGenerator {

protected final WorldGenMinable magmaGen = new WorldGenMinable(ModBlocks.magma_block, ConfigWorld.maxMagmaPerCluster, Blocks.netherrack);
protected final WorldGenMinable netherGoldGen = new WorldGenMinable(ModBlocks.nether_gold_ore, ConfigWorld.maxNetherGoldPerCluster, Blocks.netherrack);
protected final WorldGenMinable debrisGen = new WorldGenMinableCustom(ConfigWorld.debrisMax);
protected final WorldGenMinable smallDebrisGen = new WorldGenMinableCustom(ConfigWorld.smallDebrisMax);
protected final WorldGenMinable debrisGen = new WorldGenMinableCustom(ModBlocks.ancient_debris, ConfigWorld.debrisMax, Blocks.netherrack);
protected final WorldGenMinable smallDebrisGen = new WorldGenMinableCustom(ModBlocks.ancient_debris, ConfigWorld.smallDebrisMax, Blocks.netherrack);

protected final WorldGenMinable deepslateBlobGen = new WorldGenDeepslateLayerBlob(ConfigWorld.maxDeepslatePerCluster, false);
protected final WorldGenMinable tuffGen = new WorldGenDeepslateLayerBlob(ConfigWorld.maxDeepslatePerCluster, true);

public EtFuturumWorldGenerator() {
stoneGen.add(new WorldGenMinable(ModBlocks.stone, 1, ConfigWorld.maxStonesPerCluster, Blocks.stone));
stoneGen.add(new WorldGenMinable(ModBlocks.stone, 3, ConfigWorld.maxStonesPerCluster, Blocks.stone));
stoneGen.add(new WorldGenMinable(ModBlocks.stone, 5, ConfigWorld.maxStonesPerCluster, Blocks.stone));
stoneGen.add(new WorldGenMinableCustom(ModBlocks.stone, 1, ConfigWorld.maxStonesPerCluster, Blocks.stone));
stoneGen.add(new WorldGenMinableCustom(ModBlocks.stone, 3, ConfigWorld.maxStonesPerCluster, Blocks.stone));
stoneGen.add(new WorldGenMinableCustom(ModBlocks.stone, 5, ConfigWorld.maxStonesPerCluster, Blocks.stone));
flowers.add(new WorldGenFlowers(ModBlocks.lily_of_the_valley));
flowers.add(new WorldGenFlowers(ModBlocks.cornflower));
flowers.add(new WorldGenFlowers(ModBlocks.sweet_berry_bush));
Expand Down
Loading

0 comments on commit d5f00d0

Please sign in to comment.