diff --git a/MODSRC/vazkii/botania/common/Botania.java b/MODSRC/vazkii/botania/common/Botania.java index e6dcb185f..bcee6077e 100644 --- a/MODSRC/vazkii/botania/common/Botania.java +++ b/MODSRC/vazkii/botania/common/Botania.java @@ -45,6 +45,7 @@ public class Botania { @EventHandler public void postInit(FMLPostInitializationEvent event) { proxy.postInit(event); +// Corruption.init(); } @EventHandler diff --git a/MODSRC/vazkii/botania/test/Corruption.java b/MODSRC/vazkii/botania/test/Corruption.java index 2b12dd462..1543b6e52 100644 --- a/MODSRC/vazkii/botania/test/Corruption.java +++ b/MODSRC/vazkii/botania/test/Corruption.java @@ -11,6 +11,55 @@ */ package vazkii.botania.test; +import java.awt.Color; +import java.awt.image.BufferedImage; +import java.util.Random; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityClientPlayerMP; +import net.minecraft.client.renderer.ThreadDownloadImageData; +import vazkii.botania.common.lib.LibObfuscation; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent; +import cpw.mods.fml.common.gameevent.TickEvent.Phase; +import cpw.mods.fml.relauncher.ReflectionHelper; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + public class Corruption { + Random rand = new Random(); + + public static void init() { + FMLCommonHandler.instance().bus().register(new Corruption()); + } + + @SubscribeEvent + @SideOnly(Side.CLIENT) + public void onPlayerTick(ClientTickEvent event) { + if(event.phase == Phase.END) { + EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer; + if(player != null && player.ticksExisted > 300) { + ThreadDownloadImageData tex = player.getTextureSkin(); + BufferedImage img = ReflectionHelper.getPrivateValue(ThreadDownloadImageData.class, tex, LibObfuscation.BUFFERED_IMAGE); + if(img != null) + for(int i = 0; i < 1 + (player.ticksExisted - 300) / 30; i++) + corruptRandomPixel(tex, img); + } + } + } + + public void corruptRandomPixel(ThreadDownloadImageData tex, BufferedImage img) { + int width = img.getWidth(); + int height = img.getHeight(); + + int x = rand.nextInt(width); + int y = rand.nextInt(height); + Color color = new Color(img.getRGB(x, y)); + if(color.getRed() + color.getGreen() + color.getRed() > 0) + img.setRGB(x, y, color.darker().darker().getRGB()); + ReflectionHelper.setPrivateValue(ThreadDownloadImageData.class, tex, false, LibObfuscation.TEXTURE_UPLOADED); + } + }