mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-12-22 14:59:22 +01:00
added supporter fanciness in preparation for patreon revamp
This commit is contained in:
parent
9bb3951b11
commit
3ba3c064fc
5 changed files with 153 additions and 1 deletions
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<String, FancyInfo> 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<String, JsonElement> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 27 KiB |
5
supporters.json
Normal file
5
supporters.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"Ellpeck": {
|
||||
"tier": 1
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue