tons of javadoc and cleanup

This commit is contained in:
octarine-noise
2014-08-11 01:38:35 +02:00
parent bae6d9b598
commit 2b1cab8e62
17 changed files with 194 additions and 28 deletions

View File

@@ -9,6 +9,9 @@ import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.util.ResourceLocation;
/** Call hooks and helper methods for dealing with Shaders Mod.
* @author octarine-noise
*/
@SideOnly(Side.CLIENT)
public class ShadersModIntegration {
@@ -18,6 +21,7 @@ public class ShadersModIntegration {
private static Field shadersEntityData;
private static Field shadersEntityDataIndex;
/** Hide constructor */
private ShadersModIntegration() {}
public static void init() {
@@ -33,16 +37,24 @@ public class ShadersModIntegration {
}
}
/** Signal start of grass-type quads
*/
public static void startGrassQuads() {
if (!hasShadersMod) return;
setShadersEntityData(tallGrassEntityData);
}
/** Signal start of leaf-type quads
*/
public static void startLeavesQuads() {
if (!hasShadersMod) return;
setShadersEntityData(leavesEntityData);
}
/** Change the entity data (containing block ID) for the currently rendered block.
* Quads drawn afterwards will have the altered data.
* @param data
*/
private static void setShadersEntityData(int data) {
try {
int[] entityData = (int[]) shadersEntityData.get(null);
@@ -52,12 +64,21 @@ public class ShadersModIntegration {
}
}
/** Call hook from transformed ShadersMod class
* @param original entity data of currently rendered block
* @param block the block
* @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;
return original;
}
/**
* @param resource texture resource
* @return true if texture is a normal or specular map
*/
public static boolean isSpecialTexture(ResourceLocation resource) {
return resource.getResourcePath().toLowerCase().endsWith("_n.png") || resource.getResourcePath().toLowerCase().endsWith("_s.png");
}

View File

@@ -6,10 +6,25 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.world.IBlockAccess;
/** Block rendering handler that is only used under certain conditions
* @author octarine-noise
*/
@SideOnly(Side.CLIENT)
public interface IRenderBlockDecorator extends ISimpleBlockRenderingHandler {
/** Initialize necessary helper values
*/
public void init();
/**
* @param blockAccess the world
* @param x
* @param y
* @param z
* @param block
* @param original renderType of the block
* @return true if this renderer should handle this block
*/
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original);
}

View File

@@ -7,7 +7,7 @@ import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/** Loads an indexed set of textures
/** Holds an indexed set of textures
* @author octarine-noise
*/
@SideOnly(Side.CLIENT)

View File

@@ -24,7 +24,10 @@ public class RenderBlockBetterCactus extends FakeRenderBlockAOBase implements IR
public IIcon cactusRoundIcon;
public IconSet cactusSideIcons = new IconSet("bettergrassandleaves", "better_cactus_arm_%d");
/** Possible directions for cactus side growth*/
public static ForgeDirection[] cactusDirections = new ForgeDirection[] { ForgeDirection.NORTH, ForgeDirection.SOUTH, ForgeDirection.EAST, ForgeDirection.WEST};
/** Inner radius of cactus stem */
public static double cactusRadius = 0.4375;
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
@@ -43,9 +46,9 @@ public class RenderBlockBetterCactus extends FakeRenderBlockAOBase implements IR
// render cactus center
setPassCounters(1);
renderStandardBlock(block, x, y, z);
Double3 blockCenter = new Double3(x + 0.5, y + 0.5, z + 0.5);
renderStandardBlock(block, x, y, z);
Tessellator.instance.setBrightness(getBrightness(block,x, y, z));
renderCactusCore(block.getBlockTextureFromSide(ForgeDirection.UP.ordinal()),
block.getBlockTextureFromSide(ForgeDirection.NORTH.ordinal()),

View File

@@ -21,6 +21,10 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/** Base class for texture generators. Registers itself as a domain resource manager for the duration of block texture stitching.
* @author octarine-noise
*
*/
@SideOnly(Side.CLIENT)
public abstract class BlockTextureGenerator implements IResourceManager {

View File

@@ -14,6 +14,9 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.data.IMetadataSection;
/** {@link IResource} for a {@link BufferedImage}
* @author octarine-noise
*/
@SideOnly(Side.CLIENT)
public class BufferedImageResource implements IResource {

View File

@@ -47,12 +47,10 @@ public class LeafGenerator extends LeafGeneratorBase {
BufferedImage maskImage = loadLeafMaskImage(defaultMask, size * 2);
int scale = size * 2 / maskImage.getWidth();
for (int x = 0; x < overlayIcon.getWidth(); x++) {
for (int y = 0; y < overlayIcon.getHeight(); y++) {
long origPixel = overlayIcon.getRGB(x, y) & 0xFFFFFFFFl;
long maskPixel = maskImage.getRGB(x / scale, y / scale) & 0xFF000000l | 0x00FFFFFF;
overlayIcon.setRGB(x, y, (int) (origPixel & maskPixel));
}
for (int x = 0; x < overlayIcon.getWidth(); x++) for (int y = 0; y < overlayIcon.getHeight(); y++) {
long origPixel = overlayIcon.getRGB(x, y) & 0xFFFFFFFFl;
long maskPixel = maskImage.getRGB(x / scale, y / scale) & 0xFF000000l | 0x00FFFFFF;
overlayIcon.setRGB(x, y, (int) (origPixel & maskPixel));
}
}

View File

@@ -16,9 +16,14 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/** Texture generator base class for textures based on leaf blocks.
* Supports loading from resource packs instead of generating if available.
* @author octarine-noise
*/
@SideOnly(Side.CLIENT)
public abstract class LeafGeneratorBase extends BlockTextureGenerator {
@SideOnly(Side.CLIENT)
public static class TextureGenerationException extends Exception {
private static final long serialVersionUID = 7339757761980002651L;
};

View File

@@ -22,7 +22,6 @@ import cpw.mods.fml.relauncher.SideOnly;
/** Holds the texture for the falling leaf particles, and stores average texture color values for leaf textures
* @author octarine-noise
*
*/
@SideOnly(Side.CLIENT)
public class LeafParticleTextures {
@@ -59,18 +58,16 @@ public class LeafParticleTextures {
float sumHueY = 0.0f;
float sumSaturation = 0.0f;
float sumBrightness = 0.0f;
for (int x = 0; x < image.getWidth(); x++) {
for (int y = 0; y < image.getHeight(); y++) {
int pixel = image.getRGB(x, y);
int alpha = (pixel >> 24) & 0xFF;
float[] hsbVals = Color.RGBtoHSB((pixel >> 16) & 0xFF, (pixel >> 8) & 0xFF, pixel & 0xFF, null);
if (alpha == 255) {
numOpaque++;
sumHueX += Math.cos((hsbVals[0] - 0.5) * 2.0 * Math.PI);
sumHueY += Math.sin((hsbVals[0] - 0.5) * 2.0 * Math.PI);
sumSaturation += hsbVals[1];
sumBrightness += hsbVals[2];
}
for (int x = 0; x < image.getWidth(); x++) for (int y = 0; y < image.getHeight(); y++) {
int pixel = image.getRGB(x, y);
int alpha = (pixel >> 24) & 0xFF;
float[] hsbVals = Color.RGBtoHSB((pixel >> 16) & 0xFF, (pixel >> 8) & 0xFF, pixel & 0xFF, null);
if (alpha == 255) {
numOpaque++;
sumHueX += Math.cos((hsbVals[0] - 0.5) * 2.0 * Math.PI);
sumHueY += Math.sin((hsbVals[0] - 0.5) * 2.0 * Math.PI);
sumSaturation += hsbVals[1];
sumBrightness += hsbVals[2];
}
}

View File

@@ -23,12 +23,21 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/** Enumerates all leaf textures at stitch time and emits an event for each.
* @author octarine-noise
*/
@SideOnly(Side.CLIENT)
public class LeafTextureEnumerator implements IIconRegister {
/**{@link Event} that is emitted for each texture belonging to a leaf block.
* @author octarine-noise
*/
@SideOnly(Side.CLIENT)
public static class LeafTextureFoundEvent extends Event {
public TextureMap blockTextures;
public TextureAtlasSprite icon;
private LeafTextureFoundEvent(TextureMap blockTextures, TextureAtlasSprite icon) {
super();
this.blockTextures = blockTextures;
@@ -39,8 +48,7 @@ public class LeafTextureEnumerator implements IIconRegister {
/** Texture atlas for block textures used in the current run */
public TextureMap blockTextures;
/** Leaf blocks register their textures here. An extra texture will be registered in the atlas
* for each, with the resource domain of this generator.
/** Leaf blocks register their textures here.
* @return the originally registered {@link IIcon} already in the atlas
*/
public IIcon registerIcon(String resourceLocation) {
@@ -76,6 +84,7 @@ public class LeafTextureEnumerator implements IIconRegister {
Map<String, TextureAtlasSprite> mapAtlas = null;
mapAtlas = Utils.getField(blockTextures, DeobfHelper.transformElementSearge("mapRegisteredSprites"), Map.class);
if (mapAtlas == null) mapAtlas = Utils.getField(blockTextures, "mapRegisteredSprites", Map.class);
if (mapAtlas == null) {
BetterFoliage.log.warn("Failed to reflect texture atlas, textures may be missing");
} else {

View File

@@ -10,8 +10,14 @@ import java.lang.reflect.Field;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
/** Config base class using annotations
* @author octarine-noise
*/
public class ConfigBase {
/** Annotates a field linked to a config file property
* @author octarine-noise
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public static @interface CfgElement {
@@ -20,6 +26,9 @@ public class ConfigBase {
String comment() default "";
}
/** Declares a min/max limit on another field
* @author octarine-noise
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public static @interface Limit {

View File

@@ -2,6 +2,9 @@ package mods.betterfoliage.common.util;
import net.minecraftforge.common.util.ForgeDirection;
/** Immutable 3D vector of double precision.
* @author octarine-noise
*/
public class Double3 {
public final double x;

View File

@@ -14,19 +14,24 @@ 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 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, "domainResourceManagers", Map.class);
if (result == null) result = getField(manager, DeobfHelper.transformElementSearge("domainResourceManagers"), Map.class);
Map<String, IResourceManager> result = getField(manager, DeobfHelper.transformElementSearge("domainResourceManagers"), Map.class);
if (result == null) result = getField(manager, "domainResourceManagers", Map.class);
return result;
}
@@ -52,6 +57,10 @@ public class Utils {
}
}
/** 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 {
@@ -66,6 +75,10 @@ public class Utils {
}
}
/** 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);
@@ -75,6 +88,10 @@ public class Utils {
return false;
}
/** Copy a text file from a resource to the filesystem
* @param resourceLocation resource location of text file
* @param target target file
*/
public static void copyFromTextResource(ResourceLocation resourceLocation, File target) {
try {
IResource defaults = Minecraft.getMinecraft().getResourceManager().getResource(resourceLocation);

View File

@@ -41,18 +41,34 @@ public class DeobfHelper {
}
}
/** Transform a class name from MCP to obfuscated names.
* @param className MCP name
* @return obfuscated name
*/
public static String transformClassName(String className) {
return obfClasses.containsKey(className) ? obfClasses.get(className) : className;
}
/** Transform a method or field name from MCP to obfuscated names.
* @param elementName MCP name
* @return obfuscated name
*/
public static String transformElementName(String elementName) {
return obfElements.containsKey(elementName) ? obfElements.get(elementName) : elementName;
}
/** Transform a method or field name from MCP to SRG names.
* @param elementName MCP name
* @return SRG name
*/
public static String transformElementSearge(String elementName) {
return srgElements.containsKey(elementName) ? srgElements.get(elementName) : elementName;
}
/** Transform an ASM signature from MCP to obfuscated names.
* @param signature MCP signature
* @return obfuscated signature
*/
public static String transformSignature(String signature) {
String result = signature;
boolean hasChanged = false;

View File

@@ -5,31 +5,76 @@ import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
/** Base class for class transformers operating on a single method.
* @author octarine-noise
*/
public abstract class MethodTransformerBase {
/** Instruction node filter
* @author octarine-noise
*/
public static interface IInstructionMatch {
public boolean matches(AbstractInsnNode node);
}
/**
* @return MCP name of the class to transform
*/
public abstract String getClassName();
/**
* @return MCP name of the method to transform
*/
public abstract String getMethodName();
/**
* @return ASM signature of the method to transform using MCP names
*/
public abstract String getSignature();
/**
* @return Log message to write when method is found
*/
public abstract String getLogMessage();
public abstract void transform(MethodNode method, boolean obf);
/** Transform method node
* @param method method node
* @param isObfuscated true for obfuscated environment
*/
public abstract void transform(MethodNode method, boolean isObfuscated);
/** Transform a class name from MCP to obfuscated names if necessary.
* @param className MCP name
* @param isObfuscated true for obfuscated environment
* @return transformed name
*/
protected static String className(String className, boolean isObfuscated) {
return isObfuscated ? DeobfHelper.transformClassName(className) : className;
}
/** Transform a method or field name from MCP to obfuscated names if necessary.
* @param fieldName MCP name
* @param isObfuscated true for obfuscated environment
* @return transformed name
*/
protected static String element(String fieldName, boolean isObfuscated) {
return isObfuscated ? DeobfHelper.transformElementName(fieldName) : fieldName;
}
/** Transform an ASM signature from MCP to obfuscated names if necessary.
* @param signature MCP signature
* @param isObfuscated true for obfuscated environment
* @return transformed signature
*/
protected static String signature(String signature, boolean isObfuscated) {
return isObfuscated ? DeobfHelper.transformSignature(signature) : signature;
}
/** Find the next instruction node in an instruction list starting from a given node, matching a given filter
* @param start start node
* @param match filter
* @return instruction node if found, null otherwise
*/
protected AbstractInsnNode findNext(AbstractInsnNode start, IInstructionMatch match) {
AbstractInsnNode current = start;
while(current != null) {
@@ -39,6 +84,11 @@ public abstract class MethodTransformerBase {
return current;
}
/** Find the previous instruction node in a list starting from a given node, matching a given filter
* @param start start node
* @param match filter
* @return instruction node if found, null otherwise
*/
protected AbstractInsnNode findPrevious(AbstractInsnNode start, IInstructionMatch match) {
AbstractInsnNode current = start;
while(current != null) {
@@ -48,6 +98,9 @@ public abstract class MethodTransformerBase {
return current;
}
/**
* @return an instruction node filter matching any invoke instruction
*/
protected IInstructionMatch matchInvokeAny() {
return new IInstructionMatch() {
public boolean matches(AbstractInsnNode node) {
@@ -56,6 +109,9 @@ public abstract class MethodTransformerBase {
};
}
/**
* @return an instruction node filter matching the given opcode
*/
protected IInstructionMatch matchOpcode(final int opcode) {
return new IInstructionMatch() {
public boolean matches(AbstractInsnNode node) {
@@ -64,12 +120,22 @@ public abstract class MethodTransformerBase {
};
}
/** Insert a list of instruction nodes in a list after a given node
* @param insnList instruction list
* @param node start node
* @param added instructions to add
*/
protected void insertAfter(InsnList insnList, AbstractInsnNode node, AbstractInsnNode... added) {
InsnList listAdd = new InsnList();
for (AbstractInsnNode inst : added) listAdd.add(inst);
insnList.insert(node, listAdd);
}
/** Insert a list of instruction nodes in a list before a given node
* @param insnList instruction list
* @param node start node
* @param added instructions to add
*/
protected void insertBefore(InsnList insnList, AbstractInsnNode node, AbstractInsnNode... added) {
InsnList listAdd = new InsnList();
for (AbstractInsnNode inst : added) listAdd.add(inst);

View File

@@ -26,7 +26,7 @@ public class TransformRenderBlockOverride extends MethodTransformerBase {
@Override
public String getLogMessage() {
return "Applying RenderBlocks.renderBlockByRenderType() render type ovverride";
return "Applying RenderBlocks.renderBlockByRenderType() render type override";
}
@Override

View File

@@ -25,7 +25,7 @@ public class TransformShaderModBlockOverride extends MethodTransformerBase {
@Override
public String getLogMessage() {
return "Applying Shaders.pushEntity() block id ovverride";
return "Applying Shaders.pushEntity() block id override";
}
@Override