/** * Changes a village to a sandstone village. (Just sets the first * boolean it can find in the WorldGenVillageStartPiece.class to * sandstoneVillage.) * * @param subject The village. * @param sandstoneVillage Whether the village should be a sandstone * village. */ private void changeToSandstoneVillage(WorldGenVillageStartPiece subject, boolean sandstoneVillage) { ReflectionHelper.setValueInFieldOfType(subject, boolean.class, sandstoneVillage); }
private void injectInternalChunkGenerator(CustomChunkGenerator chunkGenerator) { ChunkProviderServer chunkProvider = this.world.getChunkProviderServer(); ChunkGenerator oldChunkGenerator = chunkProvider.chunkGenerator; if (oldChunkGenerator instanceof CustomChunkGenerator) { ReflectionHelper.setValueInFieldOfType(chunkProvider, ChunkGenerator.class, chunkGenerator); } }
public TXStrongholdGen(ServerConfigProvider configs) { super(ImmutableMap.of( "distance", String.valueOf(configs.getWorldConfig().strongholdDistance), "count", String.valueOf(configs.getWorldConfig().strongholdCount), "spread", String.valueOf(configs.getWorldConfig().strongholdSpread))); // Modify in which biomes the stronghold is allowed to spawn List<BiomeBase> allowedBiomes = Lists.newArrayList(); for (LocalBiome biome : configs.getBiomeArray()) { if (biome == null) continue; if (biome.getBiomeConfig().strongholdsEnabled) { allowedBiomes.add(((BukkitBiome) biome).getHandle()); } } ReflectionHelper.setValueInFieldOfType(this, List.class, allowedBiomes); }
private void injectWorldChunkManager(BiomeGenerator biomeGenerator) { if (biomeGenerator instanceof BukkitVanillaBiomeGenerator) { // Let our biome generator depend on Minecraft's ((BukkitVanillaBiomeGenerator) biomeGenerator).setWorldChunkManager(this.world.worldProvider.k()); } else { // Let Minecraft's biome generator depend on ours ReflectionHelper.setValueInFieldOfType(this.world.worldProvider, WorldChunkManager.class, new TXWorldChunkManager(this, biomeGenerator)); } }
/** * Gets the appropriate BiomeGenerator. For the vanilla biome generator we * have to use BiomeGenerator, for other biome modes TCBiomeProvider is * the right option. * * @param tcWorld ForgeWorld instance, needed to instantiate the * BiomeGenerator. * @param biomeGenerator Biome generator. * @return The most appropriate BiomeGenerator. */ private BiomeProvider createBiomeProvider(ForgeWorld tcWorld, BiomeGenerator biomeGenerator) { final World world = tcWorld.getWorld(); BiomeProvider biomeProvider; if (biomeGenerator instanceof ForgeVanillaBiomeGenerator) { biomeProvider = world.provider.getBiomeProvider(); // Let our biome generator depend on Minecraft's ((ForgeVanillaBiomeGenerator) biomeGenerator).setBiomeProvider(biomeProvider); } else { biomeProvider = new TXBiomeProvider(tcWorld, biomeGenerator); // Let Minecraft's biome generator depend on ours ReflectionHelper.setValueInFieldOfType(world.provider, BiomeProvider.class, biomeProvider); } return biomeProvider; }
/** * Simple use case: change a field. The same (somewhat problematic) field as * in {@link #testActuallyNotAmbiguousGet()} is used. */ @Test public void testSet() { Monkey monkey = new Monkey(); // First change field the normal way monkey.isClimbing = false; assertEquals(false, monkey.isClimbing); // Then set it back using reflection ReflectionHelper.setValueInFieldOfType(monkey, boolean.class, true); assertEquals(true, monkey.isClimbing); } }