new feature: use pre-drawn leaf textures if available

some refactoring
This commit is contained in:
octarine-noise
2014-07-11 15:13:38 +02:00
parent aee6e5caca
commit 32c4dc6035
8 changed files with 58 additions and 23 deletions

View File

@@ -6,7 +6,7 @@ import java.util.Map;
import java.util.Set;
import mods.betterfoliage.BetterFoliage;
import mods.betterfoliage.common.util.ReflectionUtil;
import mods.betterfoliage.common.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.IResource;
@@ -18,7 +18,10 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public abstract class BlockTextureGenerator implements IResourceManager {
/** Resource domain name of generated textures */
@@ -48,7 +51,7 @@ public abstract class BlockTextureGenerator implements IResourceManager {
blockTextures = event.map;
counter = 0;
Map<String, IResourceManager> domainManagers = ReflectionUtil.getDomainResourceManagers();
Map<String, IResourceManager> domainManagers = Utils.getDomainResourceManagers();
if (domainManagers == null) {
BetterFoliage.log.warn("Failed to inject texture generator");
return;
@@ -64,7 +67,7 @@ public abstract class BlockTextureGenerator implements IResourceManager {
if (event.map.getTextureType() != 0) return;
// don't leave a mess
Map<String, IResourceManager> domainManagers = ReflectionUtil.getDomainResourceManagers();
Map<String, IResourceManager> domainManagers = Utils.getDomainResourceManagers();
if (domainManagers != null) domainManagers.remove(domainName);
onStitchEnd(event);

View File

@@ -9,8 +9,9 @@ import java.util.Set;
import mods.betterfoliage.BetterFoliage;
import mods.betterfoliage.client.BetterFoliageClient;
import mods.betterfoliage.common.util.DeobfNames;
import mods.betterfoliage.common.util.ReflectionUtil;
import mods.betterfoliage.common.util.Utils;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.IResource;
@@ -31,6 +32,10 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class LeafTextureGenerator extends BlockTextureGenerator implements IIconRegister {
public String nonGeneratedDomain = "betterfoliage";
public int nonGeneratedCounter = 0;
public LeafTextureGenerator() {
super("bf_leaves_autogen", new ResourceLocation("betterfoliage", "textures/blocks/missing_leaf.png"));
}
@@ -39,7 +44,17 @@ public class LeafTextureGenerator extends BlockTextureGenerator implements IIcon
public List<ILeafTextureRecognizer> recognizers = Lists.newLinkedList();
public IResource getResource(ResourceLocation resourceLocation) throws IOException {
LeafTextureResource result = new LeafTextureResource(unwrapResource(resourceLocation), getMissingResource());
ResourceLocation original = unwrapResource(resourceLocation);
// check for provided texture
ResourceLocation handDrawnLocation = new ResourceLocation(nonGeneratedDomain, String.format("textures/blocks/%s/%s", original.getResourceDomain(), original.getResourcePath()));
if (Utils.resourceExists(handDrawnLocation)) {
nonGeneratedCounter++;
return Minecraft.getMinecraft().getResourceManager().getResource(handDrawnLocation);
}
// generate our own
LeafTextureResource result = new LeafTextureResource(original, getMissingResource());
if (result.data != null) counter++;
return result;
}
@@ -62,6 +77,7 @@ public class LeafTextureGenerator extends BlockTextureGenerator implements IIcon
@SuppressWarnings("unchecked")
@Override
public void onStitchStart(Pre event) {
nonGeneratedCounter = 0;
BetterFoliage.log.info("Reloading leaf textures");
// register simple block textures
@@ -76,8 +92,8 @@ public class LeafTextureGenerator extends BlockTextureGenerator implements IIcon
// enumerate all registered textures, find leaf textures among them
Map<String, TextureAtlasSprite> mapAtlas = null;
mapAtlas = ReflectionUtil.getField(blockTextures, DeobfNames.TM_MRS_SRG, Map.class);
if (mapAtlas == null) mapAtlas = ReflectionUtil.getField(blockTextures, DeobfNames.TM_MRS_MCP, Map.class);
mapAtlas = Utils.getField(blockTextures, DeobfNames.TM_MRS_SRG, Map.class);
if (mapAtlas == null) mapAtlas = Utils.getField(blockTextures, DeobfNames.TM_MRS_MCP, Map.class);
if (mapAtlas == null) {
BetterFoliage.log.warn("Failed to reflect texture atlas, textures may be missing");
} else {
@@ -95,6 +111,7 @@ public class LeafTextureGenerator extends BlockTextureGenerator implements IIcon
@Override
public void onStitchEnd(Post event) {
BetterFoliage.log.info(String.format("Found %d pre-drawn leaf textures", nonGeneratedCounter));
BetterFoliage.log.info(String.format("Generated %d leaf textures", counter));
}