moved BlockMatcher configuration into main config file
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package mods.betterfoliage.client;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
@@ -43,11 +42,6 @@ public class BetterFoliageClient {
|
||||
public static LeafParticleTextures leafParticles = new LeafParticleTextures(0);
|
||||
public static WindTracker wind = new WindTracker();
|
||||
|
||||
public static BlockMatcher leaves = new BlockMatcher();
|
||||
public static BlockMatcher crops = new BlockMatcher();
|
||||
public static BlockMatcher dirt = new BlockMatcher();
|
||||
public static BlockMatcher grass = new BlockMatcher();
|
||||
|
||||
public static void preInit() {
|
||||
FMLCommonHandler.instance().bus().register(new KeyHandler());
|
||||
FMLCommonHandler.instance().bus().register(new Config());
|
||||
@@ -66,17 +60,10 @@ public class BetterFoliageClient {
|
||||
MinecraftForge.EVENT_BUS.register(wind);
|
||||
FMLCommonHandler.instance().bus().register(wind);
|
||||
|
||||
leaves.load(new File(BetterFoliage.configDir, "classesLeaves.cfg"), new ResourceLocation("betterfoliage:classesLeavesDefault.cfg"));
|
||||
MinecraftForge.EVENT_BUS.register(leaves);
|
||||
|
||||
crops.load(new File(BetterFoliage.configDir, "classesCrops.cfg"), new ResourceLocation("betterfoliage:classesCropsDefault.cfg"));
|
||||
MinecraftForge.EVENT_BUS.register(crops);
|
||||
|
||||
dirt.load(new File(BetterFoliage.configDir, "classesDirt.cfg"), new ResourceLocation("betterfoliage:classesDirtDefault.cfg"));
|
||||
MinecraftForge.EVENT_BUS.register(dirt);
|
||||
|
||||
grass.load(new File(BetterFoliage.configDir, "classesGrass.cfg"), new ResourceLocation("betterfoliage:classesGrassDefault.cfg"));
|
||||
MinecraftForge.EVENT_BUS.register(grass);
|
||||
MinecraftForge.EVENT_BUS.register(Config.leaves);
|
||||
MinecraftForge.EVENT_BUS.register(Config.crops);
|
||||
MinecraftForge.EVENT_BUS.register(Config.dirt);
|
||||
MinecraftForge.EVENT_BUS.register(Config.grass);
|
||||
|
||||
BetterFoliage.log.info("Registering texture generators");
|
||||
MinecraftForge.EVENT_BUS.register(leafGenerator);
|
||||
@@ -110,7 +97,7 @@ public class BetterFoliageClient {
|
||||
|
||||
public static void onRandomDisplayTick(Block block, World world, int x, int y, int z) {
|
||||
if (!Config.leafFXEnabled) return;
|
||||
if (!leaves.matchesID(block) || !world.isAirBlock(x, y - 1, z)) return;
|
||||
if (!Config.leaves.matchesID(block) || !world.isAirBlock(x, y - 1, z)) return;
|
||||
if (Math.random() > Config.leafFXChance) return;
|
||||
Minecraft.getMinecraft().effectRenderer.addEffect(new EntityFXFallingLeaves(world, x, y, z));
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package mods.betterfoliage.client;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.common.util.Utils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
@@ -23,16 +23,7 @@ public class BlockMatcher {
|
||||
public Set<Class<?>> whiteList = Sets.newHashSet();
|
||||
public Set<Class<?>> blackList = Sets.newHashSet();
|
||||
public Set<Integer> blockIDs = Sets.newHashSet();
|
||||
|
||||
public void addClass(String className) {
|
||||
try {
|
||||
if (className.startsWith("-"))
|
||||
blackList.add(Class.forName(className.substring(1)));
|
||||
else
|
||||
whiteList.add(Class.forName(className));
|
||||
} catch(ClassNotFoundException e) {}
|
||||
}
|
||||
|
||||
|
||||
public boolean matchesClass(Block block) {
|
||||
for (Class<?> clazz : blackList) if (clazz.isAssignableFrom(block.getClass())) return false;
|
||||
for (Class<?> clazz : whiteList) if (clazz.isAssignableFrom(block.getClass())) return true;
|
||||
@@ -47,43 +38,56 @@ public class BlockMatcher {
|
||||
return blockIDs.contains(Block.blockRegistry.getIDForObject(block));
|
||||
}
|
||||
|
||||
public void load(File file, ResourceLocation defaults) {
|
||||
if (!file.exists()) try {
|
||||
Utils.copyFromTextResource(defaults, file);
|
||||
} catch (IOException e) {
|
||||
BetterFoliage.log.error(String.format("Error copying default resource: %s", defaults.toString()));
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(file));
|
||||
whiteList.clear();
|
||||
blackList.clear();
|
||||
String line = reader.readLine();
|
||||
while(line != null) {
|
||||
addClass(line.trim());
|
||||
line = reader.readLine();
|
||||
}
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
BetterFoliage.log.warn(String.format("Error reading configuration: %s", file.getName()));
|
||||
}
|
||||
public void updateClassLists(String[] newWhitelist, String[] newBlacklist) {
|
||||
whiteList.clear();
|
||||
for(String className : newWhitelist) try {
|
||||
whiteList.add(Class.forName(className));
|
||||
} catch(ClassNotFoundException e) {}
|
||||
|
||||
blackList.clear();
|
||||
for(String className : newBlacklist) try {
|
||||
blackList.add(Class.forName(className));
|
||||
} catch(ClassNotFoundException e) {}
|
||||
|
||||
updateBlockIDs();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void updateBlockIDs() {
|
||||
blockIDs.clear();
|
||||
Iterator<Block> iter = Block.blockRegistry.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Block block = iter.next();
|
||||
if (matchesClass(block)) blockIDs.add(Block.blockRegistry.getIDForObject(block));
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadDefaultLists(ResourceLocation defaults, Collection<String> blacklist, Collection<String> whitelist) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new InputStreamReader(Minecraft.getMinecraft().getResourceManager().getResource(defaults).getInputStream(), Charsets.UTF_8));
|
||||
String line = reader.readLine();
|
||||
while(line != null) {
|
||||
line = line.trim();
|
||||
if (!line.isEmpty() && !line.startsWith("//")) {
|
||||
if (line.startsWith("-"))
|
||||
blacklist.add(line.substring(1));
|
||||
else
|
||||
whitelist.add(line);
|
||||
}
|
||||
line = reader.readLine();
|
||||
}
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
BetterFoliage.log.warn(String.format("Error reading configuration %s", defaults.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
/** Caches block IDs on world load for fast lookup
|
||||
* @param event
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@SubscribeEvent
|
||||
public void handleWorldLoad(WorldEvent.Load event) {
|
||||
if (!(event.world instanceof WorldClient)) return;
|
||||
|
||||
blockIDs.clear();
|
||||
Iterator<Block> iter = Block.blockRegistry.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Block block = iter.next();
|
||||
if (matchesClass(block)) blockIDs.add(Block.blockRegistry.getIDForObject(block));
|
||||
}
|
||||
if (event.world instanceof WorldClient) updateBlockIDs();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.lang.reflect.Field;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import mods.betterfoliage.common.config.Config;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -70,8 +71,8 @@ public class ShadersModIntegration {
|
||||
* @return entity data to use
|
||||
*/
|
||||
public static int getBlockIdOverride(int original, Block block) {
|
||||
if (BetterFoliageClient.leaves.matchesID(original & 0xFFFF)) return leavesEntityData;
|
||||
if (BetterFoliageClient.crops.matchesID(original & 0xFFFF)) return tallGrassEntityData;
|
||||
if (Config.leaves.matchesID(original & 0xFFFF)) return leavesEntityData;
|
||||
if (Config.crops.matchesID(original & 0xFFFF)) return tallGrassEntityData;
|
||||
return original;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class ConfigGuiFactory implements IModGuiFactory {
|
||||
|
||||
public static class ConfigGuiBetterFoliage extends GuiConfig {
|
||||
public ConfigGuiBetterFoliage(GuiScreen parentScreen) {
|
||||
super(parentScreen, Config.getConfigRootCategories(), BetterFoliage.MOD_ID, null, false, false, BetterFoliage.MOD_NAME);
|
||||
super(parentScreen, Config.getConfigRootElements(), BetterFoliage.MOD_ID, null, false, false, BetterFoliage.MOD_NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package mods.betterfoliage.client.render.impl;
|
||||
import java.util.Random;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.client.BetterFoliageClient;
|
||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||
import mods.betterfoliage.client.render.IconSet;
|
||||
import mods.betterfoliage.client.render.RenderBlockAOBase;
|
||||
@@ -32,7 +31,7 @@ public class RenderBlockBetterAlgae extends RenderBlockAOBase implements IRender
|
||||
|
||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||
if (!Config.algaeEnabled) return false;
|
||||
if (!(BetterFoliageClient.dirt.matchesID(block))) return false;
|
||||
if (!(Config.dirt.matchesID(block))) return false;
|
||||
if (blockAccess.getBlock(x, y + 1, z).getMaterial() != Material.water) return false;
|
||||
if (blockAccess.getBlock(x, y + 2, z).getMaterial() != Material.water) return false;
|
||||
if (blockAccess.getBiomeGenForCoords(x, z).temperature < 0.4f) return false;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package mods.betterfoliage.client.render.impl;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.client.BetterFoliageClient;
|
||||
import mods.betterfoliage.client.ShadersModIntegration;
|
||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||
import mods.betterfoliage.client.render.IconSet;
|
||||
@@ -32,7 +31,7 @@ public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRender
|
||||
protected boolean connectXP, connectXN, connectZP, connectZN;
|
||||
|
||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||
return BetterFoliageClient.grass.matchesID(block);
|
||||
return Config.grass.matchesID(block);
|
||||
}
|
||||
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
@@ -77,16 +76,16 @@ public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRender
|
||||
|
||||
protected void checkConnectedGrass(int x, int y, int z) {
|
||||
Block blockBelow = blockAccess.getBlock(x, y - 1, z);
|
||||
if (Config.ctxGrassAggressiveEnabled && (BetterFoliageClient.grass.matchesID(blockBelow) || BetterFoliageClient.dirt.matchesID(blockBelow))) {
|
||||
if (Config.ctxGrassAggressiveEnabled && (Config.grass.matchesID(blockBelow) || Config.dirt.matchesID(blockBelow))) {
|
||||
connectXP = true;
|
||||
connectXN = true;
|
||||
connectZP = true;
|
||||
connectZN = true;
|
||||
} else if (Config.ctxGrassClassicEnabled) {
|
||||
connectXP = BetterFoliageClient.grass.matchesID(blockAccess.getBlock(x + 1, y - 1, z));
|
||||
connectXN = BetterFoliageClient.grass.matchesID(blockAccess.getBlock(x - 1, y - 1, z));
|
||||
connectZP = BetterFoliageClient.grass.matchesID(blockAccess.getBlock(x, y - 1, z + 1));
|
||||
connectZN = BetterFoliageClient.grass.matchesID(blockAccess.getBlock(x, y - 1, z - 1));
|
||||
connectXP = Config.grass.matchesID(blockAccess.getBlock(x + 1, y - 1, z));
|
||||
connectXN = Config.grass.matchesID(blockAccess.getBlock(x - 1, y - 1, z));
|
||||
connectZP = Config.grass.matchesID(blockAccess.getBlock(x, y - 1, z + 1));
|
||||
connectZN = Config.grass.matchesID(blockAccess.getBlock(x, y - 1, z - 1));
|
||||
} else {
|
||||
connectXP = false;
|
||||
connectXN = false;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class RenderBlockBetterLeaves extends RenderBlockAOBase implements IRende
|
||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||
if (!Config.leavesEnabled) return false;
|
||||
if (original > 0 && original < 42) return false;
|
||||
return BetterFoliageClient.leaves.matchesID(block) && !isBlockSurrounded(blockAccess, x, y, z);
|
||||
return Config.leaves.matchesID(block) && !isBlockSurrounded(blockAccess, x, y, z);
|
||||
}
|
||||
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package mods.betterfoliage.client.render.impl;
|
||||
import java.util.Random;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.client.BetterFoliageClient;
|
||||
import mods.betterfoliage.client.ShadersModIntegration;
|
||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||
import mods.betterfoliage.client.render.IconSet;
|
||||
@@ -34,12 +33,12 @@ public class RenderBlockBetterReed extends RenderBlockAOBase implements IRenderB
|
||||
|
||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||
if (!Config.reedEnabled) return false;
|
||||
if (!(BetterFoliageClient.dirt.matchesID(block))) return false;
|
||||
if (!(Config.dirt.matchesID(block))) return false;
|
||||
if (blockAccess.getBlock(x, y + 1, z).getMaterial() != Material.water) return false;
|
||||
if (!blockAccess.isAirBlock(x, y + 2, z)) return false;
|
||||
if (blockAccess.getBiomeGenForCoords(x, z).temperature < 0.4f || blockAccess.getBiomeGenForCoords(x, z).rainfall < 0.4f) return false;
|
||||
int terrainVariation = MathHelper.floor_double((noise.func_151605_a(x, z) + 1.0) * 32.0);
|
||||
return terrainVariation < Config.reedChance;
|
||||
return terrainVariation < Config.reedPopulation;
|
||||
}
|
||||
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package mods.betterfoliage.client.render.impl;
|
||||
|
||||
import mods.betterfoliage.client.BetterFoliageClient;
|
||||
import mods.betterfoliage.client.render.FakeRenderBlockAOBase;
|
||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||
import mods.betterfoliage.common.config.Config;
|
||||
@@ -23,8 +22,8 @@ public class RenderBlocksBetterGrassSide extends FakeRenderBlockAOBase implement
|
||||
@Override
|
||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||
return Config.ctxGrassAggressiveEnabled &&
|
||||
BetterFoliageClient.dirt.matchesID(block) &&
|
||||
BetterFoliageClient.grass.matchesID(blockAccess.getBlock(x, y + 1, z));
|
||||
Config.dirt.matchesID(block) &&
|
||||
Config.grass.matchesID(blockAccess.getBlock(x, y + 1, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.Set;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.client.BetterFoliageClient;
|
||||
import mods.betterfoliage.common.config.Config;
|
||||
import mods.betterfoliage.common.util.Utils;
|
||||
import mods.betterfoliage.loader.DeobfHelper;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -75,7 +76,7 @@ public class LeafTextureEnumerator implements IIconRegister {
|
||||
Iterator<Block> iter = Block.blockRegistry.iterator();
|
||||
while(iter.hasNext()) {
|
||||
Block block = iter.next();
|
||||
if (BetterFoliageClient.leaves.matchesClass(block)) {
|
||||
if (Config.leaves.matchesClass(block)) {
|
||||
BetterFoliage.log.debug(String.format("Inspecting leaf block: %s", block.getClass().getName()));
|
||||
block.registerBlockIcons(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user