diff --git a/src/main/java/de/ellpeck/naturesaura/compat/patchouli/PatchouliCompat.java b/src/main/java/de/ellpeck/naturesaura/compat/patchouli/PatchouliCompat.java index ce7fe19e..6f2ecdd3 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/patchouli/PatchouliCompat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/patchouli/PatchouliCompat.java @@ -4,10 +4,13 @@ import de.ellpeck.naturesaura.ModConfig; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.api.multiblock.Matcher; import de.ellpeck.naturesaura.events.ClientEvents; +import de.ellpeck.naturesaura.renderers.SupporterFancyHandler; +import de.ellpeck.naturesaura.renderers.SupporterFancyHandler.FancyInfo; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.TextFormatting; import net.minecraftforge.fml.client.config.GuiUtils; @@ -48,9 +51,38 @@ public final class PatchouliCompat { Gui.drawModalRectWithCustomSizedTexture(x, y, 469, 0, 43, 42, 512, 256); if (mouseX >= x && mouseY >= y && mouseX < x + 43 && mouseY < y + 42) - GuiUtils.drawHoveringText(Collections.singletonList(TextFormatting.GOLD + "It's the author Ellpeck's birthday!"), + GuiUtils.drawHoveringText( + Collections.singletonList(TextFormatting.GOLD + "It's the author Ellpeck's birthday!"), mouseX, mouseY, gui.width, gui.height, 0, gui.mc.fontRenderer); } + + String name = gui.mc.player.getName(); + FancyInfo info = SupporterFancyHandler.FANCY_INFOS.get(name); + if (info != null) { + int x = gui.width / 2 - 272 / 2 + 20; + int y = gui.height / 2 + 180 / 2; + + RenderHelper.disableStandardItemLighting(); + GlStateManager.color(1, 1, 1, 1); + gui.mc.getTextureManager().bindTexture(ClientEvents.BOOK_GUI); + + Gui.drawModalRectWithCustomSizedTexture(x, y, 496, 44, 16, 18, 512, 256); + if (info.tier == 1) { + Gui.drawModalRectWithCustomSizedTexture(x, y, 496 - 16, 44, 16, 18, 512, 256); + } else { + float r = ((info.color >> 16) & 255) / 255F; + float g = ((info.color >> 8) & 255) / 255F; + float b = (info.color & 255) / 255F; + GlStateManager.color(r, g, b); + Gui.drawModalRectWithCustomSizedTexture(x, y, 496 - 32, 44, 16, 18, 512, 256); + } + + if (mouseX >= x && mouseY >= y && mouseX < x + 16 && mouseY < y + 18) + GuiUtils.drawHoveringText( + Collections.singletonList(TextFormatting.YELLOW + "Thanks for your support, " + name + "!"), + mouseX, mouseY, gui.width, gui.height, 0, gui.mc.fontRenderer); + + } } } diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java index 85769a56..adfe1b3a 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java @@ -8,6 +8,7 @@ import de.ellpeck.naturesaura.reg.IColorProvidingBlock; import de.ellpeck.naturesaura.reg.IColorProvidingItem; import de.ellpeck.naturesaura.reg.ITESRProvider; import de.ellpeck.naturesaura.renderers.PlayerLayerTrinkets; +import de.ellpeck.naturesaura.renderers.SupporterFancyHandler; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.ModelResourceLocation; @@ -44,6 +45,7 @@ public class ClientProxy implements IProxy { for (RenderPlayer render : new RenderPlayer[]{skinMap.get("default"), skinMap.get("slim")}) { render.addLayer(new PlayerLayerTrinkets()); } + new SupporterFancyHandler(); } @Override diff --git a/src/main/java/de/ellpeck/naturesaura/renderers/SupporterFancyHandler.java b/src/main/java/de/ellpeck/naturesaura/renderers/SupporterFancyHandler.java new file mode 100644 index 00000000..13be19f8 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/renderers/SupporterFancyHandler.java @@ -0,0 +1,113 @@ +package de.ellpeck.naturesaura.renderers; + +import com.google.gson.*; +import com.google.gson.stream.JsonReader; +import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EnumPlayerModelParts; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeColorHelper; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.StringReader; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +@SideOnly(Side.CLIENT) +public class SupporterFancyHandler { + + public static final Map FANCY_INFOS = new HashMap<>(); + + public SupporterFancyHandler() { + new FetchThread(); + MinecraftForge.EVENT_BUS.register(this); + } + + @SubscribeEvent + public void onPlayerTick(TickEvent.PlayerTickEvent event) { + if (event.phase != TickEvent.Phase.END) + return; + EntityPlayer player = event.player; + if (!player.world.isRemote) + return; + if (player.isInvisible() || !player.isWearing(EnumPlayerModelParts.CAPE)) + return; + Minecraft mc = Minecraft.getMinecraft(); + if (player == mc.player && mc.gameSettings.thirdPersonView == 0) + return; + FancyInfo info = FANCY_INFOS.get(player.getName()); + if (info == null) + return; + + Random rand = player.world.rand; + if (rand.nextFloat() >= 0.75F) { + int color; + if (info.tier == 1) { + BlockPos pos = player.getPosition(); + color = BiomeColorHelper.getFoliageColorAtPos(player.world, pos); + } else { + color = info.color; + } + + NaturesAuraAPI.instance().spawnMagicParticle( + player.posX + rand.nextGaussian() * 0.15F, + player.posY + rand.nextFloat() * 1.8F, + player.posZ + rand.nextGaussian() * 0.15F, + rand.nextGaussian() * 0.01F, + rand.nextFloat() * 0.01F, + rand.nextGaussian() * 0.01F, + color, rand.nextFloat() + 1F, rand.nextInt(50) + 50, 0F, false, true); + } + } + + public static class FancyInfo { + public final int tier; + public final int color; + + public FancyInfo(int tier, int color) { + this.tier = tier; + this.color = color; + } + } + + private static class FetchThread extends Thread { + public FetchThread() { + this.setName(NaturesAura.MOD_ID + "_support_fetcher"); + this.setDaemon(true); + this.start(); + } + + @Override + public void run() { + try { + URL url = new URL("https://raw.githubusercontent.com/Ellpeck/NaturesAura/master/supporters.json"); + JsonReader reader = new JsonReader(new InputStreamReader(url.openStream())); + JsonParser parser = new JsonParser(); + + JsonObject main = parser.parse(reader).getAsJsonObject(); + for (Map.Entry entry : main.entrySet()) { + JsonObject object = entry.getValue().getAsJsonObject(); + int tier = object.get("tier").getAsInt(); + int color = object.has("color") ? Integer.parseInt(object.get("color").getAsString(), 16) : 0; + FANCY_INFOS.put(entry.getKey(), new FancyInfo(tier, color)); + } + + reader.close(); + } catch (Exception e) { + NaturesAura.LOGGER.warn("Fetching supporter information failed", e); + } + } + } +} diff --git a/src/main/resources/assets/naturesaura/textures/gui/book.png b/src/main/resources/assets/naturesaura/textures/gui/book.png index f8b402c0..467a5de6 100644 Binary files a/src/main/resources/assets/naturesaura/textures/gui/book.png and b/src/main/resources/assets/naturesaura/textures/gui/book.png differ diff --git a/supporters.json b/supporters.json new file mode 100644 index 00000000..d94757d1 --- /dev/null +++ b/supporters.json @@ -0,0 +1,5 @@ +{ + "Ellpeck": { + "tier": 1 + } +} \ No newline at end of file