Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47aa5df3c4 | ||
|
|
3f49f6e09b | ||
|
|
4f7ede5d9e | ||
|
|
5ad3bbe342 | ||
|
|
5a5daf6750 | ||
|
|
4bba2b06c2 | ||
|
|
adfc14bc62 | ||
|
|
85b4880391 | ||
|
|
4bc6a4a2f9 |
@@ -6,4 +6,4 @@ More info: http://www.minecraftforum.net/topic/2776217-better-foliage/
|
|||||||
|
|
||||||
Latest Download
|
Latest Download
|
||||||
========
|
========
|
||||||
[BetterFoliage 0.9.10-beta] (http://goo.gl/oaSfCY) (MC 1.7.2 & 1.7.10)
|
[BetterFoliage 0.9.11-beta] (http://goo.gl/cTCFLo) (MC 1.7.2 & 1.7.10)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ minecraft {
|
|||||||
|
|
||||||
jar.baseName = 'BetterFoliage'
|
jar.baseName = 'BetterFoliage'
|
||||||
group = 'com.github.octarine-noise'
|
group = 'com.github.octarine-noise'
|
||||||
version='0.9.11b'
|
version='0.9.12b'
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
inputs.property "version", project.version
|
inputs.property "version", project.version
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import mods.betterfoliage.client.render.impl.RenderBlockBetterGrass;
|
|||||||
import mods.betterfoliage.client.render.impl.RenderBlockBetterLeaves;
|
import mods.betterfoliage.client.render.impl.RenderBlockBetterLeaves;
|
||||||
import mods.betterfoliage.client.render.impl.RenderBlockBetterLilypad;
|
import mods.betterfoliage.client.render.impl.RenderBlockBetterLilypad;
|
||||||
import mods.betterfoliage.client.render.impl.RenderBlockBetterMycelium;
|
import mods.betterfoliage.client.render.impl.RenderBlockBetterMycelium;
|
||||||
|
import mods.betterfoliage.client.render.impl.RenderBlockBetterNetherrack;
|
||||||
import mods.betterfoliage.client.render.impl.RenderBlockBetterReed;
|
import mods.betterfoliage.client.render.impl.RenderBlockBetterReed;
|
||||||
import mods.betterfoliage.client.render.impl.RenderBlocksBetterGrassSide;
|
import mods.betterfoliage.client.render.impl.RenderBlocksBetterGrassSide;
|
||||||
import mods.betterfoliage.client.resource.LeafGenerator;
|
import mods.betterfoliage.client.resource.LeafGenerator;
|
||||||
@@ -48,6 +49,7 @@ public class BetterFoliageClient {
|
|||||||
|
|
||||||
BetterFoliage.log.info("Registering renderers");
|
BetterFoliage.log.info("Registering renderers");
|
||||||
registerRenderer(new RenderBlockBetterCactus());
|
registerRenderer(new RenderBlockBetterCactus());
|
||||||
|
registerRenderer(new RenderBlockBetterNetherrack());
|
||||||
registerRenderer(new RenderBlockBetterLilypad());
|
registerRenderer(new RenderBlockBetterLilypad());
|
||||||
registerRenderer(new RenderBlockBetterMycelium());
|
registerRenderer(new RenderBlockBetterMycelium());
|
||||||
registerRenderer(new RenderBlockBetterLeaves());
|
registerRenderer(new RenderBlockBetterLeaves());
|
||||||
|
|||||||
@@ -1,19 +1,15 @@
|
|||||||
package mods.betterfoliage.client;
|
package mods.betterfoliage.client;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import mods.betterfoliage.BetterFoliage;
|
import mods.betterfoliage.common.util.ResourceUtils;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.multiplayer.WorldClient;
|
import net.minecraft.client.multiplayer.WorldClient;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.event.world.WorldEvent;
|
import net.minecraftforge.event.world.WorldEvent;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
@@ -63,24 +59,12 @@ public class BlockMatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void loadDefaultLists(ResourceLocation defaults, Collection<String> blacklist, Collection<String> whitelist) {
|
public static void loadDefaultLists(ResourceLocation defaults, Collection<String> blacklist, Collection<String> whitelist) {
|
||||||
BufferedReader reader = null;
|
for (String line : ResourceUtils.getLines(defaults)) {
|
||||||
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("-"))
|
if (line.startsWith("-"))
|
||||||
blacklist.add(line.substring(1));
|
blacklist.add(line.substring(1));
|
||||||
else
|
else
|
||||||
whitelist.add(line);
|
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
|
/** Caches block IDs on world load for fast lookup
|
||||||
|
|||||||
67
src/main/java/mods/betterfoliage/client/TextureMatcher.java
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package mods.betterfoliage.client;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import mods.betterfoliage.common.util.ResourceUtils;
|
||||||
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
|
import net.minecraft.util.IIcon;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
public class TextureMatcher {
|
||||||
|
|
||||||
|
public static class TextureMapping {
|
||||||
|
public String matchDomain;
|
||||||
|
public String matchName;
|
||||||
|
public String textureType;
|
||||||
|
|
||||||
|
public TextureMapping(String matchDomain, String matchName, String textureType) {
|
||||||
|
this.matchDomain = matchDomain;
|
||||||
|
this.matchName = matchName;
|
||||||
|
this.textureType = textureType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean matches(TextureAtlasSprite icon) {
|
||||||
|
ResourceLocation iconLocation = new ResourceLocation(icon.getIconName());
|
||||||
|
if (matchDomain != null && !matchDomain.equals(iconLocation.getResourceDomain())) return false;
|
||||||
|
return iconLocation.getResourcePath().contains(matchName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TextureMapping> mappings = Lists.newLinkedList();
|
||||||
|
|
||||||
|
public Map<IIcon, String> types = Maps.newHashMap();
|
||||||
|
|
||||||
|
public String put(TextureAtlasSprite icon) {
|
||||||
|
if (types.keySet().contains(icon)) return types.get(icon);
|
||||||
|
for (TextureMapping mapping : mappings) if (mapping.matches(icon)) {
|
||||||
|
types.put(icon, mapping.textureType);
|
||||||
|
return mapping.textureType;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get(IIcon icon) {
|
||||||
|
return types.get(icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadMappings(ResourceLocation resource) {
|
||||||
|
mappings = Lists.newLinkedList();
|
||||||
|
|
||||||
|
for (String line : ResourceUtils.getLines(resource)) {
|
||||||
|
String[] lineSplit = line.split("=");
|
||||||
|
if (lineSplit.length != 2) continue;
|
||||||
|
|
||||||
|
String[] match = lineSplit[0].split(":");
|
||||||
|
if (match.length == 2) {
|
||||||
|
mappings.add(new TextureMapping(match[0], match[1], lineSplit[1]));
|
||||||
|
} else if (match.length == 1) {
|
||||||
|
mappings.add(new TextureMapping(null, match[0], lineSplit[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
package mods.betterfoliage.client.gui;
|
package mods.betterfoliage.client.gui;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import mods.betterfoliage.common.config.Config;
|
||||||
|
import mods.betterfoliage.common.util.BiomeUtils;
|
||||||
import net.minecraft.world.biome.BiomeGenBase;
|
import net.minecraft.world.biome.BiomeGenBase;
|
||||||
|
|
||||||
import com.google.common.base.Predicates;
|
|
||||||
import com.google.common.collect.Collections2;
|
import com.google.common.collect.Collections2;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -19,31 +17,20 @@ import cpw.mods.fml.client.config.IConfigElement;
|
|||||||
|
|
||||||
public class BiomeListConfigEntry extends SelectListConfigEntry<BiomeGenBase> {
|
public class BiomeListConfigEntry extends SelectListConfigEntry<BiomeGenBase> {
|
||||||
|
|
||||||
public static List<BiomeGenBase> reedBiomeList = Lists.newArrayList();
|
|
||||||
public static List<BiomeGenBase> algaeBiomeList = Lists.newArrayList();
|
|
||||||
public static List<BiomeGenBase> coralBiomeList = Lists.newArrayList();
|
|
||||||
|
|
||||||
public BiomeListConfigEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement<?> configElement) {
|
public BiomeListConfigEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement<?> configElement) {
|
||||||
super(owningScreen, owningEntryList, configElement);
|
super(owningScreen, owningEntryList, configElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<BiomeGenBase> getBaseSet(String qualifiedName) {
|
protected List<BiomeGenBase> getBaseSet(String name) {
|
||||||
List<BiomeGenBase> biomes = Lists.newArrayList(Collections2.filter(Arrays.asList(BiomeGenBase.getBiomeGenArray()), Predicates.notNull()));
|
return BiomeUtils.getAllBiomes();
|
||||||
Collections.sort(biomes, new Comparator<BiomeGenBase>() {
|
|
||||||
@Override
|
|
||||||
public int compare(BiomeGenBase o1, BiomeGenBase o2) {
|
|
||||||
return o1.biomeName.compareTo(o2.biomeName);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return biomes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<BiomeGenBase> getDefaultSelected(String name) {
|
protected List<BiomeGenBase> getDefaultSelected(String name) {
|
||||||
if (name.equals("reedBiomeList")) return reedBiomeList;
|
if (name.equals("reedBiomeList")) return Lists.newArrayList(Collections2.filter(getBaseSet(name), BiomeUtils.biomeIdFilter(Config.reedBiomeList)));
|
||||||
if (name.equals("algaeBiomeList")) return algaeBiomeList;
|
if (name.equals("algaeBiomeList")) return Lists.newArrayList(Collections2.filter(getBaseSet(name), BiomeUtils.biomeIdFilter(Config.algaeBiomeList)));
|
||||||
if (name.equals("coralBiomeList")) return coralBiomeList;
|
if (name.equals("coralBiomeList")) return Lists.newArrayList(Collections2.filter(getBaseSet(name), BiomeUtils.biomeIdFilter(Config.coralBiomeList)));
|
||||||
return ImmutableList.<BiomeGenBase>of();
|
return ImmutableList.<BiomeGenBase>of();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package mods.betterfoliage.client.gui;
|
package mods.betterfoliage.client.gui;
|
||||||
|
|
||||||
import mods.betterfoliage.common.util.Utils;
|
import mods.betterfoliage.common.util.RenderUtils;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
import net.minecraft.util.EnumChatFormatting;
|
import net.minecraft.util.EnumChatFormatting;
|
||||||
import cpw.mods.fml.client.config.GuiConfig;
|
import cpw.mods.fml.client.config.GuiConfig;
|
||||||
@@ -14,7 +14,7 @@ public class NonVerboseArrayEntry extends GuiConfigEntries.ArrayEntry {
|
|||||||
public NonVerboseArrayEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement<?> configElement) {
|
public NonVerboseArrayEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement<?> configElement) {
|
||||||
super(owningScreen, owningEntryList, configElement);
|
super(owningScreen, owningEntryList, configElement);
|
||||||
|
|
||||||
Utils.stripTooltipDefaultText(toolTip);
|
RenderUtils.stripTooltipDefaultText(toolTip);
|
||||||
String shortDefaults = I18n.format("betterfoliage.arrayEntryDisplay", configElement.getDefaults().length);
|
String shortDefaults = I18n.format("betterfoliage.arrayEntryDisplay", configElement.getDefaults().length);
|
||||||
toolTip.addAll(this.mc.fontRenderer.listFormattedStringToWidth(EnumChatFormatting.AQUA + I18n.format("fml.configgui.tooltip.default", shortDefaults),300));
|
toolTip.addAll(this.mc.fontRenderer.listFormattedStringToWidth(EnumChatFormatting.AQUA + I18n.format("fml.configgui.tooltip.default", shortDefaults),300));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import mods.betterfoliage.common.util.Utils;
|
import mods.betterfoliage.common.util.RenderUtils;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
import net.minecraft.util.EnumChatFormatting;
|
import net.minecraft.util.EnumChatFormatting;
|
||||||
@@ -28,7 +28,7 @@ public abstract class SelectListConfigEntry<T> extends CategoryEntry {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public SelectListConfigEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement<?> configElement) {
|
public SelectListConfigEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement<?> configElement) {
|
||||||
super(owningScreen, owningEntryList, configElement);
|
super(owningScreen, owningEntryList, configElement);
|
||||||
Utils.stripTooltipDefaultText(toolTip);
|
RenderUtils.stripTooltipDefaultText(toolTip);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package mods.betterfoliage.client.render;
|
package mods.betterfoliage.client.render;
|
||||||
|
|
||||||
import mods.betterfoliage.common.util.Utils;
|
import mods.betterfoliage.common.util.ResourceUtils;
|
||||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||||
import net.minecraft.util.IIcon;
|
import net.minecraft.util.IIcon;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
@@ -37,7 +37,7 @@ public class IconSet {
|
|||||||
// if the path contains a domain, use that to check if the resource exists
|
// if the path contains a domain, use that to check if the resource exists
|
||||||
String resolvedDomain = path.contains(":") ? new ResourceLocation(path).getResourceDomain() : domain;
|
String resolvedDomain = path.contains(":") ? new ResourceLocation(path).getResourceDomain() : domain;
|
||||||
String resolvedPath = String.format("textures/blocks/" + (path.contains(":") ? new ResourceLocation(path).getResourcePath() : path) + ".png", idx);
|
String resolvedPath = String.format("textures/blocks/" + (path.contains(":") ? new ResourceLocation(path).getResourcePath() : path) + ".png", idx);
|
||||||
if (Utils.resourceExists(new ResourceLocation(resolvedDomain, resolvedPath)))
|
if (ResourceUtils.resourceExists(new ResourceLocation(resolvedDomain, resolvedPath)))
|
||||||
icons[numLoaded++] = register.registerIcon(domain + ":" + String.format(path, idx));
|
icons[numLoaded++] = register.registerIcon(domain + ":" + String.format(path, idx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import mods.betterfoliage.common.util.Double3;
|
import mods.betterfoliage.common.util.Double3;
|
||||||
import mods.betterfoliage.common.util.Utils;
|
import mods.betterfoliage.common.util.RenderUtils;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.RenderBlocks;
|
import net.minecraft.client.renderer.RenderBlocks;
|
||||||
@@ -138,7 +138,7 @@ public class RenderBlockAOBase extends RenderBlocks {
|
|||||||
// render block
|
// render block
|
||||||
setPassCounters(1);
|
setPassCounters(1);
|
||||||
setRenderBoundsFromBlock(block);
|
setRenderBoundsFromBlock(block);
|
||||||
ISimpleBlockRenderingHandler handler = Utils.getRenderingHandler(block.getRenderType());
|
ISimpleBlockRenderingHandler handler = RenderUtils.getRenderingHandler(block.getRenderType());
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
handler.renderWorldBlock(world, x, y, z, block, block.getRenderType(), this);
|
handler.renderWorldBlock(world, x, y, z, block, block.getRenderType(), this);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -40,12 +40,12 @@ public class EntityFXFallingLeaves extends EntityFX {
|
|||||||
isMirrored = (rand.nextInt() & 1) == 1;
|
isMirrored = (rand.nextInt() & 1) == 1;
|
||||||
motionY = -Config.leafFXSpeed;
|
motionY = -Config.leafFXSpeed;
|
||||||
particleRotation = rand.nextInt(64);
|
particleRotation = rand.nextInt(64);
|
||||||
|
|
||||||
particleScale = (float) Config.leafFXSize;
|
particleScale = (float) Config.leafFXSize;
|
||||||
particleIcon = BetterFoliageClient.leafParticles.icons.get(rand.nextInt(1024));
|
|
||||||
|
|
||||||
Block block = world.getBlock(x, y, z);
|
Block block = world.getBlock(x, y, z);
|
||||||
IIcon blockIcon = block.getIcon(world, x, y, z, ForgeDirection.DOWN.ordinal());
|
IIcon blockIcon = block.getIcon(world, x, y, z, ForgeDirection.DOWN.ordinal());
|
||||||
|
particleIcon = BetterFoliageClient.leafParticles.getIconSet(blockIcon).get(rand.nextInt(1024));
|
||||||
calculateParticleColor(BetterFoliageClient.leafParticles.getColor(blockIcon), block.colorMultiplier(world, x, y, z));
|
calculateParticleColor(BetterFoliageClient.leafParticles.getColor(blockIcon), block.colorMultiplier(world, x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import mods.betterfoliage.client.render.RenderBlockAOBase;
|
|||||||
import mods.betterfoliage.common.config.Config;
|
import mods.betterfoliage.common.config.Config;
|
||||||
import mods.betterfoliage.common.util.Double3;
|
import mods.betterfoliage.common.util.Double3;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.client.renderer.RenderBlocks;
|
import net.minecraft.client.renderer.RenderBlocks;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
import net.minecraft.init.Blocks;
|
|
||||||
import net.minecraft.util.IIcon;
|
import net.minecraft.util.IIcon;
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||||
@@ -28,6 +28,7 @@ public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRender
|
|||||||
public IIcon snowGrassGenIcon;
|
public IIcon snowGrassGenIcon;
|
||||||
|
|
||||||
protected IIcon grassTopIcon;
|
protected IIcon grassTopIcon;
|
||||||
|
boolean isSnowTop;
|
||||||
protected boolean connectXP, connectXN, connectZP, connectZN;
|
protected boolean connectXP, connectXN, connectZP, connectZN;
|
||||||
|
|
||||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||||
@@ -44,7 +45,8 @@ public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRender
|
|||||||
renderWorldBlockBase(1, world, x, y, z, block, modelId, renderer);
|
renderWorldBlockBase(1, world, x, y, z, block, modelId, renderer);
|
||||||
if (!Config.grassEnabled) return true;
|
if (!Config.grassEnabled) return true;
|
||||||
|
|
||||||
boolean isSnowTop = blockAccess.getBlock(x, y + 1, z) == Blocks.snow_layer;
|
Material topMaterial = blockAccess.getBlock(x, y + 1, z).getMaterial();
|
||||||
|
isSnowTop = (topMaterial == Material.snow || topMaterial == Material.craftedSnow);
|
||||||
boolean isAirTop = blockAccess.isAirBlock(x, y + 1, z);
|
boolean isAirTop = blockAccess.isAirBlock(x, y + 1, z);
|
||||||
|
|
||||||
if (isSnowTop || isAirTop) {
|
if (isSnowTop || isAirTop) {
|
||||||
@@ -75,6 +77,13 @@ public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRender
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void checkConnectedGrass(int x, int y, int z) {
|
protected void checkConnectedGrass(int x, int y, int z) {
|
||||||
|
if (isSnowTop) {
|
||||||
|
connectXP = false;
|
||||||
|
connectXN = false;
|
||||||
|
connectZP = false;
|
||||||
|
connectZN = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
Block blockBelow = blockAccess.getBlock(x, y - 1, z);
|
Block blockBelow = blockAccess.getBlock(x, y - 1, z);
|
||||||
if (Config.ctxGrassAggressiveEnabled && (Config.grass.matchesID(blockBelow) || Config.dirt.matchesID(blockBelow))) {
|
if (Config.ctxGrassAggressiveEnabled && (Config.grass.matchesID(blockBelow) || Config.dirt.matchesID(blockBelow))) {
|
||||||
connectXP = true;
|
connectXP = true;
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package mods.betterfoliage.client.render.impl;
|
||||||
|
|
||||||
|
import mods.betterfoliage.BetterFoliage;
|
||||||
|
import mods.betterfoliage.client.ShadersModIntegration;
|
||||||
|
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||||
|
import mods.betterfoliage.client.render.IconSet;
|
||||||
|
import mods.betterfoliage.client.render.RenderBlockAOBase;
|
||||||
|
import mods.betterfoliage.common.config.Config;
|
||||||
|
import mods.betterfoliage.common.util.Double3;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.client.renderer.RenderBlocks;
|
||||||
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.util.IIcon;
|
||||||
|
import net.minecraft.world.IBlockAccess;
|
||||||
|
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public class RenderBlockBetterNetherrack extends RenderBlockAOBase implements IRenderBlockDecorator {
|
||||||
|
|
||||||
|
public IconSet netherrackVineIcons = new IconSet("bettergrassandleaves", "better_netherrack_%d");
|
||||||
|
|
||||||
|
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||||
|
if (!Config.netherrackEnabled) return false;
|
||||||
|
if (block != Blocks.netherrack) return false;
|
||||||
|
if (!blockAccess.isAirBlock(x, y - 1, z)) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||||
|
blockAccess = world;
|
||||||
|
renderWorldBlockBase(1, world, x, y, z, block, modelId, renderer);
|
||||||
|
|
||||||
|
int iconVariation = getSemiRandomFromPos(x, y, z, 0);
|
||||||
|
IIcon renderIcon = netherrackVineIcons.get(iconVariation);
|
||||||
|
|
||||||
|
if (renderIcon == null) return true;
|
||||||
|
|
||||||
|
int heightVariation = getSemiRandomFromPos(x, y, z, 1);
|
||||||
|
double scale = Config.netherrackSize * 0.5;
|
||||||
|
double halfHeight = 0.5 * (Config.netherrackHeightMin + pRand[heightVariation] * (Config.netherrackHeightMax - Config.netherrackHeightMin));
|
||||||
|
|
||||||
|
// render netherrack vines
|
||||||
|
ShadersModIntegration.startGrassQuads();
|
||||||
|
Tessellator.instance.setBrightness(getBrightness(block, x, y - 1, z));
|
||||||
|
Tessellator.instance.setColorOpaque_I(block.colorMultiplier(blockAccess, x, y, z));
|
||||||
|
renderCrossedSideQuads(new Double3(x + 0.5, y, z + 0.5), ForgeDirection.DOWN, scale, halfHeight, pRot[iconVariation], Config.netherrackHOffset, renderIcon, 2, false);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void handleTextureReload(TextureStitchEvent.Pre event) {
|
||||||
|
if (event.map.getTextureType() != 0) return;
|
||||||
|
|
||||||
|
netherrackVineIcons.registerIcons(event.map);
|
||||||
|
BetterFoliage.log.info(String.format("Found %d netherrack vine textures", netherrackVineIcons.numLoaded));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,8 +4,9 @@ import mods.betterfoliage.client.render.FakeRenderBlockAOBase;
|
|||||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||||
import mods.betterfoliage.common.config.Config;
|
import mods.betterfoliage.common.config.Config;
|
||||||
import mods.betterfoliage.common.util.OffsetBlockAccess;
|
import mods.betterfoliage.common.util.OffsetBlockAccess;
|
||||||
import mods.betterfoliage.common.util.Utils;
|
import mods.betterfoliage.common.util.RenderUtils;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.client.renderer.RenderBlocks;
|
import net.minecraft.client.renderer.RenderBlocks;
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.world.IBlockAccess;
|
||||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||||
@@ -21,7 +22,10 @@ public class RenderBlocksBetterGrassSide extends FakeRenderBlockAOBase implement
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||||
|
Material top2Material = blockAccess.getBlock(x, y + 2, z).getMaterial();
|
||||||
return Config.ctxGrassAggressiveEnabled &&
|
return Config.ctxGrassAggressiveEnabled &&
|
||||||
|
top2Material != Material.snow &&
|
||||||
|
top2Material != Material.craftedSnow &&
|
||||||
Config.dirt.matchesID(block) &&
|
Config.dirt.matchesID(block) &&
|
||||||
Config.grass.matchesID(blockAccess.getBlock(x, y + 1, z));
|
Config.grass.matchesID(blockAccess.getBlock(x, y + 1, z));
|
||||||
}
|
}
|
||||||
@@ -34,7 +38,7 @@ public class RenderBlocksBetterGrassSide extends FakeRenderBlockAOBase implement
|
|||||||
|
|
||||||
Block renderBlock = renderer.blockAccess.getBlock(x, y, z);
|
Block renderBlock = renderer.blockAccess.getBlock(x, y, z);
|
||||||
boolean result;
|
boolean result;
|
||||||
ISimpleBlockRenderingHandler handler = Utils.getRenderingHandler(renderBlock.getRenderType());
|
ISimpleBlockRenderingHandler handler = RenderUtils.getRenderingHandler(renderBlock.getRenderType());
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
result = handler.renderWorldBlock(renderer.blockAccess, x, y, z, renderBlock, renderBlock.getRenderType(), renderer);
|
result = handler.renderWorldBlock(renderer.blockAccess, x, y, z, renderBlock, renderBlock.getRenderType(), renderer);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import mods.betterfoliage.BetterFoliage;
|
import mods.betterfoliage.BetterFoliage;
|
||||||
import mods.betterfoliage.common.util.Utils;
|
import mods.betterfoliage.common.util.ResourceUtils;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.texture.TextureMap;
|
import net.minecraft.client.renderer.texture.TextureMap;
|
||||||
import net.minecraft.client.resources.IResource;
|
import net.minecraft.client.resources.IResource;
|
||||||
@@ -47,7 +47,7 @@ public abstract class BlockTextureGenerator implements IResourceManager {
|
|||||||
if (event.map.getTextureType() != 0) return;
|
if (event.map.getTextureType() != 0) return;
|
||||||
blockTextures = event.map;
|
blockTextures = event.map;
|
||||||
|
|
||||||
Map<String, IResourceManager> domainManagers = Utils.getDomainResourceManagers();
|
Map<String, IResourceManager> domainManagers = ResourceUtils.getDomainResourceManagers();
|
||||||
if (domainManagers == null) {
|
if (domainManagers == null) {
|
||||||
BetterFoliage.log.warn("Failed to inject texture generator");
|
BetterFoliage.log.warn("Failed to inject texture generator");
|
||||||
return;
|
return;
|
||||||
@@ -61,7 +61,7 @@ public abstract class BlockTextureGenerator implements IResourceManager {
|
|||||||
if (event.map.getTextureType() != 0) return;
|
if (event.map.getTextureType() != 0) return;
|
||||||
|
|
||||||
// don't leave a mess
|
// don't leave a mess
|
||||||
Map<String, IResourceManager> domainManagers = Utils.getDomainResourceManagers();
|
Map<String, IResourceManager> domainManagers = ResourceUtils.getDomainResourceManagers();
|
||||||
if (domainManagers != null) domainManagers.remove(domainName);
|
if (domainManagers != null) domainManagers.remove(domainName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import mods.betterfoliage.client.BetterFoliageClient;
|
|||||||
import mods.betterfoliage.client.ShadersModIntegration;
|
import mods.betterfoliage.client.ShadersModIntegration;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.client.event.TextureStitchEvent.Post;
|
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
@@ -59,7 +59,7 @@ public class LeafGenerator extends LeafGeneratorBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void endTextureReload(Post event) {
|
public void endTextureReload(TextureStitchEvent.Post event) {
|
||||||
super.endTextureReload(event);
|
super.endTextureReload(event);
|
||||||
if (event.map.getTextureType() != 0) return;
|
if (event.map.getTextureType() != 0) return;
|
||||||
BetterFoliage.log.info(String.format("Found %d pre-drawn leaf textures", drawnCounter));
|
BetterFoliage.log.info(String.format("Found %d pre-drawn leaf textures", drawnCounter));
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.io.IOException;
|
|||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import mods.betterfoliage.client.resource.LeafTextureEnumerator.LeafTextureFoundEvent;
|
import mods.betterfoliage.client.resource.LeafTextureEnumerator.LeafTextureFoundEvent;
|
||||||
import mods.betterfoliage.common.util.Utils;
|
import mods.betterfoliage.common.util.ResourceUtils;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.resources.IResource;
|
import net.minecraft.client.resources.IResource;
|
||||||
import net.minecraft.client.resources.IResourceManager;
|
import net.minecraft.client.resources.IResourceManager;
|
||||||
@@ -58,13 +58,13 @@ public abstract class LeafGeneratorBase extends BlockTextureGenerator {
|
|||||||
|
|
||||||
// check for provided texture
|
// check for provided texture
|
||||||
ResourceLocation handDrawnLocation = new ResourceLocation(nonGeneratedDomain, String.format(handDrawnLocationFormat, originalNoDirs.getResourceDomain(), originalNoDirs.getResourcePath()));
|
ResourceLocation handDrawnLocation = new ResourceLocation(nonGeneratedDomain, String.format(handDrawnLocationFormat, originalNoDirs.getResourceDomain(), originalNoDirs.getResourcePath()));
|
||||||
if (Utils.resourceExists(handDrawnLocation)) {
|
if (ResourceUtils.resourceExists(handDrawnLocation)) {
|
||||||
drawnCounter++;
|
drawnCounter++;
|
||||||
return resourceManager.getResource(handDrawnLocation);
|
return resourceManager.getResource(handDrawnLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate our own
|
// generate our own
|
||||||
if (!Utils.resourceExists(originalWithDirs)) return getMissingResource();
|
if (!ResourceUtils.resourceExists(originalWithDirs)) return getMissingResource();
|
||||||
|
|
||||||
BufferedImage result;
|
BufferedImage result;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
import mods.betterfoliage.BetterFoliage;
|
||||||
|
import mods.betterfoliage.client.TextureMatcher;
|
||||||
import mods.betterfoliage.client.render.IconSet;
|
import mods.betterfoliage.client.render.IconSet;
|
||||||
import mods.betterfoliage.client.resource.LeafTextureEnumerator.LeafTextureFoundEvent;
|
import mods.betterfoliage.client.resource.LeafTextureEnumerator.LeafTextureFoundEvent;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@@ -21,34 +23,46 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
/** Holds the texture for the falling leaf particles, and stores average texture color values for leaf textures
|
/** Holds the textures for the falling leaf particles, and stores average texture color values for leaf textures
|
||||||
* @author octarine-noise
|
* @author octarine-noise
|
||||||
*/
|
*/
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class LeafParticleTextures {
|
public class LeafParticleTextures {
|
||||||
|
|
||||||
/** Icons for leaf particles */
|
/** Icons for leaf particles */
|
||||||
public IconSet icons = new IconSet("betterfoliage", "falling_leaf_default_%d");
|
public Map<String, IconSet> iconSets = Maps.newHashMap();
|
||||||
|
|
||||||
|
/** Leaf type mappings */
|
||||||
|
public TextureMatcher leafTypes = new TextureMatcher();
|
||||||
|
|
||||||
/** Map of average color values */
|
/** Map of average color values */
|
||||||
public Map<IIcon, Integer> colors = Maps.newHashMap();
|
public Map<IIcon, Integer> iconColors = Maps.newHashMap();
|
||||||
|
|
||||||
/** Default color value */
|
/** Default color value */
|
||||||
public int defaultColor = 0x208040;
|
public int defaultColor = 0x208040;
|
||||||
|
|
||||||
|
public int loadedSets;
|
||||||
|
|
||||||
public LeafParticleTextures(int defaultColor) {
|
public LeafParticleTextures(int defaultColor) {
|
||||||
this.defaultColor = defaultColor;
|
this.defaultColor = defaultColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IconSet getIconSet(IIcon icon) {
|
||||||
|
String leafType = leafTypes.get(icon);
|
||||||
|
if (leafType == null) leafType = "default";
|
||||||
|
IconSet result = iconSets.get(leafType);
|
||||||
|
return result.hasIcons() ? result : iconSets.get("default");
|
||||||
|
}
|
||||||
|
|
||||||
public int getColor(IIcon icon) {
|
public int getColor(IIcon icon) {
|
||||||
Integer result = colors.get(icon);
|
Integer result = iconColors.get(icon);
|
||||||
return result == null ? defaultColor : result;
|
return result == null ? defaultColor : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Calculate average color value (in HSB color space) for a texture and store it in the map.
|
/** Calculate average color value (in HSB color space) for a texture.
|
||||||
* @param icon texture
|
* @param icon texture
|
||||||
*/
|
*/
|
||||||
protected void addAtlasTexture(TextureAtlasSprite icon) {
|
protected Integer calculateTextureColor(TextureAtlasSprite icon) {
|
||||||
ResourceLocation locationNoDirs = new ResourceLocation(icon.getIconName());
|
ResourceLocation locationNoDirs = new ResourceLocation(icon.getIconName());
|
||||||
ResourceLocation locationWithDirs = new ResourceLocation(locationNoDirs.getResourceDomain(), String.format("textures/blocks/%s.png", locationNoDirs.getResourcePath()));
|
ResourceLocation locationWithDirs = new ResourceLocation(locationNoDirs.getResourceDomain(), String.format("textures/blocks/%s.png", locationNoDirs.getResourcePath()));
|
||||||
try {
|
try {
|
||||||
@@ -74,20 +88,42 @@ public class LeafParticleTextures {
|
|||||||
|
|
||||||
// average hue as usual for circular values - transform average unit vector back to polar angle
|
// average hue as usual for circular values - transform average unit vector back to polar angle
|
||||||
float avgHue = (float) (Math.atan2(sumHueY, sumHueX) / (2.0 * Math.PI) + 0.5);
|
float avgHue = (float) (Math.atan2(sumHueY, sumHueX) / (2.0 * Math.PI) + 0.5);
|
||||||
colors.put(icon, Color.HSBtoRGB(avgHue, sumSaturation / numOpaque, sumBrightness / numOpaque));
|
return Color.HSBtoRGB(avgHue, sumSaturation / numOpaque, sumBrightness / numOpaque);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void handleTextureReload(TextureStitchEvent.Pre event) {
|
public void handleTextureReload(TextureStitchEvent.Pre event) {
|
||||||
if (event.map.getTextureType() != 0) return;
|
if (event.map.getTextureType() != 0) return;
|
||||||
colors.clear();
|
loadedSets = 1;
|
||||||
icons.registerIcons(event.map);
|
iconSets.clear();
|
||||||
|
iconColors.clear();
|
||||||
|
|
||||||
|
leafTypes.loadMappings(new ResourceLocation("betterfoliage", "leafTextureMappings.cfg"));
|
||||||
|
IconSet defaultIcons = new IconSet("betterfoliage", "falling_leaf_default_%d");
|
||||||
|
iconSets.put("default", defaultIcons);
|
||||||
|
defaultIcons.registerIcons(event.map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void endTextureReload(TextureStitchEvent.Post event) {
|
||||||
|
if (event.map.getTextureType() == 0) BetterFoliage.log.info(String.format("Loaded %d leaf particle sets", loadedSets));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void handleRegisterTexture(LeafTextureFoundEvent event) {
|
public void handleRegisterTexture(LeafTextureFoundEvent event) {
|
||||||
addAtlasTexture(event.icon);
|
Integer textureColor = calculateTextureColor(event.icon);
|
||||||
|
if (textureColor != null) iconColors.put(event.icon, textureColor);
|
||||||
|
|
||||||
|
String leafType = leafTypes.put(event.icon);
|
||||||
|
if (leafType != null && !iconSets.keySet().contains(leafType)) {
|
||||||
|
IconSet newSet = new IconSet("betterfoliage", String.format("falling_leaf_%s_%%d", leafType));
|
||||||
|
newSet.registerIcons(event.blockTextures);
|
||||||
|
iconSets.put(leafType, newSet);
|
||||||
|
loadedSets++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import java.util.Set;
|
|||||||
import mods.betterfoliage.BetterFoliage;
|
import mods.betterfoliage.BetterFoliage;
|
||||||
import mods.betterfoliage.client.BetterFoliageClient;
|
import mods.betterfoliage.client.BetterFoliageClient;
|
||||||
import mods.betterfoliage.common.config.Config;
|
import mods.betterfoliage.common.config.Config;
|
||||||
import mods.betterfoliage.common.util.Utils;
|
|
||||||
import mods.betterfoliage.loader.DeobfHelper;
|
import mods.betterfoliage.loader.DeobfHelper;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||||
@@ -22,6 +21,8 @@ import com.google.common.collect.Sets;
|
|||||||
import cpw.mods.fml.common.eventhandler.Event;
|
import cpw.mods.fml.common.eventhandler.Event;
|
||||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||||
|
import cpw.mods.fml.relauncher.ReflectionHelper.UnableToAccessFieldException;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
@@ -83,13 +84,11 @@ public class LeafTextureEnumerator implements IIconRegister {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// enumerate all registered textures, find leaf textures among them
|
// enumerate all registered textures, find leaf textures among them
|
||||||
Map<String, TextureAtlasSprite> mapAtlas = null;
|
try {
|
||||||
mapAtlas = Utils.getField(blockTextures, DeobfHelper.transformElementSearge("mapRegisteredSprites"), Map.class);
|
Map<String, TextureAtlasSprite> mapAtlas = ReflectionHelper.<Map<String, TextureAtlasSprite>, TextureMap> getPrivateValue(
|
||||||
if (mapAtlas == null) mapAtlas = Utils.getField(blockTextures, "mapRegisteredSprites", Map.class);
|
TextureMap.class, blockTextures, DeobfHelper.transformElementSearge("mapRegisteredSprites"), "mapRegisteredSprites"
|
||||||
|
);
|
||||||
|
|
||||||
if (mapAtlas == null) {
|
|
||||||
BetterFoliage.log.warn("Failed to reflect texture atlas, textures may be missing");
|
|
||||||
} else {
|
|
||||||
Set<TextureAtlasSprite> foundLeafTextures = Sets.newHashSet();
|
Set<TextureAtlasSprite> foundLeafTextures = Sets.newHashSet();
|
||||||
for (TextureAtlasSprite icon : mapAtlas.values())
|
for (TextureAtlasSprite icon : mapAtlas.values())
|
||||||
if (BetterFoliageClient.isLeafTexture(icon)) foundLeafTextures.add(icon);
|
if (BetterFoliageClient.isLeafTexture(icon)) foundLeafTextures.add(icon);
|
||||||
@@ -97,6 +96,8 @@ public class LeafTextureEnumerator implements IIconRegister {
|
|||||||
BetterFoliage.log.debug(String.format("Found non-block-registered leaf texture: %s", icon.getIconName()));
|
BetterFoliage.log.debug(String.format("Found non-block-registered leaf texture: %s", icon.getIconName()));
|
||||||
MinecraftForge.EVENT_BUS.post(new LeafTextureFoundEvent(blockTextures, icon));
|
MinecraftForge.EVENT_BUS.post(new LeafTextureFoundEvent(blockTextures, icon));
|
||||||
}
|
}
|
||||||
|
} catch (UnableToAccessFieldException e) {
|
||||||
|
BetterFoliage.log.warn("Failed to reflect texture atlas, textures may be missing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import mods.betterfoliage.client.BlockMatcher;
|
|||||||
import mods.betterfoliage.client.gui.AlternateTextBooleanEntry;
|
import mods.betterfoliage.client.gui.AlternateTextBooleanEntry;
|
||||||
import mods.betterfoliage.client.gui.BiomeListConfigEntry;
|
import mods.betterfoliage.client.gui.BiomeListConfigEntry;
|
||||||
import mods.betterfoliage.client.gui.NonVerboseArrayEntry;
|
import mods.betterfoliage.client.gui.NonVerboseArrayEntry;
|
||||||
import mods.betterfoliage.common.util.Utils;
|
import mods.betterfoliage.common.util.BiomeUtils;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.world.biome.BiomeGenBase;
|
import net.minecraft.world.biome.BiomeGenBase;
|
||||||
@@ -17,9 +17,6 @@ import net.minecraftforge.common.config.ConfigElement;
|
|||||||
import net.minecraftforge.common.config.Configuration;
|
import net.minecraftforge.common.config.Configuration;
|
||||||
import net.minecraftforge.common.config.Property;
|
import net.minecraftforge.common.config.Property;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.collect.Collections2;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import cpw.mods.fml.client.config.IConfigElement;
|
import cpw.mods.fml.client.config.IConfigElement;
|
||||||
@@ -29,7 +26,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|||||||
public class Config {
|
public class Config {
|
||||||
|
|
||||||
public enum Category {
|
public enum Category {
|
||||||
blockTypes, extraLeaves, shortGrass, cactus, lilypad, reed, algae, coral, fallingLeaves, connectedGrass;
|
blockTypes, extraLeaves, shortGrass, cactus, lilypad, reed, algae, coral, netherrack, fallingLeaves, connectedGrass;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@link Configuration} object bound to the config file */
|
/** {@link Configuration} object bound to the config file */
|
||||||
@@ -91,6 +88,12 @@ public class Config {
|
|||||||
public static double leafFXPerturb;
|
public static double leafFXPerturb;
|
||||||
public static double leafFXLifetime;
|
public static double leafFXLifetime;
|
||||||
|
|
||||||
|
public static boolean netherrackEnabled;
|
||||||
|
public static double netherrackHOffset;
|
||||||
|
public static double netherrackHeightMin;
|
||||||
|
public static double netherrackHeightMax;
|
||||||
|
public static double netherrackSize;
|
||||||
|
|
||||||
public static boolean ctxGrassClassicEnabled;
|
public static boolean ctxGrassClassicEnabled;
|
||||||
public static boolean ctxGrassAggressiveEnabled;
|
public static boolean ctxGrassAggressiveEnabled;
|
||||||
|
|
||||||
@@ -164,6 +167,13 @@ public class Config {
|
|||||||
leafFXPerturb = getDouble(Category.fallingLeaves, "perturb", 0.25, 0.01, 1.0, "betterfoliage.fallingLeaves.perturb");
|
leafFXPerturb = getDouble(Category.fallingLeaves, "perturb", 0.25, 0.01, 1.0, "betterfoliage.fallingLeaves.perturb");
|
||||||
leafFXLifetime = getDouble(Category.fallingLeaves, "lifetime", 5.0, 1.0, 15.0, "betterfoliage.fallingLeaves.lifetime");
|
leafFXLifetime = getDouble(Category.fallingLeaves, "lifetime", 5.0, 1.0, 15.0, "betterfoliage.fallingLeaves.lifetime");
|
||||||
|
|
||||||
|
netherrackEnabled = getBoolean(Category.netherrack, "enabled", true, "betterfoliage.enabled");
|
||||||
|
netherrackHOffset = getDouble(Category.netherrack, "hOffset", 0.2, 0.0, 0.4, "betterfoliage.hOffset");
|
||||||
|
netherrackHeightMin = getDouble(Category.netherrack, "heightMin", 0.6, 0.1, 1.5, "betterfoliage.minHeight");
|
||||||
|
netherrackHeightMax = getDouble(Category.netherrack, "heightMax", 0.8, 0.1, 1.5, "betterfoliage.maxHeight");
|
||||||
|
netherrackSize = getDouble(Category.netherrack, "size", 1.0, 0.5, 1.5, "betterfoliage.size");
|
||||||
|
netherrackHeightMin = clampDoubleToMax(Category.netherrack, "heightMin", "heightMax");
|
||||||
|
|
||||||
ctxGrassClassicEnabled = getBoolean(Category.connectedGrass, "classic", true, "betterfoliage.connectedGrass.classic");
|
ctxGrassClassicEnabled = getBoolean(Category.connectedGrass, "classic", true, "betterfoliage.connectedGrass.classic");
|
||||||
ctxGrassAggressiveEnabled= getBoolean(Category.connectedGrass, "aggressive", true, "betterfoliage.connectedGrass.aggressive");
|
ctxGrassAggressiveEnabled= getBoolean(Category.connectedGrass, "aggressive", true, "betterfoliage.connectedGrass.aggressive");
|
||||||
|
|
||||||
@@ -185,37 +195,16 @@ public class Config {
|
|||||||
setOrder(Category.reed, "enabled", "hOffset", "heightMin", "heightMax", "population", "biomeList");
|
setOrder(Category.reed, "enabled", "hOffset", "heightMin", "heightMax", "population", "biomeList");
|
||||||
setOrder(Category.algae, "enabled", "hOffset", "heightMin", "heightMax", "population");
|
setOrder(Category.algae, "enabled", "hOffset", "heightMin", "heightMax", "population");
|
||||||
setOrder(Category.coral, "enabled", "hOffset", "vOffset", "size", "crustSize", "population", "chance");
|
setOrder(Category.coral, "enabled", "hOffset", "vOffset", "size", "crustSize", "population", "chance");
|
||||||
|
setOrder(Category.netherrack, "enabled", "hOffset", "heightMin", "heightMax", "size");
|
||||||
setOrder(Category.fallingLeaves, "enabled", "size", "chance", "lifetime", "speed", "windStrength", "stormStrength", "perturb");
|
setOrder(Category.fallingLeaves, "enabled", "size", "chance", "lifetime", "speed", "windStrength", "stormStrength", "perturb");
|
||||||
setOrder(Category.connectedGrass, "classic", "aggressive");
|
setOrder(Category.connectedGrass, "classic", "aggressive");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void getDefaultBiomes() {
|
public static void getDefaultBiomes() {
|
||||||
for (BiomeGenBase biome : BiomeGenBase.getBiomeGenArray()) {
|
List<BiomeGenBase> biomes = BiomeUtils.getAllBiomes();
|
||||||
if (biome == null) continue;
|
reedBiomeList = BiomeUtils.getFilteredBiomeIds(biomes, BiomeUtils.biomeTempRainFilter(0.4f, null, 0.4f, null));
|
||||||
if (Utils.biomeTempRainFilter(0.4f, null, 0.4f, null).apply(biome)) {
|
algaeBiomeList = BiomeUtils.getFilteredBiomeIds(biomes, BiomeUtils.biomeClassNameFilter("river", "ocean"));
|
||||||
reedBiomeList.add(biome.biomeID);
|
algaeBiomeList = BiomeUtils.getFilteredBiomeIds(biomes, BiomeUtils.biomeClassNameFilter("river", "ocean", "beach"));
|
||||||
BiomeListConfigEntry.reedBiomeList.add(biome);
|
|
||||||
}
|
|
||||||
if (Utils.biomeClassNameFilter("river", "ocean").apply(biome)) {
|
|
||||||
algaeBiomeList.add(biome.biomeID);
|
|
||||||
BiomeListConfigEntry.algaeBiomeList.add(biome);
|
|
||||||
}
|
|
||||||
if (Utils.biomeClassNameFilter("river", "ocean", "beach").apply(biome)) {
|
|
||||||
coralBiomeList.add(biome.biomeID);
|
|
||||||
BiomeListConfigEntry.coralBiomeList.add(biome);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static List<Integer> getFilteredBiomeIds(List<BiomeGenBase> biomes, Predicate<BiomeGenBase> filter) {
|
|
||||||
return Lists.newArrayList(Collections2.transform(
|
|
||||||
Collections2.filter(biomes, filter),
|
|
||||||
new Function<BiomeGenBase, Integer>() {
|
|
||||||
public Integer apply(BiomeGenBase input) {
|
|
||||||
return input.biomeID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
|
|||||||
87
src/main/java/mods/betterfoliage/common/util/BiomeUtils.java
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
package mods.betterfoliage.common.util;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.world.biome.BiomeGenBase;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
|
import com.google.common.collect.Collections2;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
|
||||||
|
public class BiomeUtils {
|
||||||
|
|
||||||
|
/** Hide constructor */
|
||||||
|
private BiomeUtils() {}
|
||||||
|
|
||||||
|
public static List<BiomeGenBase> getAllBiomes() {
|
||||||
|
List<BiomeGenBase> biomes = Lists.newArrayList(Collections2.filter(Arrays.asList(BiomeGenBase.getBiomeGenArray()), Predicates.notNull()));
|
||||||
|
Collections.sort(biomes, new Comparator<BiomeGenBase>() {
|
||||||
|
@Override
|
||||||
|
public int compare(BiomeGenBase o1, BiomeGenBase o2) {
|
||||||
|
return o1.biomeName.compareTo(o2.biomeName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return biomes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Predicate<BiomeGenBase> biomeIdFilter(final List<Integer> biomeIdList) {
|
||||||
|
return new Predicate<BiomeGenBase>() {
|
||||||
|
public boolean apply(BiomeGenBase biome) {
|
||||||
|
return biomeIdList.contains(biome.biomeID);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Function<BiomeGenBase, Integer> biomeIdTransform() {
|
||||||
|
return new Function<BiomeGenBase, Integer>() {
|
||||||
|
public Integer apply(BiomeGenBase input) {
|
||||||
|
return input.biomeID;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Predicate<BiomeGenBase> biomeTempRainFilter(final Float minTemp, final Float maxTemp, final Float minRain, final Float maxRain) {
|
||||||
|
return new Predicate<BiomeGenBase>() {
|
||||||
|
public boolean apply(BiomeGenBase biome) {
|
||||||
|
if (minTemp != null && biome.temperature < minTemp) return false;
|
||||||
|
if (maxTemp != null && biome.temperature > maxTemp) return false;
|
||||||
|
if (minRain != null && biome.rainfall < minRain) return false;
|
||||||
|
if (maxRain != null && biome.rainfall > maxRain) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Predicate<BiomeGenBase> biomeClassFilter(final Class<?>... classList) {
|
||||||
|
return new Predicate<BiomeGenBase>() {
|
||||||
|
public boolean apply(BiomeGenBase biome) {
|
||||||
|
for (Class<?> clazz : classList)
|
||||||
|
if (clazz.isAssignableFrom(biome.getClass()) || clazz.equals(biome.getClass()))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Predicate<BiomeGenBase> biomeClassNameFilter(final String... names) {
|
||||||
|
return new Predicate<BiomeGenBase>() {
|
||||||
|
public boolean apply(BiomeGenBase biome) {
|
||||||
|
for (String name : names) if (biome.getClass().getName().toLowerCase().contains(name.toLowerCase())) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Integer> getFilteredBiomeIds(Collection<BiomeGenBase> biomes, Predicate<BiomeGenBase> filter) {
|
||||||
|
return Lists.newArrayList(Collections2.transform(Collections2.filter(biomes, filter), biomeIdTransform()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package mods.betterfoliage.common.util;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.minecraft.util.EnumChatFormatting;
|
||||||
|
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||||
|
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||||
|
|
||||||
|
|
||||||
|
public class RenderUtils {
|
||||||
|
|
||||||
|
/** Hide constructor */
|
||||||
|
private RenderUtils() {}
|
||||||
|
|
||||||
|
/** Retrieve a specific rendering handler from the registry
|
||||||
|
* @param renderType render type of block
|
||||||
|
* @return {@link ISimpleBlockRenderingHandler} if defined, null otherwise
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static ISimpleBlockRenderingHandler getRenderingHandler(int renderType) {
|
||||||
|
try {
|
||||||
|
Field field = RenderingRegistry.class.getDeclaredField("INSTANCE");
|
||||||
|
field.setAccessible(true);
|
||||||
|
RenderingRegistry inst = (RenderingRegistry) field.get(null);
|
||||||
|
field = RenderingRegistry.class.getDeclaredField("blockRenderers");
|
||||||
|
field.setAccessible(true);
|
||||||
|
return ((Map<Integer, ISimpleBlockRenderingHandler>) field.get(inst)).get(renderType);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stripTooltipDefaultText(List<String> tooltip) {
|
||||||
|
boolean defaultRows = false;
|
||||||
|
Iterator<String> iter = tooltip.iterator();
|
||||||
|
while(iter.hasNext()) {
|
||||||
|
if (iter.next().startsWith(EnumChatFormatting.AQUA.toString())) defaultRows = true;
|
||||||
|
if (defaultRows) iter.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
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.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import mods.betterfoliage.BetterFoliage;
|
||||||
|
import mods.betterfoliage.loader.DeobfHelper;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.resources.IResource;
|
||||||
|
import net.minecraft.client.resources.IResourceManager;
|
||||||
|
import net.minecraft.client.resources.SimpleReloadableResourceManager;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||||
|
import cpw.mods.fml.relauncher.ReflectionHelper.UnableToAccessFieldException;
|
||||||
|
|
||||||
|
public class ResourceUtils {
|
||||||
|
|
||||||
|
/** Hide constructor */
|
||||||
|
private ResourceUtils() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return (({@link SimpleReloadableResourceManager}) Minecraft.getMinecraft().getResourceManager()).domainResourceManagers
|
||||||
|
*/
|
||||||
|
public static Map<String, IResourceManager> getDomainResourceManagers() {
|
||||||
|
try {
|
||||||
|
return ReflectionHelper.<Map<String, IResourceManager>, SimpleReloadableResourceManager> getPrivateValue(
|
||||||
|
SimpleReloadableResourceManager.class, (SimpleReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(), DeobfHelper.transformElementSearge("domainResourceManagers"), "domainResourceManagers"
|
||||||
|
);
|
||||||
|
} catch (UnableToAccessFieldException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Check for the existence of a {@link IResource}
|
||||||
|
* @param resourceLocation
|
||||||
|
* @return true if the resource exists
|
||||||
|
*/
|
||||||
|
public static boolean resourceExists(ResourceLocation resourceLocation) {
|
||||||
|
try {
|
||||||
|
IResource resource = Minecraft.getMinecraft().getResourceManager().getResource(resourceLocation);
|
||||||
|
if (resource != null) return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Copy a text file from a resource to the filesystem
|
||||||
|
* @param resourceLocation resource location of text file
|
||||||
|
* @param target target file
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static void copyFromTextResource(ResourceLocation resourceLocation, File target) throws IOException {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Iterable<String> getLines(ResourceLocation resource) {
|
||||||
|
BufferedReader reader = null;
|
||||||
|
List<String> result = Lists.newArrayList();
|
||||||
|
try {
|
||||||
|
reader = new BufferedReader(new InputStreamReader(Minecraft.getMinecraft().getResourceManager().getResource(resource).getInputStream(), Charsets.UTF_8));
|
||||||
|
String line = reader.readLine();
|
||||||
|
while(line != null) {
|
||||||
|
line = line.trim();
|
||||||
|
if (!line.isEmpty() && !line.startsWith("//")) result.add(line);
|
||||||
|
line = reader.readLine();
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
BetterFoliage.log.warn(String.format("Error reading resource %s", resource.toString()));
|
||||||
|
return Lists.newArrayList();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,157 +0,0 @@
|
|||||||
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.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import mods.betterfoliage.loader.DeobfHelper;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.resources.IResource;
|
|
||||||
import net.minecraft.client.resources.IResourceManager;
|
|
||||||
import net.minecraft.client.resources.SimpleReloadableResourceManager;
|
|
||||||
import net.minecraft.util.EnumChatFormatting;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.world.biome.BiomeGenBase;
|
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
|
|
||||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
|
||||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
|
||||||
|
|
||||||
public class Utils {
|
|
||||||
|
|
||||||
/** Hide constructor */
|
|
||||||
private Utils() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return (({@link SimpleReloadableResourceManager}) Minecraft.getMinecraft().getResourceManager()).domainResourceManagers
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static Map<String, IResourceManager> getDomainResourceManagers() {
|
|
||||||
IResourceManager manager = Minecraft.getMinecraft().getResourceManager();
|
|
||||||
Map<String, IResourceManager> result = getField(manager, DeobfHelper.transformElementSearge("domainResourceManagers"), Map.class);
|
|
||||||
if (result == null) result = getField(manager, "domainResourceManagers", Map.class);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> T getField(Object target, String fieldName, Class<T> resultClass) {
|
|
||||||
try {
|
|
||||||
Field field = target.getClass().getDeclaredField(fieldName);
|
|
||||||
field.setAccessible(true);
|
|
||||||
return (T) field.get(target);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> T getStaticField(Class<?> clazz, String fieldName, Class<T> resultClass) {
|
|
||||||
try {
|
|
||||||
Field field = clazz.getDeclaredField(fieldName);
|
|
||||||
field.setAccessible(true);
|
|
||||||
return (T) field.get(null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Retrieve a specific rendering handler from the registry
|
|
||||||
* @param renderType render type of block
|
|
||||||
* @return {@link ISimpleBlockRenderingHandler} if defined, null otherwise
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static ISimpleBlockRenderingHandler getRenderingHandler(int renderType) {
|
|
||||||
try {
|
|
||||||
Field field = RenderingRegistry.class.getDeclaredField("INSTANCE");
|
|
||||||
field.setAccessible(true);
|
|
||||||
RenderingRegistry inst = (RenderingRegistry) field.get(null);
|
|
||||||
field = RenderingRegistry.class.getDeclaredField("blockRenderers");
|
|
||||||
field.setAccessible(true);
|
|
||||||
return ((Map<Integer, ISimpleBlockRenderingHandler>) field.get(inst)).get(renderType);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Check for the existence of a {@link IResource}
|
|
||||||
* @param resourceLocation
|
|
||||||
* @return true if the resource exists
|
|
||||||
*/
|
|
||||||
public static boolean resourceExists(ResourceLocation resourceLocation) {
|
|
||||||
try {
|
|
||||||
IResource resource = Minecraft.getMinecraft().getResourceManager().getResource(resourceLocation);
|
|
||||||
if (resource != null) return true;
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Copy a text file from a resource to the filesystem
|
|
||||||
* @param resourceLocation resource location of text file
|
|
||||||
* @param target target file
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public static void copyFromTextResource(ResourceLocation resourceLocation, File target) throws IOException {
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void stripTooltipDefaultText(List<String> tooltip) {
|
|
||||||
boolean defaultRows = false;
|
|
||||||
Iterator<String> iter = tooltip.iterator();
|
|
||||||
while(iter.hasNext()) {
|
|
||||||
if (iter.next().startsWith(EnumChatFormatting.AQUA.toString())) defaultRows = true;
|
|
||||||
if (defaultRows) iter.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Predicate<BiomeGenBase> biomeTempRainFilter(final Float minTemp, final Float maxTemp, final Float minRain, final Float maxRain) {
|
|
||||||
return new Predicate<BiomeGenBase>() {
|
|
||||||
public boolean apply(BiomeGenBase biome) {
|
|
||||||
if (minTemp != null && biome.temperature < minTemp) return false;
|
|
||||||
if (maxTemp != null && biome.temperature > maxTemp) return false;
|
|
||||||
if (minRain != null && biome.rainfall < minRain) return false;
|
|
||||||
if (maxRain != null && biome.rainfall > maxRain) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Predicate<BiomeGenBase> biomeClassFilter(final Class<?>... classList) {
|
|
||||||
return new Predicate<BiomeGenBase>() {
|
|
||||||
public boolean apply(BiomeGenBase biome) {
|
|
||||||
for (Class<?> clazz : classList)
|
|
||||||
if (clazz.isAssignableFrom(biome.getClass()) || clazz.equals(biome.getClass()))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Predicate<BiomeGenBase> biomeClassNameFilter(final String... names) {
|
|
||||||
return new Predicate<BiomeGenBase>() {
|
|
||||||
public boolean apply(BiomeGenBase biome) {
|
|
||||||
for (String name : names) if (biome.getClass().getName().toLowerCase().contains(name.toLowerCase())) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -80,6 +80,9 @@ betterfoliage.coral.biomeList=Biome List
|
|||||||
betterfoliage.coral.biomeList.tooltip=Configure which biomes coral is allowed to appear in
|
betterfoliage.coral.biomeList.tooltip=Configure which biomes coral is allowed to appear in
|
||||||
betterfoliage.coral.biomeSelectTooltip=Should coral appear in the %s biome?
|
betterfoliage.coral.biomeSelectTooltip=Should coral appear in the %s biome?
|
||||||
|
|
||||||
|
betterfoliage.netherrack=Netherrack Vines
|
||||||
|
betterfoliage.netherrack.tooltip=Hanging Vines under netherrack
|
||||||
|
|
||||||
betterfoliage.fallingLeaves=Falling leaves
|
betterfoliage.fallingLeaves=Falling leaves
|
||||||
betterfoliage.fallingLeaves.tooltip=Falling leaf particle FX emitted from the bottom of leaf blocks
|
betterfoliage.fallingLeaves.tooltip=Falling leaf particle FX emitted from the bottom of leaf blocks
|
||||||
betterfoliage.fallingLeaves.speed=Particle speed
|
betterfoliage.fallingLeaves.speed=Particle speed
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Vanilla
|
||||||
|
spruce=spruce
|
||||||
|
jungle=jungle
|
||||||
|
|
||||||
|
// Biomes O' Plenty
|
||||||
|
fir=spruce
|
||||||
|
After Width: | Height: | Size: 286 B |
|
After Width: | Height: | Size: 265 B |
|
After Width: | Height: | Size: 274 B |
|
After Width: | Height: | Size: 278 B |
|
After Width: | Height: | Size: 255 B |
|
After Width: | Height: | Size: 244 B |
|
After Width: | Height: | Size: 231 B |
|
After Width: | Height: | Size: 236 B |