Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Merge branch '1.9.4' into 1.10.2
Browse files Browse the repository at this point in the history
Conflicts:
	build.gradle
	gradle.properties
	src/main/java/com/kamesuta/mc/signpic/asm/SignPictureCorePlugin.java
  • Loading branch information
Kamesuta committed Dec 18, 2016
2 parents 0e31dfa + 3d67f0d commit fb1bfcb
Show file tree
Hide file tree
Showing 20 changed files with 135 additions and 72 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ dependencies {
def commonManifest = {
if (project.hasProperty('extra_fmlcore'))
attributes 'FMLCorePlugin': project.extra_fmlcore
if (project.hasProperty('extra_fmlcoremod'))
if (project.hasProperty('extra_fmlmod'))
attributes 'FMLCorePluginContainsFMLMod': project.extra_fmlcore
if (project.hasProperty('extra_fmlat'))
attributes 'FMLAT': project.extra_fmlat
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ group=com.kamesuta.mc
modid=signpic
modname=SignPicture
extra_fmlcore=com.kamesuta.mc.signpic.asm.SignPictureCorePlugin
extra_fmlcoremod=com.kamesuta.mc.signpic.SignPicture
extra_fmlmod=com.kamesuta.mc.signpic.SignPicture
version_major=2
version_minor=6
version_micro=1
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/kamesuta/mc/bnnwidget/StencilClip.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static void init() {
ReflectionHelper.<BitSet, MinecraftForgeClient> getPrivateValue(MinecraftForgeClient.class, null, "stencilBits").set(0, 8);
}
} catch (final Throwable e) {
Log.info("Failed to enable stencil buffer", e);
Log.log.info("Failed to enable stencil buffer", e);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/kamesuta/mc/signpic/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static void deleteMod(final File mod) {
if (!mod.delete()) {
mod.deleteOnExit();
final String msg = Reference.NAME+" was unable to delete file "+mod.getPath()+" the game will now try to delete it on exit. If this dialog appears again, delete it manually.";
Log.error(msg);
Log.log.error(msg);
if (!GraphicsEnvironment.isHeadless())
JOptionPane.showMessageDialog(null, msg, "An update error has occured", JOptionPane.ERROR_MESSAGE);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/kamesuta/mc/signpic/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private File getDataDirectory() {
try {
return file.getCanonicalFile();
} catch (final IOException e) {
Log.debugerror("Could not canonize path!", e);
Log.dev.error("Could not canonize path!", e);
}
return file;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/kamesuta/mc/signpic/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class CommonProxy {
public void preInit(final FMLPreInitializationEvent event) {
Log.logger = event.getModLog();
Log.log = event.getModLog();
Config.instance = new Config(event.getSuggestedConfigurationFile());
}

Expand Down
15 changes: 14 additions & 1 deletion src/main/java/com/kamesuta/mc/signpic/Debug.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

import org.apache.commons.lang3.StringUtils;

import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntitySign;
import net.minecraft.util.math.AxisAlignedBB;

public class Debug {
public static void main(final String[] args) throws Exception {
// Reference.logger.info(ImageSizes.LIMIT.size(32, 24, 10, 12));
Expand Down Expand Up @@ -53,7 +57,7 @@ public static void main(final String[] args) throws Exception {
// Reference.logger.info(String.format("R:%.04f G:%.04f B:%.04f A:%.04f", r, g, b, a));

final String src = "gyazo.com/114514e";
Log.info(replace(src));
Log.log.info(replace(src));
}

final static Pattern p = Pattern.compile("[^\\w]");
Expand Down Expand Up @@ -91,6 +95,15 @@ static boolean isPlaceable(final String entryId) {
return StringUtils.length(entryId)<=15*4;
}

public static class DebugSign extends TileEntitySign {
@Override
public AxisAlignedBB getRenderBoundingBox() {
if (this instanceof TileEntitySign)
return TileEntity.INFINITE_EXTENT_AABB;
return super.getRenderBoundingBox();
}
}

// TODO: Fix and test this method.
// static void PostData() throws Exception {
// final String url = "https://upload.gyazo.com/api/upload";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/kamesuta/mc/signpic/Locations.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private File getSignPicDir(final File defaultdir) {
if (!StringUtils.isEmpty(Config.instance.signpicDir.get())) {
if (dir.exists()&&dir.isDirectory()&&!dir.equals(defaultdir))
return dir;
Log.debugerror("invalid signpic dir location! use default dir.");
Log.dev.error("invalid signpic dir location! use default dir.");
}
return new File(defaultdir, "signpic");
}
Expand All @@ -53,7 +53,7 @@ private boolean securementDirectory(final File cachedir) {
i++;
} while (to.exists());
cachedir.renameTo(to);
Log.warn("non-directory conflicting file exists. renamed to "+to.getName());
Log.log.warn("non-directory conflicting file exists. renamed to "+to.getName());
return true;
}
cachedir.mkdir();
Expand Down
94 changes: 47 additions & 47 deletions src/main/java/com/kamesuta/mc/signpic/Log.java
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
package com.kamesuta.mc.signpic;

import javax.annotation.Nonnull;

import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.spi.AbstractLogger;

import com.kamesuta.mc.signpic.gui.OverlayFrame;

public class Log {
public static Logger logger = LogManager.getLogger(Reference.MODID);
public static Logger log = LogManager.getLogger(Reference.MODID);
public static Logger dev = new DevLogger(log);

public static void error(final Object message) {
logger.error(message);
}
private static class DevLogger extends AbstractLogger {
private Logger logger;

public static void error(final Object message, final Throwable e) {
logger.error(message, e);
}
public DevLogger(@Nonnull final Logger logger) {
this.logger = logger;
}

public static void warn(final Object message) {
logger.warn(message);
}
private boolean isEnabled() {
Validate.notNull(Config.instance, "internal error: debug logger can be used after config loaded!");
return Config.instance.debugLog.get();
}

public static void warn(final Object message, final Throwable e) {
logger.warn(message, e);
}
@Override
protected boolean isEnabled(final Level level, final Marker marker, final Message data, final Throwable t) {
return isEnabled();
}

public static void info(final Object message) {
logger.info(message);
}
@Override
protected boolean isEnabled(final Level level, final Marker marker, final Object data, final Throwable t) {
return isEnabled();
}

public static void info(final Object message, final Throwable e) {
logger.info(message, e);
}
@Override
protected boolean isEnabled(final Level level, final Marker marker, final String data) {
return isEnabled();
}

public static void debugerror(final Object message) {
if (Config.instance.debugLog.get())
logger.error("[DEBUG] "+message);
}
@Override
protected boolean isEnabled(final Level level, final Marker marker, final String data, final Object... p1) {
return isEnabled();
}

public static void debugerror(final Object message, final Throwable e) {
if (Config.instance.debugLog.get())
logger.error("[DEBUG] "+message, e);
}

public static void debugwarn(final Object message) {
if (Config.instance.debugLog.get())
logger.warn("[DEBUG] "+message);
}

public static void debugwarn(final Object message, final Throwable e) {
if (Config.instance.debugLog.get())
logger.warn("[DEBUG] "+message, e);
}

public static void debuginfo(final Object message) {
if (Config.instance.debugLog.get())
logger.info("[DEBUG] "+message);
}
@Override
protected boolean isEnabled(final Level level, final Marker marker, final String data, final Throwable t) {
return isEnabled();
}

public static void debuginfo(final Object message, final Throwable e) {
if (Config.instance.debugLog.get())
logger.info("[DEBUG] "+message, e);
@Override
public void log(final Marker marker, final String fqcn, final Level level, final Message data, final Throwable t) {
if (isEnabled())
this.logger.log(level, marker, "[DEBUG] "+data.getFormattedMessage(), t);
}
}

@SuppressWarnings("deprecation")
public static void notice(final Object notice, final float duration) {
OverlayFrame.instance.pane.addNotice1(notice.toString(), duration);
debuginfo(notice);
if (dev!=null)
dev.info(notice);
}

@SuppressWarnings("deprecation")
public static void notice(final String notice, final Throwable e, final float duration) {
OverlayFrame.instance.pane.addNotice1(notice, duration);
debuginfo(notice, e);
if (dev!=null)
dev.info(notice, e);
}

public static void notice(final String notice) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public HookMethodVisitor(final MethodVisitor mv) {
@Override
public void visitFieldInsn(final int opcode, final String owner, final String name, final String desc) {
super.visitFieldInsn(opcode, "net/minecraft/tileentity/TileEntity", "INFINITE_EXTENT_AABB", desc);
Log.info("BlockSign patch applied. You can see the sign from any angle");
Log.log.info("BlockSign patch applied. You can see the sign from any angle");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class SignPictureCorePlugin implements IFMLLoadingPlugin {
@Override
public String[] getASMTransformerClass() {
return new String[] {
SignPictureClassTransformer.class.getName()
SignPictureTransformer.class.getName()
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@

import net.minecraft.launchwrapper.IClassTransformer;

public class SignPictureClassTransformer implements IClassTransformer {
public class SignPictureTransformer implements IClassTransformer {

@Override
public byte[] transform(final String name, final String transformedName, final byte[] bytes) {
if (bytes==null)
return bytes;

if (transformedName.equals("net.minecraft.block.BlockSign"))
if (transformedName.equals("net.minecraft.tileentity.TileEntity"))
return VisitorHelper.apply(bytes, name, new TransformProvider(ClassWriter.COMPUTE_FRAMES) {
@Override
public ClassVisitor createVisitor(final String name, final ClassVisitor cv) {
Log.info(String.format("Trying to patch BlockSign.getCollisionBoundingBox (class: %s)", name));
return new BlockSignVisitor(name, cv);
Log.log.info(String.format("Patching TileEntity.getRenderBoundingBox (class: %s)", name));
return new TileEntityVisitor(name, cv);
}
});

Expand Down
50 changes: 50 additions & 0 deletions src/main/java/com/kamesuta/mc/signpic/asm/TileEntityVisitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.kamesuta.mc.signpic.asm;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

import com.kamesuta.mc.signpic.asm.lib.DescHelper;
import com.kamesuta.mc.signpic.asm.lib.MethodMatcher;

public class TileEntityVisitor extends ClassVisitor {
private static class HookMethodVisitor extends MethodVisitor {
public HookMethodVisitor(final MethodVisitor mv) {
super(Opcodes.ASM5, mv);
}

@Override
public void visitCode() {
super.visitCode();
/*
* 0 aload_0 [this]
* 1 instanceof net.minecraft.tileentity.TileEntitySign [3]
* 4 ifeq 11
* 7 getstatic net.minecraft.tileentity.TileEntity.INFINITE_EXTENT_AABB : net.minecraft.util.math.AxisAlignedBB [16]
* 10 areturn
* 11 aload_0 [this]
*/
visitVarInsn(Opcodes.ALOAD, 0);
visitTypeInsn(Opcodes.INSTANCEOF, "net/minecraft/tileentity/TileEntitySign");
final Label skipReturn = new Label();
visitJumpInsn(Opcodes.IFEQ, skipReturn);
visitFieldInsn(Opcodes.GETSTATIC, "net/minecraft/tileentity/TileEntity", "INFINITE_EXTENT_AABB", DescHelper.toDesc("net.minecraft.util.math.AxisAlignedBB"));
visitInsn(Opcodes.ARETURN);
visitLabel(skipReturn);
}
}

private final MethodMatcher matcher;

public TileEntityVisitor(final String obfClassName, final ClassVisitor cv) {
super(Opcodes.ASM5, cv);
this.matcher = new MethodMatcher(obfClassName, DescHelper.toDesc("net.minecraft.util.math.AxisAlignedBB", new Object[0]), "getRenderBoundingBox", "func_184177_bl");
}

@Override
public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) {
final MethodVisitor parent = super.visitMethod(access, name, desc, signature, exceptions);
return this.matcher.match(name, desc) ? new HookMethodVisitor(parent) : parent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private E loadData() {
return data;
}
} catch (final Exception e) {
Log.warn("content meta data is broken. aborted. ["+this.location.getName()+"]");
Log.log.warn("content meta data is broken. aborted. ["+this.location.getName()+"]");
} finally {
IOUtils.closeQuietly(reader);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ protected void close() {

@Override
protected void apply(final File f) {
Log.info(f.getAbsolutePath());
Log.log.info(f.getAbsolutePath());
}

@Override
protected void transfer(final Transferable transferable) {
Log.info(transferable);
Log.log.info(transferable);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void init() {
guiEditSignTileEntity = field;
}
} catch (final SecurityException e) {
Log.error("Could not hook TileEntitySign field included in GuiEditSign", e);
Log.log.error("Could not hook TileEntitySign field included in GuiEditSign", e);
}
try {
final Field[] fields = GuiRepair.class.getDeclaredFields();
Expand All @@ -75,7 +75,7 @@ public static void init() {
}
}
} catch (final SecurityException e) {
Log.error("Could not hook GuiTextField or ContainerRepair field included in GuiRepair", e);
Log.log.error("Could not hook GuiTextField or ContainerRepair field included in GuiRepair", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected void afterWrite(final int n) throws IOException {
onDone(new CommunicateResponse(true, null));
return;
} catch (final Throwable e) {
Log.warn("Updater Downloading Error", e);
Log.log.warn("Updater Downloading Error", e);
final ITextComponent chat = new ChatBuilder().setChat(new TextComponentTranslation("signpic.versioning.error").setStyle(new Style().setColor(TextFormatting.RED))).build();
this.result = new ModDLResult(chat);
onDone(new CommunicateResponse(false, e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ImageMeta parse(final String src) {
b = parseMeta(src, key, value)&&b;
}
}
Log.debuginfo("signmeta={"+src+"}, unsupported="+!b);
Log.dev.info("signmeta={"+src+"}, unsupported="+!b);
this.hasInvalidMeta = this.hasInvalidMeta||!b;
return this;
}
Expand Down
Loading

0 comments on commit fb1bfcb

Please sign in to comment.