@SubscribeEvent public void onEvent(ChunkProviderEvent.ReplaceBiomeBlocks event){ int dim = event.world.provider.getDimensionId(); if(this.replacedMapGensDimensions.contains(dim)){ //don't touch, we already replaced it return; } this.replacedMapGensDimensions.add(dim); IChunkProvider prov = event.chunkProvider; if(!(prov instanceof ChunkProviderGenerate)){ return; } List<Field> genFields = ReflectionUtil.getFieldsByType(MapGenBase.class, ChunkProviderGenerate.class, false); for(Field field : genFields){ MapGenBase value = ReflectionUtil.getValue(field, prov, MapGenBase.class); value = WorldGenUtil.tileableMapGen(value); ReflectionUtil.setValue(field, prov, value); } }
public static void generateTileable(MapGenBase base, IChunkProvider chunkProvider, // World worldIn, int chunkX, int chunkZ, ChunkPrimer blocks) { // radius is the inly int field in MapGenBase int radius = ReflectionUtil.getValueByType(int.class, MapGenBase.class, base, false); // set world Field worldField = ReflectionUtil.getFieldByType(World.class, MapGenBase.class, false); ReflectionUtil.setValue(worldField, base, worldIn); // This is the same rand instance that will be used by other generator Random rand = ReflectionUtil.getValueByType(Random.class, MapGenBase.class, base, false); rand.setSeed(worldIn.getSeed()); long randX = rand.nextLong(); long randZ = rand.nextLong(); int bitmask = Bits.bitmaskClamped(Config.loopBits(worldIn.provider.getDimensionId()) - 4); Method meth = ReflectionUtil.findMethod(MapGenBase.class, void.class, false, // World.class, int.class, int.class, int.class, int.class, ChunkPrimer.class); for (int xOrigin = chunkX - radius; xOrigin <= chunkX + radius; ++xOrigin) { for (int zOrigin = chunkZ - radius; zOrigin <= chunkZ + radius; ++zOrigin) { int xOriginMod = xOrigin & bitmask; int zOriginMod = zOrigin & bitmask; long xSeed = (long) xOriginMod * randX; long zSeedi2 = (long) zOriginMod * randZ; rand.setSeed(xSeed ^ zSeedi2 ^ worldIn.getSeed()); ReflectionUtil.invokeMethod(void.class, base, meth, // worldIn, xOrigin, zOrigin, chunkX, chunkZ, blocks); } } }
protected static BlockPos func_191069_a(World p_191069_0_, MapGenStructure p_191069_1_, BlockPos p_191069_2_, int p_191069_3_, int p_191069_4_, int p_191069_5_, boolean p_191069_6_, int p_191069_7_, boolean p_191069_8_) { int i = p_191069_2_.getX() >> 4; int j = p_191069_2_.getZ() >> 4; int k = 0; for (Random random = new Random(); k <= p_191069_7_; ++k) { for (int l = -k; l <= k; ++l) { boolean flag = l == -k || l == k; for (int i1 = -k; i1 <= k; ++i1) { boolean flag1 = i1 == -k || i1 == k; if (flag || flag1) { int j1 = i + p_191069_3_ * l; int k1 = j + p_191069_3_ * i1; if (j1 < 0) { j1 -= p_191069_3_ - 1; } if (k1 < 0) { k1 -= p_191069_3_ - 1; } int l1 = j1 / p_191069_3_; int i2 = k1 / p_191069_3_; Random random1 = p_191069_0_.setRandomSeed(l1, i2, p_191069_5_); l1 = l1 * p_191069_3_; i2 = i2 * p_191069_3_; if (p_191069_6_) { l1 = l1 + (random1.nextInt(p_191069_3_ - p_191069_4_) + random1.nextInt(p_191069_3_ - p_191069_4_)) / 2; i2 = i2 + (random1.nextInt(p_191069_3_ - p_191069_4_) + random1.nextInt(p_191069_3_ - p_191069_4_)) / 2; } else { l1 = l1 + random1.nextInt(p_191069_3_ - p_191069_4_); i2 = i2 + random1.nextInt(p_191069_3_ - p_191069_4_); } MapGenBase.func_191068_a(p_191069_0_.getSeed(), random, l1, i2); random.nextInt(); if (p_191069_1_.canSpawnStructureAtCoords(l1, i2)) { if (!p_191069_8_ || !p_191069_0_.func_190526_b(l1, i2)) { return new BlockPos((l1 << 4) + 8, 64, (i2 << 4) + 8); } } else if (k == 0) { break; } } } if (k == 0) { break; } } } return null; }
public static MapGenBase getModdedMapGen(MapGenBase original, InitMapGenEvent.EventType type) { InitMapGenEvent event = new InitMapGenEvent(type, original); MinecraftForge.TERRAIN_GEN_BUS.post(event); return event.getNewGen(); }
InitMapGenEvent(EventType type, MapGenBase original) { this.type = type; this.originalGen = original; this.setNewGen(original); }
public static MapGenBase getModdedMapGen(MapGenBase original, InitMapGenEvent.EventType type) { InitMapGenEvent event = new InitMapGenEvent(type, original); MinecraftForge.TERRAIN_GEN_BUS.post(event); return event.newGen; }
InitMapGenEvent(EventType type, MapGenBase original) { this.type = type; this.originalGen = original; this.newGen = original; }
public static MapGenBase tileableMapGen(MapGenBase originalGen) { logger.info("Creating new Generator for typr: " + originalGen.getClass()); return new MapGenTileable(originalGen); }
public MapGenTileable(MapGenBase generator){ this.generator = generator; }
public MapGenDeadzone(MapGenBase base) { this.childGen = base; }
InitMapGenEventRunes(EventType type, MapGenBase original) { this.type = type; this.originalGen = original; this.newGen = original; }
public MapGenBase getOriginalGen() { return originalGen; }
public MapGenBase getNewGen() { return newGen; }
public void setNewGen(MapGenBase newGen) { this.newGen = newGen; }