Skip to content

Commit

Permalink
Fixed glitch with the magma boss warning messing up GUI's, added mana…
Browse files Browse the repository at this point in the history
… bar (not complete with settings yet).
  • Loading branch information
biscuut committed Jun 30, 2019
1 parent efc1791 commit abd62f9
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public void drawButton(Minecraft mc, int mouseX, int mouseY) {
boxAlpha = 170;
}
if (feature.getButtonType() == Feature.ButtonType.REGULAR) {
if (main.getConfigValues().getDisabledFeatures().contains(feature)) {
if ((feature == Feature.MANA_BAR && main.getConfigValues().getManaBarType() == Feature.ManaBarType.OFF) ||
(feature != Feature.MANA_BAR && main.getConfigValues().getDisabledFeatures().contains(feature))) {
boxColor = ConfigColor.RED.getColor(boxAlpha * alphaMultiplier);
} else {
boxColor = ConfigColor.GREEN.getColor(boxAlpha * alphaMultiplier);
Expand Down Expand Up @@ -75,7 +76,9 @@ public void drawButton(Minecraft mc, int mouseX, int mouseY) {
fontColor = new Color(255, 255, 160, alpha).getRGB();
}
if (feature == Feature.WARNING_TIME) {
displayString = "Warning Time - "+main.getConfigValues().getWarningSeconds()+"s";
displayString = "Warning Time: "+main.getConfigValues().getWarningSeconds()+"s";
} else if (feature == Feature.MANA_BAR) {
displayString = "Mana Bar: "+main.getConfigValues().getManaBarType().getDisplayText();
}
this.drawCenteredString(mc.fontRendererObj, displayString, xPosition+width/2, yPosition+(this.height-8)/2, fontColor);
GlStateManager.disableBlend();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ public void initGui() {
int halfWidth = width/2;
int boxWidth = 120;
int boxHeight = 20;
buttonList.add(new ButtonRegular(0, halfWidth-boxWidth-30, height*0.35, "Magma Boss Warning", main, Feature.MAGMA_WARNING, boxWidth, boxHeight));
buttonList.add(new ButtonRegular(0, halfWidth+30, height*0.35, "Item Drop Confirmation", main, Feature.DROP_CONFIRMATION, boxWidth, boxHeight));
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.35, null, main, Feature.MANA_BAR, boxWidth, boxHeight));
boxWidth = 200;
buttonList.add(new ButtonRegular(0, halfWidth-100, height*0.45, "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, "Warning Time - 3s", main, Feature.WARNING_TIME, boxWidth, boxHeight));
buttonList.add(new ButtonRegular(0, halfWidth-boxWidth-20, height*0.73, null, main, Feature.WARNING_TIME, boxWidth, boxHeight));
boxWidth = 20;
buttonList.add(new ButtonRegular(0, halfWidth-boxWidth-125, height*0.73, "+", main, Feature.ADD, boxWidth, boxHeight));
buttonList.add(new ButtonRegular(0, halfWidth-boxWidth+5, height*0.73, "-", main, Feature.SUBTRACT, boxWidth, boxHeight));
Expand Down Expand Up @@ -59,7 +60,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
GlStateManager.scale(scale, scale, scale);
if (alpha < 4) alpha = 4; // Text under 4 alpha appear 100% transparent for some reason o.O
drawCenteredString(fontRendererObj, EnumChatFormatting.WHITE+"SkyblockAddons",
(int)(width/2*scaleMultiplier), (int)(height*0.2*scaleMultiplier), new Color(255,255,255, alpha*2).getRGB());
(int)(width/2*scaleMultiplier), (int)(height*0.12*scaleMultiplier), new Color(255,255,255, alpha*2).getRGB());
GlStateManager.popMatrix();

GlStateManager.pushMatrix();
Expand All @@ -78,10 +79,14 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
protected void actionPerformed(GuiButton abstractButton) {
Feature feature = ((ButtonRegular)abstractButton).getFeature();
if (feature.getButtonType() == Feature.ButtonType.REGULAR) {
if (main.getConfigValues().getDisabledFeatures().contains(feature)) {
main.getConfigValues().getDisabledFeatures().remove(feature);
if (feature == Feature.MANA_BAR) {
main.getConfigValues().setManaBarType(main.getConfigValues().getManaBarType().getNextType());
} else {
main.getConfigValues().getDisabledFeatures().add(feature);
if (main.getConfigValues().getDisabledFeatures().contains(feature)) {
main.getConfigValues().getDisabledFeatures().remove(feature);
} else {
main.getConfigValues().getDisabledFeatures().add(feature);
}
}
} else if (feature.getButtonType() == Feature.ButtonType.COLOR) {
if (feature == Feature.WARNING_COLOR) {
Expand Down
151 changes: 140 additions & 11 deletions src/main/java/codes/biscuit/skyblockaddons/listeners/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,35 @@
import net.minecraft.scoreboard.ScoreObjective;
import net.minecraft.scoreboard.ScorePlayerTeam;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

import java.awt.*;
import java.util.Collection;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static net.minecraft.client.gui.Gui.icons;

public class PlayerListener {

private boolean predictMana = false;
private int mana = 0;
private int maxMana = 100;
private boolean openGUI = false;
private boolean bossWarning = false;
private long lastBoss = -1;
private int currentTick = 1;
private int soundTick = 1;
private int manaTick = 1;
// private Map<Long, String> spawnLog = new HashMap<>();

private SkyblockAddons main;
Expand All @@ -50,27 +61,129 @@ public void onWorldJoin(EntityJoinWorldEvent e) {
}

@SubscribeEvent()
public void onRender(RenderGameOverlayEvent.Post e) {
if (bossWarning) { // Render a title-like warning.
public void onRenderBossWarning(RenderGameOverlayEvent.Post e) {
if (bossWarning && 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);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
// GlStateManager.enableBlend();
// GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.pushMatrix();
GlStateManager.scale(4.0F, 4.0F, 4.0F);
String text;
text = main.getConfigValues().getWarningColor().getChatFormatting() + "MagmaCube Boss!";
mc.ingameGUI.getFontRenderer().drawString(text, (float) (-mc.ingameGUI.getFontRenderer().getStringWidth(text) / 2), -20.0F, 16777215, true);
GlStateManager.popMatrix();
GlStateManager.disableBlend();
// GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
}

@SubscribeEvent()
public void onChatReceive(ClientChatReceivedEvent e) {
if (e.type == 2 && main.getConfigValues().getManaBarType() != Feature.ManaBarType.OFF) { // Render a title-like warning.
String message = e.message.getUnformattedText();
if (message.contains("\u270E Mana")) {
String[] manaSplit = message.split(Pattern.quote("\u270E Mana"));
if (manaSplit.length > 1) {
if (manaSplit[0].contains(EnumChatFormatting.AQUA.toString())) {
message = manaSplit[0].split(Pattern.quote(EnumChatFormatting.AQUA.toString()))[1];
manaSplit = message.split(Pattern.quote("/"));
mana = Integer.parseInt(manaSplit[0]);
maxMana = Integer.parseInt(manaSplit[1]);
e.message = new ChatComponentText(e.message.getUnformattedText().split(EnumChatFormatting.AQUA.toString())[0].trim());
predictMana = false;
return;
}
}
}
predictMana = true;
}
}

@SubscribeEvent()
public void onRenderManaBar(RenderGameOverlayEvent.Post e) {
if (e.type == RenderGameOverlayEvent.ElementType.EXPERIENCE && main.getConfigValues().getManaBarType() != Feature.ManaBarType.OFF) {
Minecraft mc = Minecraft.getMinecraft();
ScaledResolution res = new ScaledResolution(mc);
int width = res.getScaledWidth();
int height = res.getScaledHeight();
mc.getTextureManager().bindTexture(icons);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableBlend();

short barWidth = 92;
int left = width / 2 - 91 + barWidth;

if (main.getConfigValues().getManaBarType() == Feature.ManaBarType.BAR
|| main.getConfigValues().getManaBarType() == Feature.ManaBarType.BAR_TEXT) {
float manaFill = (float) mana / maxMana;
if (manaFill > 1) manaFill = 1;
int filled = (int) (manaFill * barWidth);
int top = height - 59;
mc.ingameGUI.drawTexturedModalRect(left, top, 10, 84, barWidth, 5);
if (filled > 0) {
mc.ingameGUI.drawTexturedModalRect(left, top, 10, 89, filled, 5);
}

if (main.getConfigValues().getManaBarType() == Feature.ManaBarType.TEXT
|| main.getConfigValues().getManaBarType() == Feature.ManaBarType.BAR_TEXT) {
int color = new Color(47, 71, 249).getRGB();
String text = mana + "/" + maxMana;
int x = ((width - mc.ingameGUI.getFontRenderer().getStringWidth(text)) / 2) + (barWidth / 2);
int y = height - 65;
mc.ingameGUI.getFontRenderer().drawString(text, x + 1, y, 0);
mc.ingameGUI.getFontRenderer().drawString(text, x - 1, y, 0);
mc.ingameGUI.getFontRenderer().drawString(text, x, y + 1, 0);
mc.ingameGUI.getFontRenderer().drawString(text, x, y - 1, 0);
mc.ingameGUI.getFontRenderer().drawString(text, x, y, color);
GlStateManager.enableBlend();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
}
}
}
}

// Minecraft mc = Minecraft.getMinecraft();
// ScaledResolution p_175176_1_ = new ScaledResolution(mc);
// int p_175176_2_ = p_175176_1_.getScaledWidth() / 2 - 91;
// mc.getTextureManager().bindTexture(icons);
// int i = mc.thePlayer.xpBarCap();
//
// if (i > 0)
// {
// int j = 182; //182
// int k = (int)(mc.thePlayer.experience * (float)(j + 1));
// int l = p_175176_1_.getScaledHeight() - 20 + 3; // p_175176_1_.getScaledHeight() - 32 + 3
// mc.ingameGUI.drawTexturedModalRect(p_175176_2_, l, 0, 64, j, 5);
//
// if (k > 0)
// {
// mc.ingameGUI.drawTexturedModalRect(p_175176_2_, l, 0, 69, k, 5);
// }
// }
//
// mc.mcProfiler.endSection();
//
// if (mc.thePlayer.experienceLevel > 0)
// {
// mc.mcProfiler.startSection("expLevel");
// int k1 = 8453920;
// String s = "" + mc.thePlayer.experienceLevel;
// int l1 = (p_175176_1_.getScaledWidth() - mc.ingameGUI.getFontRenderer().getStringWidth(s)) / 2;
// int i1 = p_175176_1_.getScaledHeight() - 31 - 4;
// int j1 = 0;
// mc.ingameGUI.getFontRenderer().drawString(s, l1 + 1, i1, 0);
// mc.ingameGUI.getFontRenderer().drawString(s, l1 - 1, i1, 0);
// mc.ingameGUI.getFontRenderer().drawString(s, l1, i1 + 1, 0);
// mc.ingameGUI.getFontRenderer().drawString(s, l1, i1 - 1, 0);
// mc.ingameGUI.getFontRenderer().drawString(s, l1, i1, k1);
// mc.mcProfiler.endSection();
// }

@SubscribeEvent()
public void onInteract(PlayerInteractEvent e) {
if (!main.getConfigValues().getDisabledFeatures().contains(Feature.DISABLE_EMBER_ROD)) {
Expand All @@ -85,20 +198,36 @@ public void onInteract(PlayerInteractEvent e) {
}
}

@SubscribeEvent()
public void onTickMana(TickEvent.ClientTickEvent e) {
if (e.phase == TickEvent.Phase.START) {
manaTick++;
if (manaTick == 20) {
if (predictMana) {
mana += (maxMana/50);
if (mana>maxMana) mana = maxMana;
}
} else if (manaTick > 20) {
manaTick = 1;
}
}
}


@SubscribeEvent()
public void onTickSound(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) {
if ((lastBoss == -1 || System.currentTimeMillis() - lastBoss > 1800000) && currentTick % 5 == 0) {
if ((lastBoss == -1 || System.currentTimeMillis() - lastBoss > 1800000) && soundTick % 5 == 0) {
for (Entity entity : mc.theWorld.loadedEntityList) { // Loop through all the entities.
if (entity instanceof EntityMagmaCube) {
EntitySlime magma = (EntitySlime) entity;
int size = magma.getSlimeSize();
if (size > 10) { // Find a big magma boss
lastBoss = System.currentTimeMillis();
bossWarning = true; // Enable warning and disable again in four seconds.
soundTick = 16; // so the sound plays instantly
new Timer().schedule(new TimerTask() {
@Override
public void run() {
Expand All @@ -110,14 +239,14 @@ public void run() {
}
}
}
if (bossWarning && currentTick % 4 == 0) { // Play sound every 4 ticks or 1/5 second.
if (bossWarning && soundTick % 4 == 0) { // Play sound every 4 ticks or 1/5 second.
mc.thePlayer.playSound("random.orb", 1, 0.5F);
}
}
currentTick++;
if (currentTick > 20) {
soundTick++;
if (soundTick > 20) {
isOnIsland();
currentTick = 1;
soundTick = 1;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,30 @@
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;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Minecraft.class)
public class MixinMinecraft {
@Mixin(EntityPlayerSP.class)
public abstract class MixinEntityPlayerSP {

private Item lastItem = null;
private long lastDrop = System.currentTimeMillis();

@Redirect(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;dropOneItem(Z)Lnet/minecraft/entity/item/EntityItem;", ordinal = 0))
private EntityItem dropOneItemConfirmation(EntityPlayerSP entityPlayerSP, boolean dropAll) {
if (SkyblockAddons.INSTANCE.getConfigValues().getDisabledFeatures().contains(Feature.DROP_CONFIRMATION)) {
System.out.println(SkyblockAddons.INSTANCE.getConfigValues().getDisabledFeatures());
return entityPlayerSP.dropOneItem(dropAll);
} else {
ItemStack heldItemStack = entityPlayerSP.getHeldItem();
System.out.println(heldItemStack);
@Inject(method = "dropOneItem", at = @At(value = "HEAD"), cancellable = true)
private void dropOneItemConfirmation(boolean dropAll, CallbackInfoReturnable<EntityItem> cir) {
if (!SkyblockAddons.INSTANCE.getConfigValues().getDisabledFeatures().contains(Feature.DROP_CONFIRMATION)) {
ItemStack heldItemStack = Minecraft.getMinecraft().thePlayer.getHeldItem();
if (heldItemStack != null) {
Item heldItem = heldItemStack.getItem();
if (lastItem != null && lastItem == heldItem && System.currentTimeMillis() - lastDrop < 3000) {
lastDrop = System.currentTimeMillis();
return entityPlayerSP.dropOneItem(dropAll);
} else {
Utils.sendMessage(SkyblockAddons.INSTANCE.getConfigValues().getConfirmationColor().getChatFormatting() + "Drop this item again to confirm!");
lastItem = heldItem;
lastDrop = System.currentTimeMillis();
cir.setReturnValue(null);
}
}
}
return null;
}
}
Loading

0 comments on commit abd62f9

Please sign in to comment.