7 Commits

Author SHA1 Message Date
octarine-noise
ec723113d3 bump version 2014-07-26 10:00:58 +02:00
octarine-noise
4e42f63c36 don't alter ShaderMod special textures 2014-07-25 20:59:21 +02:00
octarine-noise
0daf61583a fixed leaves and grass block data for ShadersMod integration 2014-07-25 15:57:27 +02:00
octarine-noise
504f033c2e only rebuild block ID cache on client world load 2014-07-24 17:59:06 +02:00
octarine-noise
fa099b1b97 fix deadlock issue during class transformation 2014-07-24 17:50:06 +02:00
octarine-noise
b0c0cd0d1b avoid Class.forName() in world loading event 2014-07-24 01:03:35 +02:00
octarine-noise
df69605521 Update README.md 2014-07-23 02:19:18 +02:00
6 changed files with 45 additions and 59 deletions

View File

@@ -6,6 +6,4 @@ More info: http://www.minecraftforum.net/topic/2776217-better-foliage/
Download
========
[BetterFoliage 0.9.4-beta] (http://goo.gl/pNBE23) (MC 1.7.2)
[BetterFoliage 0.9.4-beta] (http://goo.gl/ywT6Xg) (MC 1.7.10)
[BetterFoliage 0.9.6-beta] (http://goo.gl/8qVKMl) (MC 1.7.2 & 1.7.10)

View File

@@ -22,7 +22,7 @@ minecraft {
jar.baseName = 'BetterFoliage'
group = 'com.github.octarine-noise'
version='0.9.6b'
version='0.9.7b'
processResources {
inputs.property "version", project.version

View File

@@ -2,16 +2,14 @@ package mods.betterfoliage.client;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
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.multiplayer.WorldClient;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.world.WorldEvent;
@@ -21,30 +19,22 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class BlockMatcher {
public Set<String> whiteList = Sets.newHashSet();
public Set<String> blackList = Sets.newHashSet();
public Set<Class<?>> whiteList = Sets.newHashSet();
public Set<Class<?>> blackList = Sets.newHashSet();
public Set<Integer> blockIDs = Sets.newHashSet();
public void addClass(String className) {
if (className.startsWith("-"))
blackList.add(className.substring(1));
else
whiteList.add(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 (String className : blackList) {
try {
Class<?> clazz = Class.forName(className);
if (clazz.isAssignableFrom(block.getClass())) return false;
} catch(ClassNotFoundException e) {}
}
for (String className : whiteList) {
try {
Class<?> clazz = Class.forName(className);
if (clazz.isAssignableFrom(block.getClass())) return true;
} catch(ClassNotFoundException e) {}
}
for (Class<?> clazz : blackList) if (clazz.isAssignableFrom(block.getClass())) return false;
for (Class<?> clazz : whiteList) if (clazz.isAssignableFrom(block.getClass())) return true;
return false;
}
@@ -70,40 +60,19 @@ public class BlockMatcher {
line = reader.readLine();
}
reader.close();
} catch (FileNotFoundException e) {
saveDefaults(file);
} catch (IOException e) {
} catch (Exception e) {
BetterFoliage.log.warn(String.format("Error reading configuration: %s", file.getName()));
}
}
public void saveDefaults(File file) {
FileWriter writer = null;
try {
writer = new FileWriter(file);
for (String className : whiteList) {
writer.write(className);
writer.write("\n");
}
for (String className : blackList) {
writer.write("-");
writer.write(className);
writer.write("\n");
}
writer.close();
} catch (FileNotFoundException e) {
saveDefaults(file);
} catch (IOException e) {
BetterFoliage.log.warn(String.format("Error writing default configuration: %s", file.getName()));
}
}
/** 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()) {

View File

@@ -48,8 +48,8 @@ public class ShadersModIntegration {
}
public static int getBlockIdOverride(int original, Block block) {
if (BetterFoliageClient.leaves.matchesID(original & 0xFFFF)) return tallGrassEntityData;
if (BetterFoliageClient.crops.matchesID(original & 0xFFFF)) return leavesEntityData;
if (BetterFoliageClient.leaves.matchesID(original & 0xFFFF)) return leavesEntityData;
if (BetterFoliageClient.crops.matchesID(original & 0xFFFF)) return tallGrassEntityData;
return original;
}
}

View File

@@ -39,8 +39,14 @@ public class LeafTextureResource implements IResource {
IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
try {
// load normal leaf texture
ResourceLocation origResource = new ResourceLocation(resLeaf.getResourceDomain(), "textures/blocks/" + resLeaf.getResourcePath());
if (origResource.getResourcePath().toLowerCase().endsWith("_n.png") || origResource.getResourcePath().toLowerCase().endsWith("_s.png")) {
// Don't alter ShaderMod normal and specular maps
fallbackResource = resourceManager.getResource(origResource);
return;
}
// load normal leaf texture
BufferedImage origImage = ImageIO.read(resourceManager.getResource(origResource).getInputStream());
if (origImage.getWidth() != origImage.getHeight()) return;
int size = origImage.getWidth();

View File

@@ -49,20 +49,33 @@ public class EZTransformerBase implements IClassTransformer {
for (Method classMethod : getClass().getMethods()) {
// check for annotated method with correct signature
MethodTransform annot = classMethod.getAnnotation(MethodTransform.class);
if (annot == null) continue;
String aClassName = null;
String aMethodName = null;
String aSignature = null;
String aLog = null;
synchronized (this) {
MethodTransform annotation = classMethod.getAnnotation(MethodTransform.class);
if (annotation != null) {
aClassName = annotation.className();
aMethodName = annotation.methodName();
aSignature = annotation.signature();
aLog = annotation.log();
}
}
if (aClassName == null) continue;
if (classMethod.getParameterTypes().length != 1) continue;
if (!classMethod.getParameterTypes()[0].equals(MethodNode.class)) continue;
// try to find specified method in class
if (!transformedName.equals(annot.className())) continue;
if (!transformedName.equals(aClassName)) continue;
logger.debug(String.format("Found class: %s -> %s", name, transformedName));
for (MethodNode methodNode : classNode.methods) {
logger.trace(String.format("Checking method: %s, sig: %s", methodNode.name, methodNode.desc));
isObfuscated = null;
if (methodNode.name.equals(DeobfHelper.transformElementName(annot.methodName())) && methodNode.desc.equals(DeobfHelper.transformSignature(annot.signature()))) {
if (methodNode.name.equals(DeobfHelper.transformElementName(aMethodName)) && methodNode.desc.equals(DeobfHelper.transformSignature(aSignature))) {
isObfuscated = true;
} else if (methodNode.name.equals(annot.methodName()) && methodNode.desc.equals(annot.signature())) {
} else if (methodNode.name.equals(aMethodName) && methodNode.desc.equals(aSignature)) {
isObfuscated = false;
}
@@ -71,9 +84,9 @@ public class EZTransformerBase implements IClassTransformer {
hasTransformed = true;
try {
classMethod.invoke(this, new Object[] {methodNode});
logger.info(String.format("%s: SUCCESS", annot.log()));
logger.info(String.format("%s: SUCCESS", aLog));
} catch (Exception e) {
logger.info(String.format("%s: FAILURE", annot.log()));
logger.info(String.format("%s: FAILURE", aLog));
}
break;
}