move default class lists to resource files
This commit is contained in:
@@ -16,13 +16,6 @@ import mods.betterfoliage.client.resource.BlockTextureGenerator;
|
||||
import mods.betterfoliage.client.resource.HalfTextureResource;
|
||||
import mods.betterfoliage.client.resource.LeafTextureGenerator;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockCarrot;
|
||||
import net.minecraft.block.BlockCrops;
|
||||
import net.minecraft.block.BlockDoublePlant;
|
||||
import net.minecraft.block.BlockLeavesBase;
|
||||
import net.minecraft.block.BlockPotato;
|
||||
import net.minecraft.block.BlockReed;
|
||||
import net.minecraft.block.BlockTallGrass;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -40,8 +33,8 @@ public class BetterFoliageClient {
|
||||
public static Map<Integer, IRenderBlockDecorator> decorators = Maps.newHashMap();
|
||||
public static LeafTextureGenerator leafGenerator;
|
||||
|
||||
public static BlockMatcher leaves;
|
||||
public static BlockMatcher crops;
|
||||
public static BlockMatcher leaves = new BlockMatcher();
|
||||
public static BlockMatcher crops = new BlockMatcher();
|
||||
|
||||
public static void preInit() {
|
||||
FMLCommonHandler.instance().bus().register(new KeyHandler());
|
||||
@@ -54,21 +47,11 @@ public class BetterFoliageClient {
|
||||
registerRenderer(new RenderBlockBetterReed());
|
||||
registerRenderer(new RenderBlockBetterAlgae());
|
||||
|
||||
leaves = new BlockMatcher(BlockLeavesBase.class.getName(),
|
||||
"forestry.arboriculture.gadgets.BlockLeaves",
|
||||
"thaumcraft.common.blocks.BlockMagicalLeaves");
|
||||
leaves.load(new File(BetterFoliage.configDir, "classesLeaves.cfg"));
|
||||
leaves.load(new File(BetterFoliage.configDir, "classesLeaves.cfg"), new ResourceLocation("betterfoliage:classesLeavesDefault.cfg"));
|
||||
MinecraftForge.EVENT_BUS.register(leaves);
|
||||
|
||||
crops = new BlockMatcher(BlockCrops.class.getName(),
|
||||
"-" + BlockCarrot.class.getName(),
|
||||
"-" + BlockPotato.class.getName(),
|
||||
BlockTallGrass.class.getName(),
|
||||
BlockDoublePlant.class.getName(),
|
||||
BlockReed.class.getName(),
|
||||
"biomesoplenty.common.blocks.BlockBOPFlower",
|
||||
"biomesoplenty.common.blocks.BlockBOPFlower2",
|
||||
"tconstruct.blocks.slime.SlimeTallGrass");
|
||||
crops.load(new File(BetterFoliage.configDir, "classesCrops.cfg"));
|
||||
crops.load(new File(BetterFoliage.configDir, "classesCrops.cfg"), new ResourceLocation("betterfoliage:classesCropsDefault.cfg"));
|
||||
MinecraftForge.EVENT_BUS.register(crops);
|
||||
|
||||
BetterFoliage.log.info("Registering leaf texture generator");
|
||||
leafGenerator = new LeafTextureGenerator();
|
||||
|
||||
@@ -10,8 +10,9 @@ 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.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
@@ -24,11 +25,6 @@ public class BlockMatcher {
|
||||
public Set<String> blackList = Sets.newHashSet();
|
||||
public Set<Integer> blockIDs = Sets.newHashSet();
|
||||
|
||||
public BlockMatcher(String... defaults) {
|
||||
for (String clazz : defaults) addClass(clazz);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
public void addClass(String className) {
|
||||
if (className.startsWith("-"))
|
||||
blackList.add(className.substring(1));
|
||||
@@ -60,7 +56,9 @@ public class BlockMatcher {
|
||||
return blockIDs.contains(Block.blockRegistry.getIDForObject(block));
|
||||
}
|
||||
|
||||
public void load(File file) {
|
||||
public void load(File file, ResourceLocation defaults) {
|
||||
if (!file.exists()) Utils.copyFromTextResource(defaults, file);
|
||||
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(file));
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
package mods.betterfoliage.common.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
import mods.betterfoliage.loader.DeobfHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
@@ -68,4 +74,21 @@ public class Utils {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void copyFromTextResource(ResourceLocation resourceLocation, File target) {
|
||||
try {
|
||||
IResource defaults = Minecraft.getMinecraft().getResourceManager().getResource(resourceLocation);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(defaults.getInputStream(), Charsets.UTF_8));
|
||||
FileWriter writer = new FileWriter(target);
|
||||
|
||||
String line = reader.readLine();
|
||||
while(line != null) {
|
||||
writer.write(line + System.lineSeparator());
|
||||
line = reader.readLine();
|
||||
}
|
||||
reader.close();
|
||||
writer.close();
|
||||
} catch(IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// Vanilla
|
||||
net.minecraft.block.BlockTallGrass
|
||||
net.minecraft.block.BlockCrops
|
||||
net.minecraft.block.BlockReed
|
||||
net.minecraft.block.BlockDoublePlant
|
||||
-net.minecraft.block.BlockCarrot
|
||||
-net.minecraft.block.BlockPotato
|
||||
|
||||
// Biomes O'Plenty
|
||||
biomesoplenty.common.blocks.BlockBOPFlower
|
||||
biomesoplenty.common.blocks.BlockBOPFlower2
|
||||
|
||||
// Tinkers' Construct
|
||||
tconstruct.blocks.slime.SlimeTallGrass
|
||||
|
||||
// Plant Mega Pack
|
||||
plantmegapack.block.PMPBlockBerrybush
|
||||
plantmegapack.block.PMPBlockCrops
|
||||
plantmegapack.block.PMPBlockDesert
|
||||
plantmegapack.block.PMPBlockFern
|
||||
plantmegapack.block.PMPBlockFlowerMulti
|
||||
plantmegapack.block.PMPBlockFlowerSingle
|
||||
plantmegapack.block.PMPBlockForest
|
||||
plantmegapack.block.PMPBlockGrass
|
||||
plantmegapack.block.PMPBlockJungle
|
||||
plantmegapack.block.PMPBlockMountain
|
||||
plantmegapack.block.PMPBlockSavanna
|
||||
plantmegapack.block.PMPBlockShrub
|
||||
plantmegapack.block.PMPBlockWetlands
|
||||
|
||||
// Pam's HarvestCraft
|
||||
com.pam.harvestcraft.BlockPamCrop
|
||||
com.pam.harvestcraft.BlockPamDesertGarden
|
||||
com.pam.harvestcraft.BlockPamNormalGarden
|
||||
com.pam.harvestcraft.BlockPamWaterGarden
|
||||
@@ -0,0 +1,4 @@
|
||||
net.minecraft.block.BlockLeavesBase
|
||||
forestry.arboriculture.gadgets.BlockLeaves
|
||||
thaumcraft.common.blocks.BlockMagicalLeaves
|
||||
-tconstruct.blocks.OreberryBushEssence
|
||||
Reference in New Issue
Block a user