Skip to content

Commit

Permalink
Fixed bug where spawn protection and biome black listing was applied …
Browse files Browse the repository at this point in the history
…to the chunk not the whole dungeon
  • Loading branch information
BlackJar72 committed Jun 15, 2021
1 parent 701538a commit ea60842
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 32 deletions.
7 changes: 7 additions & 0 deletions main/java/jaredbgreat/dldungeons/ConfigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


import jaredbgreat.dldungeons.builder.Builder;
import jaredbgreat.dldungeons.builder.RegisteredBlock;
import jaredbgreat.dldungeons.pieces.chests.BasicChest;
import jaredbgreat.dldungeons.pieces.chests.TreasureChest;
import jaredbgreat.dldungeons.planner.mapping.MapMatrix;
Expand Down Expand Up @@ -595,4 +596,10 @@ private static void processBiomeExclusions(String[] array) {
public static String getConfigDir() {
return configDir + File.separator;
}


public static void listDBlocks() {
RegisteredBlock.listDBlocks(listsDir);
}

}
1 change: 1 addition & 0 deletions main/java/jaredbgreat/dldungeons/DoomlikeDungeons.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void postInit(FMLPostInitializationEvent event) {
ConfigHandler.generateLists();
ThemeReader.readThemes();
ThemeType.SyncMobLists();
//ConfigHandler.listDBlocks();
}

@EventHandler
Expand Down
37 changes: 13 additions & 24 deletions main/java/jaredbgreat/dldungeons/GenerationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,13 @@ public void generate(Random random, int chunkX, int chunkZ, World world,
// Prevent bad spawns
if(world.isRemote) return;
if((ConfigHandler.obeyRule && !world.getWorldInfo().isMapFeaturesEnabled())
|| !ConfigHandler.naturalSpawn) return;
boolean blockedBiome = false;
Set<Type> types = BiomeDictionary.getTypes((world.getBiome(new BlockPos(chunkX * 16, 63, chunkZ * 16))));
for(Type type : types) {
blockedBiome = ConfigHandler.biomeExclusions.contains(type) || blockedBiome;
}
if(blockedBiome) return;
if((dimensions.contains(Integer.valueOf(world.provider.getDimension())) != ConfigHandler.positiveDims)) return;
if((Math.abs(chunkX - (world.getSpawnPoint().getX() / 16)) < minXZ)
|| (Math.abs(chunkZ - (world.getSpawnPoint().getZ() / 16)) < minXZ)) return;

mrand = new Random(world.getSeed() + world.provider.getDimension()
+ (2027 * (long)(chunkX / factor))
+ (1987 * (long)(chunkZ / factor)));
int xrand = mrand.nextInt();
int zrand = mrand.nextInt();
int xuse = ((chunkX + xrand) % factor);
int zuse = ((chunkZ + zrand) % factor);

//Find if a dungeon is here
//buildDungeonHere(world, chunkGenerator, chunkProvider, chunkX, chunkZ);
|| !ConfigHandler.naturalSpawn) return;
findDungeonsToBuild(world, chunkX, chunkZ);
}


