From 7e62bca83a68540de589e00ae34d3806e52f53b0 Mon Sep 17 00:00:00 2001 From: Biscuit Date: Thu, 11 Jul 2019 12:04:11 -0400 Subject: [PATCH] Added magma boss bar to show health, disabled durability on tools while on skyblock, added a full inventory warning, other bug fixes and stuff. --- build.gradle | 4 +- .../skyblockaddons/SkyblockAddons.java | 8 +- .../skyblockaddons/gui/ButtonSlider.java | 4 + .../skyblockaddons/gui/SkyblockAddonsGui.java | 26 +++-- .../listeners/PlayerListener.java | 106 ++++++++++++++---- .../mixins/MixinEntityPlayerSP.java | 3 +- .../mixins/MixinEntityRenderer.java | 4 +- .../skyblockaddons/mixins/MixinItem.java | 20 ++++ .../mixins/MixinSoundManager.java | 2 +- .../skyblockaddons/utils/ConfigValues.java | 91 ++++++++------- .../biscuit/skyblockaddons/utils/Feature.java | 2 + .../biscuit/skyblockaddons/utils/Utils.java | 96 +++++++++++----- src/main/resources/mcmod.info | 3 +- src/main/resources/mixins.skyblockaddons.json | 3 +- 14 files changed, 263 insertions(+), 109 deletions(-) create mode 100644 src/main/java/codes/biscuit/skyblockaddons/gui/ButtonSlider.java create mode 100644 src/main/java/codes/biscuit/skyblockaddons/mixins/MixinItem.java diff --git a/build.gradle b/build.gradle index 48f194c1c1..0ec9d3f646 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,7 @@ plugins { id "net.minecraftforge.gradle.forge" version "2.0.2" } */ -version = "1.0-b5" +version = "1.0-b6" group= "codes.biscuit.skyblockaddons" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "SkyblockAddons" @@ -60,7 +60,7 @@ repositories { //} dependencies { - provided('org.spongepowered:mixin:0.7.11-SNAPSHOT') { + provided('org.spongepowered:mixin:0.7.11-SNAPSHOT') { //0.5.3-SNAPSHOT exclude module: 'launchwrapper' exclude module: 'guava' exclude module: 'gson' diff --git a/src/main/java/codes/biscuit/skyblockaddons/SkyblockAddons.java b/src/main/java/codes/biscuit/skyblockaddons/SkyblockAddons.java index 84d0fd2b12..9cc2e36c3f 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/SkyblockAddons.java +++ b/src/main/java/codes/biscuit/skyblockaddons/SkyblockAddons.java @@ -3,6 +3,7 @@ import codes.biscuit.skyblockaddons.commands.SkyblockAddonsCommand; import codes.biscuit.skyblockaddons.listeners.PlayerListener; import codes.biscuit.skyblockaddons.utils.ConfigValues; +import codes.biscuit.skyblockaddons.utils.Utils; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; @@ -14,11 +15,12 @@ public class SkyblockAddons { static final String MOD_ID = "skyblockaddons"; static final String MOD_NAME = "SkyblockAddons"; - public static final String VERSION = "1.0-b5"; + public static final String VERSION = "1.0-b6"; public static SkyblockAddons INSTANCE; // for Mixins cause they don't have a constructor private ConfigValues configValues; private PlayerListener playerListener = new PlayerListener(this); + private Utils utils = new Utils(this); @Mod.EventHandler public void preInit(FMLPreInitializationEvent e) { @@ -41,4 +43,8 @@ public ConfigValues getConfigValues() { public PlayerListener getPlayerListener() { return playerListener; } + + public Utils getUtils() { + return utils; + } } \ No newline at end of file diff --git a/src/main/java/codes/biscuit/skyblockaddons/gui/ButtonSlider.java b/src/main/java/codes/biscuit/skyblockaddons/gui/ButtonSlider.java new file mode 100644 index 0000000000..05925cf361 --- /dev/null +++ b/src/main/java/codes/biscuit/skyblockaddons/gui/ButtonSlider.java @@ -0,0 +1,4 @@ +package codes.biscuit.skyblockaddons.gui; + +public class ButtonSlider { +} diff --git a/src/main/java/codes/biscuit/skyblockaddons/gui/SkyblockAddonsGui.java b/src/main/java/codes/biscuit/skyblockaddons/gui/SkyblockAddonsGui.java index 7a46e4a316..225e082b39 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/gui/SkyblockAddonsGui.java +++ b/src/main/java/codes/biscuit/skyblockaddons/gui/SkyblockAddonsGui.java @@ -24,22 +24,34 @@ public SkyblockAddonsGui(SkyblockAddons main) { @Override public void initGui() { int halfWidth = width/2; + int oneThird = width/3; + int twoThirds = oneThird*2; int boxWidth = 130; int boxHeight = 20; - buttonList.add(new ButtonRegular(0, halfWidth-boxWidth-30, height*0.25, "Magma Boss Warning", main, Feature.MAGMA_WARNING, boxWidth, boxHeight)); - buttonList.add(new ButtonRegular(0, halfWidth+30, height*0.25, "Item Drop Confirmation", main, Feature.DROP_CONFIRMATION, boxWidth, boxHeight)); - buttonList.add(new ButtonRegular(0, halfWidth-boxWidth-30, height*0.33, null, main, Feature.MANA_BAR, boxWidth, boxHeight)); - buttonList.add(new ButtonRegular(0, halfWidth+30, height*0.33, "Hide Skeleton Hat Bones", main, Feature.BONES, boxWidth, boxHeight)); - buttonList.add(new ButtonRegular(0, halfWidth-boxWidth-30, height*0.41, "Skeleton Hat Bones Bar", main, Feature.SKELETON_BAR, boxWidth, boxHeight)); - buttonList.add(new ButtonRegular(0, halfWidth+30, height*0.41, "Hide Food & Armor Bar", main, Feature.HIDE_FOOD_ARMOR_BAR, boxWidth, boxHeight)); + buttonList.add(new ButtonRegular(0, oneThird-boxWidth-30, height*0.25, "Magma Boss Warning", main, Feature.MAGMA_WARNING, boxWidth, boxHeight)); + buttonList.add(new ButtonRegular(0, halfWidth-(boxWidth/2), height*0.25, "Item Drop Confirmation", main, Feature.DROP_CONFIRMATION, boxWidth, boxHeight)); + buttonList.add(new ButtonRegular(0, oneThird-boxWidth-30, height*0.33, null, main, Feature.MANA_BAR, boxWidth, boxHeight)); + buttonList.add(new ButtonRegular(0, halfWidth-(boxWidth/2), height*0.33, "Hide Skeleton Hat Bones", main, Feature.BONES, boxWidth, boxHeight)); + buttonList.add(new ButtonRegular(0, oneThird-boxWidth-30, height*0.41, "Skeleton Hat Bones Bar", main, Feature.SKELETON_BAR, boxWidth, boxHeight)); + buttonList.add(new ButtonRegular(0, halfWidth-(boxWidth/2), height*0.41, "Hide Food & Armor Bar", main, Feature.HIDE_FOOD_ARMOR_BAR, boxWidth, boxHeight)); + buttonList.add(new ButtonRegular(0, oneThird-boxWidth-30, height*0.49, "Full Inventory Warning", main, Feature.FULL_INVENTORY_WARNING, boxWidth, boxHeight)); + buttonList.add(new ButtonRegular(0, twoThirds+30, height*0.25, "Magma Boss Bar", main, Feature.MAGMA_BOSS_BAR, boxWidth, boxHeight)); +// buttonList.add(new ButtonRegular(0, oneThird-boxWidth-30, height*0.25, "Magma Boss Warning", main, Feature.MAGMA_WARNING, boxWidth, boxHeight)); +// buttonList.add(new ButtonRegular(0, twoThirds+30, height*0.25, "Item Drop Confirmation", main, Feature.DROP_CONFIRMATION, boxWidth, boxHeight)); +// buttonList.add(new ButtonRegular(0, oneThird-boxWidth-30, height*0.33, null, main, Feature.MANA_BAR, boxWidth, boxHeight)); +// buttonList.add(new ButtonRegular(0, twoThirds+30, height*0.33, "Hide Skeleton Hat Bones", main, Feature.BONES, boxWidth, boxHeight)); +// buttonList.add(new ButtonRegular(0, oneThird-boxWidth-30, height*0.41, "Skeleton Hat Bones Bar", main, Feature.SKELETON_BAR, boxWidth, boxHeight)); +// buttonList.add(new ButtonRegular(0, twoThirds+30, height*0.41, "Hide Food & Armor Bar", main, Feature.HIDE_FOOD_ARMOR_BAR, boxWidth, boxHeight)); +// buttonList.add(new ButtonRegular(0, twoThirds+30, height*0.49, "Full Inventory Warning", main, Feature.FULL_INVENTORY_WARNING, boxWidth, boxHeight)); boxWidth = 200; - buttonList.add(new ButtonRegular(0, halfWidth-100, height*0.49, "Disable Ember Rod Ability on Island", main, Feature.DISABLE_EMBER_ROD, boxWidth, boxHeight)); + buttonList.add(new ButtonRegular(0, halfWidth-(boxWidth/2), height*0.49, "Disable Ember Rod Ability on Island", main, Feature.DISABLE_EMBER_ROD, boxWidth, boxHeight)); boxWidth = 100; buttonList.add(new ButtonRegular(0, halfWidth-boxWidth-20, height*0.65, "Warning Color", main, Feature.WARNING_COLOR, boxWidth, boxHeight)); buttonList.add(new ButtonRegular(0, halfWidth+20, height*0.65, "Confirmation Color", main, Feature.CONFIRMATION_COLOR, boxWidth, boxHeight)); buttonList.add(new ButtonRegular(0, halfWidth-boxWidth-20, height*0.73, "Mana Text Color", main, Feature.MANA_TEXT_COLOR, boxWidth, boxHeight)); buttonList.add(new ButtonRegular(0, halfWidth+20, height*0.73, "Mana Bar Color", main, Feature.MANA_BAR_COLOR, boxWidth, boxHeight)); buttonList.add(new ButtonRegular(0, halfWidth-boxWidth-20, height*0.81, null, main, Feature.WARNING_TIME, boxWidth, boxHeight)); + buttonList.add(new ButtonRegular(0, halfWidth-boxWidth-20, height*0.81, null, main, Feature.WARNING_TIME, boxWidth, boxHeight)); buttonList.add(new ButtonRegular(0, halfWidth+20, height*0.81, "Edit Locations", main, Feature.EDIT_LOCATIONS, boxWidth, boxHeight)); boxWidth = 20; buttonList.add(new ButtonRegular(0, halfWidth-boxWidth-125, height*0.81, "+", main, Feature.ADD, boxWidth, boxHeight)); diff --git a/src/main/java/codes/biscuit/skyblockaddons/listeners/PlayerListener.java b/src/main/java/codes/biscuit/skyblockaddons/listeners/PlayerListener.java index 5c50340db8..a07f36b78b 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/listeners/PlayerListener.java +++ b/src/main/java/codes/biscuit/skyblockaddons/listeners/PlayerListener.java @@ -4,15 +4,16 @@ import codes.biscuit.skyblockaddons.gui.LocationEditGui; import codes.biscuit.skyblockaddons.gui.SkyblockAddonsGui; import codes.biscuit.skyblockaddons.utils.Feature; -import codes.biscuit.skyblockaddons.utils.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityArmorStand; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.monster.EntityMagmaCube; import net.minecraft.entity.monster.EntitySlime; import net.minecraft.entity.monster.EntityZombie; +import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ChatComponentText; @@ -25,11 +26,14 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.lwjgl.opengl.GL11; import java.util.Timer; import java.util.TimerTask; import java.util.regex.Pattern; +import static net.minecraft.client.gui.Gui.icons; + public class PlayerListener { public final static ItemStack BONE = new ItemStack(Item.getItemById(352)); @@ -37,9 +41,11 @@ public class PlayerListener { private boolean sentUpdate = false; private boolean predictMana = false; + private long lastWorldJoin = -1; private int mana = 0; private int maxMana = 100; private boolean openGUI = false; + private boolean fullInventoryWarning = false; private boolean bossWarning = false; private long lastBoss = -1; private int soundTick = 1; @@ -55,6 +61,7 @@ public PlayerListener(SkyblockAddons main) { @SubscribeEvent() public void onWorldJoin(EntityJoinWorldEvent e) { if (e.entity == Minecraft.getMinecraft().thePlayer) { + lastWorldJoin = System.currentTimeMillis(); bossWarning = false; lastBoss = -1; soundTick = 1; @@ -64,23 +71,65 @@ public void onWorldJoin(EntityJoinWorldEvent e) { @SubscribeEvent() public void onRenderBossWarning(RenderGameOverlayEvent.Post e) { - if (bossWarning && e.type == RenderGameOverlayEvent.ElementType.TEXT) { // Render a title-like warning. + if (e.type == RenderGameOverlayEvent.ElementType.TEXT) { // Render a title-like warning. Minecraft mc = Minecraft.getMinecraft(); ScaledResolution scaledresolution = e.resolution; int i = scaledresolution.getScaledWidth(); - int j = scaledresolution.getScaledHeight(); - GlStateManager.pushMatrix(); - GlStateManager.translate((float) (i / 2), (float) (j / 2), 0.0F); + if (bossWarning) { + int j = scaledresolution.getScaledHeight(); + GlStateManager.pushMatrix(); + GlStateManager.translate((float) (i / 2), (float) (j / 2), 0.0F); // GlStateManager.enableBlend(); // GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.pushMatrix(); - GlStateManager.scale(4.0F, 4.0F, 4.0F); - String text; - text = main.getConfigValues().getColor(Feature.WARNING_COLOR).getChatFormatting() + "MagmaCube Boss!"; - mc.ingameGUI.getFontRenderer().drawString(text, (float) (-mc.ingameGUI.getFontRenderer().getStringWidth(text) / 2), -20.0F, 16777215, true); - GlStateManager.popMatrix(); + GlStateManager.pushMatrix(); + GlStateManager.scale(4.0F, 4.0F, 4.0F); + String text; + text = main.getConfigValues().getColor(Feature.WARNING_COLOR).getChatFormatting() + "MagmaCube Boss!"; + mc.ingameGUI.getFontRenderer().drawString(text, (float) (-mc.ingameGUI.getFontRenderer().getStringWidth(text) / 2), -20.0F, 16777215, true); + GlStateManager.popMatrix(); // GlStateManager.disableBlend(); - GlStateManager.popMatrix(); + GlStateManager.popMatrix(); + } + if (fullInventoryWarning && !main.getConfigValues().getDisabledFeatures().contains(Feature.FULL_INVENTORY_WARNING)) { + int j = scaledresolution.getScaledHeight(); + GlStateManager.pushMatrix(); + GlStateManager.translate((float) (i / 2), (float) (j / 2), 0.0F); + GlStateManager.pushMatrix(); + GlStateManager.scale(4.0F, 4.0F, 4.0F); + String text; + text = main.getConfigValues().getColor(Feature.WARNING_COLOR).getChatFormatting() + "Full Inventory!"; + mc.ingameGUI.getFontRenderer().drawString(text, (float) (-mc.ingameGUI.getFontRenderer().getStringWidth(text) / 2), -20.0F, 16777215, true); + GlStateManager.popMatrix(); + GlStateManager.popMatrix(); + } + if (!main.getConfigValues().getDisabledFeatures().contains(Feature.MAGMA_BOSS_BAR)) { + for (Entity entity : mc.theWorld.loadedEntityList) { + if (entity instanceof EntityArmorStand) { + String name = entity.getDisplayName().getFormattedText(); + if (name.contains("Magma Cube Boss ")) { + name = name.split(Pattern.quote("Magma Cube Boss "))[1]; + mc.getTextureManager().bindTexture(icons); + GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); + GlStateManager.enableBlend(); + int j = 182; + int k = i / 2 - j / 2; + int health = 1; + int l = (int) (health * (float) (j + 1)); + int i1 = 12; + mc.ingameGUI.drawTexturedModalRect(k, i1, 0, 74, j, 5); + mc.ingameGUI.drawTexturedModalRect(k, i1, 0, 74, j, 5); + + if (l > 0) { + mc.ingameGUI.drawTexturedModalRect(k, i1, 0, 79, l, 5); + } + mc.ingameGUI.getFontRenderer().drawStringWithShadow(name, (float) (i / 2 - mc.ingameGUI.getFontRenderer().getStringWidth(name) / 2), (float) (i1 - 10), 16777215); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + mc.getTextureManager().bindTexture(icons); + GlStateManager.disableBlend(); + } + } + } + } } } @@ -116,7 +165,7 @@ public void onChatReceive(ClientChatReceivedEvent e) { @SubscribeEvent() public void onRenderManaBar(RenderGameOverlayEvent.Post e) { Minecraft mc = Minecraft.getMinecraft(); - if (e.type == RenderGameOverlayEvent.ElementType.EXPERIENCE && Utils.isOnSkyblock()) { + if (e.type == RenderGameOverlayEvent.ElementType.EXPERIENCE && main.getUtils().isOnSkyblock()) { if (main.getConfigValues().getManaBarType() != Feature.ManaBarType.OFF && !(mc.currentScreen instanceof LocationEditGui)) { mc.getTextureManager().bindTexture(manaBars); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); @@ -178,7 +227,7 @@ public void onRenderManaBar(RenderGameOverlayEvent.Post e) { @SubscribeEvent() public void onRenderRemoveBars(RenderGameOverlayEvent.Pre e) { if (e.type == RenderGameOverlayEvent.ElementType.ALL) { - if (Utils.isOnSkyblock() && !main.getConfigValues().getDisabledFeatures().contains(Feature.HIDE_FOOD_ARMOR_BAR)) { + if (main.getUtils().isOnSkyblock() && !main.getConfigValues().getDisabledFeatures().contains(Feature.HIDE_FOOD_ARMOR_BAR)) { GuiIngameForge.renderFood = false; GuiIngameForge.renderArmor = false; } @@ -189,11 +238,10 @@ public void onRenderRemoveBars(RenderGameOverlayEvent.Pre e) { public void onInteract(PlayerInteractEvent e) { if (!main.getConfigValues().getDisabledFeatures().contains(Feature.DISABLE_EMBER_ROD)) { Minecraft mc = Minecraft.getMinecraft(); - if (e.entityPlayer == mc.thePlayer && e.entityPlayer.getHeldItem() != null) { - if (mc.thePlayer.getHeldItem().getItem().getRegistryName().equals("minecraft:blaze_rod") && mc.thePlayer.getHeldItem().isItemEnchanted()) { - if (Utils.isOnIsland()) { - e.setCanceled(true); - } + ItemStack heldItem = e.entityPlayer.getHeldItem(); + if (e.entityPlayer == mc.thePlayer && heldItem != null) { + if (heldItem.getItem().equals(Items.blaze_rod) && heldItem.isItemEnchanted() && main.getUtils().isOnIsland()) { + e.setCanceled(true); } } } @@ -208,11 +256,13 @@ public void onTickMana(TickEvent.ClientTickEvent e) { mana += (maxMana/50); if (mana>maxMana) mana = maxMana; } + } else if (manaTick % 5 == 0) { + main.getUtils().checkIfInventoryIsFull(); } else if (manaTick > 20) { - Utils.checkIfOnSkyblockAndIsland(); + main.getUtils().checkIfOnSkyblockAndIsland(); Minecraft mc = Minecraft.getMinecraft(); if (!sentUpdate && mc != null && mc.thePlayer != null && mc.theWorld != null) { - Utils.checkUpdates(); + main.getUtils().checkUpdates(); sentUpdate = true; } manaTick = 1; @@ -221,7 +271,7 @@ public void onTickMana(TickEvent.ClientTickEvent e) { } @SubscribeEvent() - public void onTickSound(TickEvent.ClientTickEvent e) { + public void onTickMagmaBossChecker(TickEvent.ClientTickEvent e) { if (e.phase == TickEvent.Phase.START && !main.getConfigValues().getDisabledFeatures().contains(Feature.MAGMA_WARNING)) { Minecraft mc = Minecraft.getMinecraft(); if (mc != null && mc.thePlayer != null) { @@ -285,4 +335,16 @@ public void setOpenGUI(boolean openGUI) { private boolean isOpenGUI() { return openGUI; } + + public void setFullInventoryWarning(boolean fullInventoryWarning) { + this.fullInventoryWarning = fullInventoryWarning; + } + + public boolean isFullInventoryWarning() { + return fullInventoryWarning; + } + + public long getLastWorldJoin() { + return lastWorldJoin; + } } diff --git a/src/main/java/codes/biscuit/skyblockaddons/mixins/MixinEntityPlayerSP.java b/src/main/java/codes/biscuit/skyblockaddons/mixins/MixinEntityPlayerSP.java index 769c399d15..b08328b825 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/mixins/MixinEntityPlayerSP.java +++ b/src/main/java/codes/biscuit/skyblockaddons/mixins/MixinEntityPlayerSP.java @@ -2,7 +2,6 @@ import codes.biscuit.skyblockaddons.SkyblockAddons; import codes.biscuit.skyblockaddons.utils.Feature; -import codes.biscuit.skyblockaddons.utils.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.item.EntityItem; @@ -28,7 +27,7 @@ private void dropOneItemConfirmation(boolean dropAll, CallbackInfoReturnable list, double d2, int i) { - if (Utils.isOnSkyblock()) { // conditions for the invisible zombie that Skeleton hat bones are riding + if (SkyblockAddons.INSTANCE.getUtils().isOnSkyblock()) { // conditions for the invisible zombie that Skeleton hat bones are riding list.removeIf(listEntity -> listEntity instanceof EntityZombie && listEntity.isInvisible() && listEntity.riddenByEntity instanceof EntityItem); } } diff --git a/src/main/java/codes/biscuit/skyblockaddons/mixins/MixinItem.java b/src/main/java/codes/biscuit/skyblockaddons/mixins/MixinItem.java new file mode 100644 index 0000000000..4b00062ec6 --- /dev/null +++ b/src/main/java/codes/biscuit/skyblockaddons/mixins/MixinItem.java @@ -0,0 +1,20 @@ +package codes.biscuit.skyblockaddons.mixins; + +import codes.biscuit.skyblockaddons.SkyblockAddons; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(Item.class) +public class MixinItem { + + @Redirect(method = "showDurabilityBar", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isItemDamaged()Z", ordinal = 0)) + private boolean showDurabilityBar(ItemStack stack) { //Item item, ItemStack stack + if (SkyblockAddons.INSTANCE.getUtils().isOnSkyblock()) { + return false; + } + return stack.isItemDamaged(); + } +} diff --git a/src/main/java/codes/biscuit/skyblockaddons/mixins/MixinSoundManager.java b/src/main/java/codes/biscuit/skyblockaddons/mixins/MixinSoundManager.java index 2b82af25ac..f54954415a 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/mixins/MixinSoundManager.java +++ b/src/main/java/codes/biscuit/skyblockaddons/mixins/MixinSoundManager.java @@ -18,7 +18,7 @@ public abstract class MixinSoundManager { // This makes sure our warning plays at full volume (only affected by master volume switch). @Redirect(method = "playSound", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/audio/SoundManager;getNormalizedVolume(Lnet/minecraft/client/audio/ISound;Lnet/minecraft/client/audio/SoundPoolEntry;Lnet/minecraft/client/audio/SoundCategory;)F", ordinal = 0)) private float setVolumeBypass(SoundManager soundManager, ISound sound, SoundPoolEntry entry, SoundCategory category) { - if (SkyblockAddons.INSTANCE.getPlayerListener().isBossWarning() && sound.getSoundLocation().getResourcePath().equals("random.orb")) { + if ((SkyblockAddons.INSTANCE.getPlayerListener().isBossWarning() && SkyblockAddons.INSTANCE.getPlayerListener().isFullInventoryWarning()) && sound.getSoundLocation().getResourcePath().equals("random.orb")) { return 1; } else { return getNormalizedVolume(sound, entry, category); diff --git a/src/main/java/codes/biscuit/skyblockaddons/utils/ConfigValues.java b/src/main/java/codes/biscuit/skyblockaddons/utils/ConfigValues.java index 9fa72404fa..14cef2c0bf 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/utils/ConfigValues.java +++ b/src/main/java/codes/biscuit/skyblockaddons/utils/ConfigValues.java @@ -17,6 +17,7 @@ public class ConfigValues { private Map featureColors = new EnumMap<>(Feature.class); private Feature.ManaBarType manaBarType = Feature.ManaBarType.BAR_TEXT; private int warningSeconds = 4; +// private int inventoryWarningSeconds = 3; private float manaBarX = 0.45F; private float manaBarY = 0.83F; private float skeletonBarX = 0.68F; @@ -43,49 +44,54 @@ public void loadConfig() { return; } loadedConfig = fileElement.getAsJsonObject(); - - for (JsonElement element : loadedConfig.getAsJsonArray("disabledFeatures")) { - disabledFeatures.add(Feature.fromId(element.getAsInt())); - } - warningSeconds = loadedConfig.get("warningSeconds").getAsInt(); - if (loadedConfig.has("manaBarType")) { - manaBarType = Feature.ManaBarType.values()[loadedConfig.get("manaBarType").getAsInt()]; - } - if (loadedConfig.has("manaBarX")) { - manaBarX = loadedConfig.get("manaBarX").getAsFloat(); - } - if (loadedConfig.has("manaBarY")) { - manaBarY = loadedConfig.get("manaBarY").getAsFloat(); - } - if (loadedConfig.has("skeletonBarX")) { - skeletonBarX = loadedConfig.get("skeletonBarX").getAsFloat(); - } - if (loadedConfig.has("skeletonBarY")) { - skeletonBarY = loadedConfig.get("skeletonBarY").getAsFloat(); - } - if (loadedConfig.has("warningColor")) { // migrate from old config - featureColors.put(Feature.WARNING_COLOR, ConfigColor.values()[loadedConfig.get("warningColor").getAsInt()]); - } else { - featureColors.put(Feature.WARNING_COLOR, ConfigColor.RED); - } - if (loadedConfig.has("confirmationColor")) { // migrate from old config - featureColors.put(Feature.CONFIRMATION_COLOR, ConfigColor.values()[loadedConfig.get("confirmationColor").getAsInt()]); - } else { - featureColors.put(Feature.CONFIRMATION_COLOR, ConfigColor.RED); - } - if (loadedConfig.has("manaBarColor")) { // migrate from old config - featureColors.put(Feature.MANA_BAR_COLOR, ConfigColor.values()[loadedConfig.get("manaBarColor").getAsInt()]); - } else { - featureColors.put(Feature.MANA_BAR_COLOR, ConfigColor.BLUE); - } - if (loadedConfig.has("manaBarTextColor")) { // migrate from old config - featureColors.put(Feature.MANA_TEXT_COLOR, ConfigColor.values()[loadedConfig.get("manaBarTextColor").getAsInt()]); - } else { - featureColors.put(Feature.MANA_TEXT_COLOR, ConfigColor.BLUE); - } - } catch (IOException e) { - e.printStackTrace(); + } catch (JsonParseException | IllegalStateException | IOException ex) { + ex.printStackTrace(); + System.out.println("SkyblockAddons: There was an error loading the config. Resetting to defaults."); + addDefaultsAndSave(); + return; + } + for (JsonElement element : loadedConfig.getAsJsonArray("disabledFeatures")) { + disabledFeatures.add(Feature.fromId(element.getAsInt())); + } + warningSeconds = loadedConfig.get("warningSeconds").getAsInt(); + if (loadedConfig.has("manaBarType")) { + manaBarType = Feature.ManaBarType.values()[loadedConfig.get("manaBarType").getAsInt()]; + } + if (loadedConfig.has("manaBarX")) { + manaBarX = loadedConfig.get("manaBarX").getAsFloat(); + } + if (loadedConfig.has("manaBarY")) { + manaBarY = loadedConfig.get("manaBarY").getAsFloat(); + } + if (loadedConfig.has("skeletonBarX")) { + skeletonBarX = loadedConfig.get("skeletonBarX").getAsFloat(); + } + if (loadedConfig.has("skeletonBarY")) { + skeletonBarY = loadedConfig.get("skeletonBarY").getAsFloat(); + } + if (loadedConfig.has("warningColor")) { // migrate from old config + featureColors.put(Feature.WARNING_COLOR, ConfigColor.values()[loadedConfig.get("warningColor").getAsInt()]); + } else { + featureColors.put(Feature.WARNING_COLOR, ConfigColor.RED); + } + if (loadedConfig.has("confirmationColor")) { // migrate from old config + featureColors.put(Feature.CONFIRMATION_COLOR, ConfigColor.values()[loadedConfig.get("confirmationColor").getAsInt()]); + } else { + featureColors.put(Feature.CONFIRMATION_COLOR, ConfigColor.RED); + } + if (loadedConfig.has("manaBarColor")) { // migrate from old config + featureColors.put(Feature.MANA_BAR_COLOR, ConfigColor.values()[loadedConfig.get("manaBarColor").getAsInt()]); + } else { + featureColors.put(Feature.MANA_BAR_COLOR, ConfigColor.BLUE); + } + if (loadedConfig.has("manaBarTextColor")) { // migrate from old config + featureColors.put(Feature.MANA_TEXT_COLOR, ConfigColor.values()[loadedConfig.get("manaBarTextColor").getAsInt()]); + } else { + featureColors.put(Feature.MANA_TEXT_COLOR, ConfigColor.BLUE); } +// if (loadedConfig.has("inventoryWarningSeconds")) { +// inventoryWarningSeconds = loadedConfig.get("inventoryWarningSeconds").getAsInt(); +// } } else { addDefaultsAndSave(); } @@ -118,6 +124,7 @@ public void saveConfig() { loadedConfig.addProperty("manaBarTextColor", getColor(Feature.MANA_TEXT_COLOR).ordinal()); loadedConfig.addProperty("manaBarType", manaBarType.ordinal()); loadedConfig.addProperty("warningSeconds", warningSeconds); +// loadedConfig.addProperty("inventoryWarningSeconds", inventoryWarningSeconds); loadedConfig.addProperty("manaBarX", manaBarX); loadedConfig.addProperty("manaBarY", manaBarY); loadedConfig.addProperty("skeletonBarX", skeletonBarX); diff --git a/src/main/java/codes/biscuit/skyblockaddons/utils/Feature.java b/src/main/java/codes/biscuit/skyblockaddons/utils/Feature.java index fc48326d60..c2882ae767 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/utils/Feature.java +++ b/src/main/java/codes/biscuit/skyblockaddons/utils/Feature.java @@ -9,6 +9,8 @@ public enum Feature { BONES(4, ButtonType.REGULAR), SKELETON_BAR(5, ButtonType.REGULAR), HIDE_FOOD_ARMOR_BAR(6, ButtonType.REGULAR), + FULL_INVENTORY_WARNING(7, ButtonType.REGULAR), + MAGMA_BOSS_BAR(8, ButtonType.REGULAR), WARNING_COLOR(-1, ButtonType.COLOR), CONFIRMATION_COLOR(-1, ButtonType.COLOR), diff --git a/src/main/java/codes/biscuit/skyblockaddons/utils/Utils.java b/src/main/java/codes/biscuit/skyblockaddons/utils/Utils.java index 2e4a28609e..3a6c75302b 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/utils/Utils.java +++ b/src/main/java/codes/biscuit/skyblockaddons/utils/Utils.java @@ -4,7 +4,9 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.event.ClickEvent; +import net.minecraft.item.ItemStack; import net.minecraft.scoreboard.Score; import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.scoreboard.ScorePlayerTeam; @@ -26,9 +28,16 @@ public class Utils { private static boolean onIsland = false; private static boolean onSkyblock = false; + private static boolean inventoryIsFull = false; + + private SkyblockAddons main; + + public Utils(SkyblockAddons main) { + this.main = main; + } // Static cause I can't be bothered to pass the instance ok stop bullying me - public static void sendMessage(String text) { + public void sendMessage(String text) { ClientChatReceivedEvent event = new ClientChatReceivedEvent((byte)1, new ChatComponentText(text)); MinecraftForge.EVENT_BUS.post(event); // Let other mods pick up the new message if (!event.isCanceled()) { @@ -36,7 +45,7 @@ public static void sendMessage(String text) { } } - private static void sendMessage(ChatComponentText text) { + private void sendMessage(ChatComponentText text) { ClientChatReceivedEvent event = new ClientChatReceivedEvent((byte)1, text); MinecraftForge.EVENT_BUS.post(event); // Let other mods pick up the new message if (!event.isCanceled()) { @@ -44,24 +53,54 @@ private static void sendMessage(ChatComponentText text) { } } - public static void checkIfOnSkyblockAndIsland() { // Most of this is replicated from the scoreboard rendering code so not many comments here xD + public void checkIfInventoryIsFull() { + if (!main.getConfigValues().getDisabledFeatures().contains(Feature.FULL_INVENTORY_WARNING)) { + Minecraft mc = Minecraft.getMinecraft(); + if (mc != null) { + EntityPlayerSP player = mc.thePlayer; + if (player != null) { + for (ItemStack item : player.inventory.mainInventory) { + if (item == null) { + inventoryIsFull = false; + return; + } + } + if (!inventoryIsFull) { + inventoryIsFull = true; + if (mc.currentScreen == null && System.currentTimeMillis() - main.getPlayerListener().getLastWorldJoin() > 3000) { + mc.thePlayer.playSound("random.orb", 1, 0.5F); + main.getPlayerListener().setFullInventoryWarning(true); + new Timer().schedule(new TimerTask() { + @Override + public void run() { + main.getPlayerListener().setFullInventoryWarning(false); + } + }, main.getConfigValues().getWarningSeconds() * 1000); + } + } + } + } + } + } + + public void checkIfOnSkyblockAndIsland() { // Most of this is replicated from the scoreboard rendering code so not many comments here xD Minecraft mc = Minecraft.getMinecraft(); if (mc != null && mc.theWorld != null) { Scoreboard scoreboard = mc.theWorld.getScoreboard(); - ScoreObjective scoreobjective = null; + ScoreObjective objective = null; ScorePlayerTeam scoreplayerteam = scoreboard.getPlayersTeam(mc.thePlayer.getName()); - if (scoreplayerteam != null) { - int randomNumber = scoreplayerteam.getChatFormat().getColorIndex(); - if (randomNumber >= 0) { - scoreobjective = scoreboard.getObjectiveInDisplaySlot(3 + randomNumber); - } + if (scoreplayerteam != null) + { + int slot = scoreplayerteam.getChatFormat().getColorIndex(); + if (slot >= 0) objective = scoreboard.getObjectiveInDisplaySlot(3 + slot); } - ScoreObjective scoreobjective1 = scoreobjective != null ? scoreobjective : scoreboard.getObjectiveInDisplaySlot(1); + ScoreObjective scoreobjective1 = objective != null ? objective : scoreboard.getObjectiveInDisplaySlot(1); if (scoreobjective1 != null) { - String scoreboardTitle = scoreobjective1.getDisplayName(); - onSkyblock = stripColor(scoreboardTitle).startsWith("SKYBLOCK"); - Collection collection = scoreboard.getSortedScores(scoreobjective1); - List list = Lists.newArrayList(collection.stream().filter(score -> score.getPlayerName() != null && !score.getPlayerName().startsWith("#")).collect(Collectors.toList())); + objective = scoreobjective1; + onSkyblock = stripColor(objective.getDisplayName()).startsWith("SKYBLOCK"); + scoreboard = objective.getScoreboard(); + Collection collection = scoreboard.getSortedScores(objective); + List list = Lists.newArrayList(collection.stream().filter(p_apply_1_ -> p_apply_1_.getPlayerName() != null && !p_apply_1_.getPlayerName().startsWith("#")).collect(Collectors.toList())); if (list.size() > 15) { collection = Lists.newArrayList(Iterables.skip(list, collection.size() - 15)); } else { @@ -69,8 +108,7 @@ public static void checkIfOnSkyblockAndIsland() { // Most of this is replicated } for (Score score1 : collection) { ScorePlayerTeam scoreplayerteam1 = scoreboard.getPlayersTeam(score1.getPlayerName()); - String s1 = ScorePlayerTeam.formatPlayerName(scoreplayerteam1, score1.getPlayerName()); - if (s1.equals(" \u00A77\u23E3 \u00A7aYour Isla\uD83C\uDFC0\u00A7and")) { + if (getStringOnly(stripColor(ScorePlayerTeam.formatPlayerName(scoreplayerteam1, score1.getPlayerName()))).endsWith("Your Island")) {//s1.equals(" \u00A77\u23E3 \u00A7aYour Isla\uD83C\uDFC0\u00A7and")) { onIsland = true; return; } @@ -80,7 +118,11 @@ public static void checkIfOnSkyblockAndIsland() { // Most of this is replicated onIsland = false; } - public static void checkUpdates() { + private String getStringOnly(String text) { + return Pattern.compile("[^a-z A-Z]").matcher(text).replaceAll(""); + } + + public void checkUpdates() { new Thread(() -> { try { URL url = new URL("https://raw.githubusercontent.com/biscuut/SkyblockAddons/master/build.gradle"); @@ -133,16 +175,16 @@ public static void checkUpdates() { thisVersionNumbers.add(i, 0); } if (newestVersionNumbers.get(i) > thisVersionNumbers.get(i)) { - Utils.sendMessage(EnumChatFormatting.GRAY.toString() + EnumChatFormatting.STRIKETHROUGH + "--------------" + EnumChatFormatting.GRAY + "[" + EnumChatFormatting.BLUE + EnumChatFormatting.BOLD + " SkyblockAddons " + EnumChatFormatting.GRAY + "]" + EnumChatFormatting.GRAY + EnumChatFormatting.STRIKETHROUGH + "--------------"); + sendMessage(EnumChatFormatting.GRAY.toString() + EnumChatFormatting.STRIKETHROUGH + "--------------" + EnumChatFormatting.GRAY + "[" + EnumChatFormatting.BLUE + EnumChatFormatting.BOLD + " SkyblockAddons " + EnumChatFormatting.GRAY + "]" + EnumChatFormatting.GRAY + EnumChatFormatting.STRIKETHROUGH + "--------------"); ChatComponentText newVersion = new ChatComponentText(EnumChatFormatting.YELLOW+"A new version, " + newestVersion + " is available. Download it by clicking here."); newVersion.setChatStyle(newVersion.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://hypixel.net/threads/forge-1-8-9-skyblockaddons-useful-features-for-skyblock.2109217/"))); - Utils.sendMessage(newVersion); - Utils.sendMessage(EnumChatFormatting.GRAY.toString() + EnumChatFormatting.STRIKETHROUGH + "---------------------------------------"); + sendMessage(newVersion); + sendMessage(EnumChatFormatting.GRAY.toString() + EnumChatFormatting.STRIKETHROUGH + "---------------------------------------"); break; } else if (thisVersionNumbers.get(i) > newestVersionNumbers.get(i)) { - Utils.sendMessage(EnumChatFormatting.GRAY.toString() + EnumChatFormatting.STRIKETHROUGH + "--------------" + EnumChatFormatting.GRAY + "[" + EnumChatFormatting.BLUE + EnumChatFormatting.BOLD + " SkyblockAddons " + EnumChatFormatting.GRAY + "]" + EnumChatFormatting.GRAY + EnumChatFormatting.STRIKETHROUGH + "--------------"); - Utils.sendMessage(EnumChatFormatting.YELLOW + "You are running a development version: " + SkyblockAddons.VERSION + ". The latest online version is " + newestVersion + "."); - Utils.sendMessage(EnumChatFormatting.GRAY.toString() + EnumChatFormatting.STRIKETHROUGH + "---------------------------------------"); + sendMessage(EnumChatFormatting.GRAY.toString() + EnumChatFormatting.STRIKETHROUGH + "--------------" + EnumChatFormatting.GRAY + "[" + EnumChatFormatting.BLUE + EnumChatFormatting.BOLD + " SkyblockAddons " + EnumChatFormatting.GRAY + "]" + EnumChatFormatting.GRAY + EnumChatFormatting.STRIKETHROUGH + "--------------"); + sendMessage(EnumChatFormatting.YELLOW + "You are running a development version: " + SkyblockAddons.VERSION + ". The latest online version is " + newestVersion + "."); + sendMessage(EnumChatFormatting.GRAY.toString() + EnumChatFormatting.STRIKETHROUGH + "---------------------------------------"); break; } } @@ -152,16 +194,16 @@ public static void checkUpdates() { }).start(); } - private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile( "(?i)" + '\u00A7' + "[0-9A-FK-OR]" ); - private static String stripColor(final String input) { + private final Pattern STRIP_COLOR_PATTERN = Pattern.compile( "(?i)" + '\u00A7' + "[0-9A-FK-OR]" ); + private String stripColor(final String input) { return STRIP_COLOR_PATTERN.matcher(input).replaceAll(""); } - public static boolean isOnIsland() { + public boolean isOnIsland() { return onIsland; } - public static boolean isOnSkyblock() { + public boolean isOnSkyblock() { return onSkyblock; } } diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index cb1ffe03a6..7e8b0f7dc9 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -4,6 +4,5 @@ "description": "A mod with a few features to improve your skyblock experience.", "version": "${version}", "mcversion": "${mcversion}", - "authorList": ["Biscut"], - "dependencies": ["ChatTriggers"] + "authorList": ["Biscut"] }] \ No newline at end of file diff --git a/src/main/resources/mixins.skyblockaddons.json b/src/main/resources/mixins.skyblockaddons.json index 9e8762360d..ba63628808 100644 --- a/src/main/resources/mixins.skyblockaddons.json +++ b/src/main/resources/mixins.skyblockaddons.json @@ -8,6 +8,7 @@ "MixinSoundManager", "MixinEntityRenderer", "MixinRenderManager", - "MixinGuiContainer" + "MixinGuiContainer", + "MixinItem" ] } \ No newline at end of file