private void buildDungeonHere(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, int chunkX, int chunkZ) {
if(isDungeonCenter(world.getSeed(), chunkX, chunkZ, world.provider.getDimension())) {
if(isDungeonCenter(world, world.getSeed(), chunkX, chunkZ, world.provider.getDimension())) {
try {
placeDungeon(chunkX, chunkZ, world);
} catch (Throwable e) {
Expand All @@ -121,7 +101,7 @@ private void findDungeonsToBuild(final World world, final int chunkX, final int
int sz = chunkZ - Sizes.HUGE.chunkRadius, ez = chunkZ + Sizes.HUGE.chunkRadius;
for(int i = sx; i <= ex; i++)
for(int j = sz; j <= ez; j++) {
if(isDungeonCenter(seed, i, j, dim)) {
if(isDungeonCenter(world, seed, i, j, dim)) {
dungeonLocs.add(new Coords(i, j, dim));
}
}
Expand All @@ -135,7 +115,16 @@ private void findDungeonsToBuild(final World world, final int chunkX, final int



private boolean isDungeonCenter(long seed, int chunkX, int chunkZ, int dim) {
private boolean isDungeonCenter(World world, long seed, int chunkX, int chunkZ, int dim) {
boolean blockedBiome = false;
Set<Type> types = BiomeDictionary.getTypes((world.getBiome(new BlockPos(chunkX * 16, 63, chunkZ * 16))));
for(Type type : types) {
blockedBiome = ConfigHandler.biomeExclusions.contains(type) || blockedBiome;
}
if(blockedBiome) return false;
if((dimensions.contains(Integer.valueOf(world.provider.getDimension())) != ConfigHandler.positiveDims)) return false;
if((Math.abs(chunkX - (world.getSpawnPoint().getX() / 16)) < minXZ)
|| (Math.abs(chunkZ - (world.getSpawnPoint().getZ() / 16)) < minXZ)) return false;
mrand = new Random(seed + dim
+ (2027 * (long)(chunkX / factor))
+ (1987 * (long)(chunkZ / factor)));
Expand Down
2 changes: 1 addition & 1 deletion main/java/jaredbgreat/dldungeons/Info.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public final class Info {
public static final String OLD_ID = "DLDungeonsJBG";
public static final String ID = "dldungeonsjbg";
public static final String NAME = "Doomlike Dungeons";
public static final String VERSION = "1.14.5";
public static final String VERSION = "1.14.6";
public static final String MINECRAFT = "1.12.2";
public static final String CHANNEL = "JBGDungeons";
public static final String LOG_NAME = "DLDUNGEONS";
Expand Down
3 changes: 2 additions & 1 deletion main/java/jaredbgreat/dldungeons/api/DLDungeonsAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ public static void reloadConfig() {
* 0: Common Mobs (e.g., zombie, skeleton, spider)
* 1: Tough Mobs (e.g., creeper, blaze, enderman, cave spider)
* 2: Brute Mobs (e.g., witch, tougher Lycanite's Mobs, most Dungeons Mobs)
* 3: Elite Mobs (e.g., bosses, mini-bosses, MineFantasy dragon and knights)
* 3: Elite Mobs (e.g., mini-bosses, MineFantasy dragon and knights)
* 4: Boss Mobs (e.g., things comparable to The With and Ender Dragon)
*
* Valid theme types are similar to biome types from the Forge biome dictionary, and
* have many names in common. You can list as many as needed.
Expand Down
3 changes: 3 additions & 0 deletions main/java/jaredbgreat/dldungeons/builder/AbstractBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ public static boolean isProtectedBlock(World world, int x, int y, int z) {
return (block == chestid || block == spawnerid
|| block == portal1id || block == portal2id || block == bedrockId);
}




}
41 changes: 36 additions & 5 deletions main/java/jaredbgreat/dldungeons/builder/RegisteredBlock.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package jaredbgreat.dldungeons.builder;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.NoSuchElementException;

/*
* Doomlike Dungeons by is licensed the MIT License
* Copyright (c) 2014-2018 Jared Blackburn
*/

import jaredbgreat.dldungeons.api.DLDEvent;
import jaredbgreat.dldungeons.util.debug.Logging;

import java.util.ArrayList;
import java.util.NoSuchElementException;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
Expand All @@ -37,6 +42,7 @@ public final class RegisteredBlock extends AbstractBlock {
// All blocks, complete with meta-data used by the mod
public static final ArrayList<RegisteredBlock> registry = new ArrayList<RegisteredBlock>();

private static HashSet<String> names = new HashSet<>();

/**
* Gets the item named by the string "in" -- hacky, but might work
Expand All @@ -56,7 +62,8 @@ private static Item getItem(String in) {
*
* @param id
*/
private RegisteredBlock(String id) throws NoSuchElementException {
private RegisteredBlock(String id) throws NoSuchElementException {
names.add(id);
this.id = id;
block = DBlock.makeDBlock(id);
if(block.toString().contains("minecraft:air")
Expand All @@ -69,6 +76,30 @@ private RegisteredBlock(String id) throws NoSuchElementException {
}


public static void listDBlocks(File listsDir) {
ArrayList<String> namel = new ArrayList<>();
names.forEach( (name) -> namel.add(name) ) ;
Collections.sort(namel);
File itemlist = new File(listsDir.toString() + File.separator + "DBlocks.txt");
if(itemlist.exists()) itemlist.delete();
try {
final BufferedWriter outstream
= new BufferedWriter(new FileWriter(itemlist.toString()));

for(String name : namel) {
outstream.write(name);
outstream.newLine();
}

if(outstream != null) outstream.close();
} catch (IOException e) {
System.err.println("Error: Could not write file blocks.txt");
e.printStackTrace();
}
}



/**
* Construct a dungeon block using a theme format from version 1.7 of the mod
* or newer.
Expand Down
2 changes: 1 addition & 1 deletion main/resources/mcmod.info
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"modid": "dldungeonsjbg",
"name": "Doomlike Dungeons",
"description": "Procedurally generates multiroom dungeons resembling Doom levels into the world.",
"version": "1.14.5",
"version": "1.14.6",
"mcversion": "1.12.2",
"url": "http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/1293843-doomlike-dungeons",
"updateUrl": "",
Expand Down

0 comments on commit ea60842

Please sign in to comment.