From e63334182aef461aff7f7d20547ea9d0ee4f1bf7 Mon Sep 17 00:00:00 2001 From: Bella Date: Tue, 24 Mar 2020 11:55:53 -0400 Subject: [PATCH] add gui for beaconselector --- .../mixin/client/MixinEntityPlayerSP.java | 45 ++--- ...BetterBeacons.java => BeaconSelector.java} | 22 +-- .../me/zeroeightsix/kami/util/BeaconGui.java | 157 ++++++++++++++++++ 3 files changed, 186 insertions(+), 38 deletions(-) rename src/main/java/me/zeroeightsix/kami/module/modules/misc/{BetterBeacons.java => BeaconSelector.java} (68%) create mode 100644 src/main/java/me/zeroeightsix/kami/util/BeaconGui.java diff --git a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinEntityPlayerSP.java b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinEntityPlayerSP.java index 22365719..2bf2319d 100644 --- a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinEntityPlayerSP.java +++ b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinEntityPlayerSP.java @@ -1,12 +1,18 @@ package me.zeroeightsix.kami.mixin.client; +import com.mojang.authlib.GameProfile; import me.zeroeightsix.kami.KamiMod; import me.zeroeightsix.kami.event.events.PlayerMoveEvent; import me.zeroeightsix.kami.module.ModuleManager; +import me.zeroeightsix.kami.util.BeaconGui; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.MoverType; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.world.IInteractionObject; +import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -17,7 +23,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; * Created by 086 on 12/12/2017. */ @Mixin(EntityPlayerSP.class) -public class MixinEntityPlayerSP { +public abstract class MixinEntityPlayerSP extends EntityPlayer { + + public MixinEntityPlayerSP(World worldIn, GameProfile gameProfileIn) { + super(worldIn, gameProfileIn); + } @Redirect(method = "onLivingUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;closeScreen()V")) public void closeScreen(EntityPlayerSP entityPlayerSP) { @@ -29,25 +39,20 @@ public class MixinEntityPlayerSP { if (ModuleManager.isModuleEnabled("PortalChat")) return; } -// @ModifyArgs(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/AbstractClientPlayer;move(Lnet/minecraft/entity/MoverType;DDD)V")) -// public void move(Args args) { -// MoverType type = args.get(0); -// double x = args.get(1);< -// double y = args.get(2); -// double z = args.get(3); -// PlayerMoveEvent event = new PlayerMoveEvent(type, x, y, z); -// KamiMod.EVENT_BUS.post(event); -// if (event.isCancelled()) { -// x = y = z = 0; -// } else { -// x = event.getX(); -// y = event.getY(); -// z = event.getZ(); -// } -// args.set(1, x); -// args.set(2, y); -// args.set(3, z); -// } + /** + * Author: TBM + */ + @Inject(method = "displayGUIChest", at = @At("HEAD"), cancellable = true) + public void onDisplayGUIChest(IInventory chestInventory, CallbackInfo ci) { + if (ModuleManager.getModuleByName("BeaconSelector").isEnabled()) { + if (chestInventory instanceof IInteractionObject) { + if ("minecraft:beacon".equals(((IInteractionObject)chestInventory).getGuiID())) { + Minecraft.getMinecraft().displayGuiScreen(new BeaconGui(this.inventory, chestInventory)); + ci.cancel(); + } + } + } + } @Inject(method = "move", at = @At("HEAD"), cancellable = true) public void move(MoverType type, double x, double y, double z, CallbackInfo info) { diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/BetterBeacons.java b/src/main/java/me/zeroeightsix/kami/module/modules/misc/BeaconSelector.java similarity index 68% rename from src/main/java/me/zeroeightsix/kami/module/modules/misc/BetterBeacons.java rename to src/main/java/me/zeroeightsix/kami/module/modules/misc/BeaconSelector.java index ed94dde8..d68eb0b3 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/BetterBeacons.java +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/BeaconSelector.java @@ -17,25 +17,11 @@ import net.minecraft.network.play.client.CPacketCustomPayload; /*** * Created by 0x2E | PretendingToCode */ -@Module.Info(name = "BetterBeacons", category = Module.Category.MISC, description = "Choose any of the 5 beacon effects regardless of beacon base height") -public class BetterBeacons extends Module { - private Setting effects = register(Settings.e("Effect", Effects.SPEED)); - +@Module.Info(name = "BeaconSelector", category = Module.Category.MISC, description = "Choose any of the 5 beacon effects regardless of beacon base height") +public class BeaconSelector extends Module { + public static int effect = -1; private boolean doCancelPacket = true; - private enum Effects { SPEED, HASTE, RESISTANCE, JUMP_BOOST, STRENGTH } - - private int getPotionID() { - switch (effects.getValue()) { - case SPEED: return 1; - case HASTE: return 3; - case RESISTANCE: return 11; - case JUMP_BOOST: return 8; - case STRENGTH: return 5; - default: return -1; - } - } - @EventHandler public Listener packetListener = new Listener<>(event -> { if (event.getPacket() instanceof CPacketCustomPayload && ((CPacketCustomPayload) event.getPacket()).getChannelName().equals("MC|Beacon") && doCancelPacket) { @@ -50,7 +36,7 @@ public class BetterBeacons extends Module { event.cancel(); PacketBuffer buf = new PacketBuffer(Unpooled.buffer()); - buf.writeInt(getPotionID()); + buf.writeInt(effect); buf.writeInt(k1); Wrapper.getPlayer().connection.sendPacket(new CPacketCustomPayload("MC|Beacon", buf)); diff --git a/src/main/java/me/zeroeightsix/kami/util/BeaconGui.java b/src/main/java/me/zeroeightsix/kami/util/BeaconGui.java new file mode 100644 index 00000000..e29a4746 --- /dev/null +++ b/src/main/java/me/zeroeightsix/kami/util/BeaconGui.java @@ -0,0 +1,157 @@ +package me.zeroeightsix.kami.util; + +import me.zeroeightsix.kami.module.modules.misc.BeaconSelector; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.inventory.GuiBeacon; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.init.MobEffects; +import net.minecraft.inventory.IInventory; +import net.minecraft.potion.Potion; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import java.io.IOException; + +/** + * @author TBM + */ +public class BeaconGui extends GuiBeacon { + private static final ResourceLocation BEACON_GUI_TEXTURES = new ResourceLocation("textures/gui/container/beacon.png"); + public static final Potion[][] EFFECTS_LIST = new Potion[][] {{MobEffects.SPEED, MobEffects.HASTE}, {MobEffects.RESISTANCE, MobEffects.JUMP_BOOST}, {MobEffects.STRENGTH}}; + + public BeaconGui(InventoryPlayer playerInventory, IInventory tileBeaconIn) { + super(playerInventory, tileBeaconIn); + } + + boolean doRenderBtns; + + @Override + public void initGui() { + super.initGui(); + doRenderBtns = true; + } + + @Override + public void updateScreen() { + super.updateScreen(); + if (doRenderBtns) { + int id = 20; + int newY = this.guiTop; + for (Potion[] pos1 : EFFECTS_LIST) { + for (int i = 0; i < pos1.length; i++) { + BeaconGui.PowerButtonCustom custompotion = + new BeaconGui.PowerButtonCustom(id, guiLeft-27, newY, pos1[i], 0); + this.buttonList.add(custompotion); + if (pos1[i] == Potion.getPotionById(BeaconSelector.effect)) { + custompotion.setSelected(true); + } + newY += 27; + id++; + } + } + } + } + + @Override + protected void actionPerformed(GuiButton button) throws IOException { + super.actionPerformed(button); + + if (button instanceof BeaconGui.PowerButtonCustom) { + BeaconGui.PowerButtonCustom guibeacon$powerbutton = (BeaconGui.PowerButtonCustom)button; + + if (guibeacon$powerbutton.isSelected()) return; + + int i = Potion.getIdFromPotion(guibeacon$powerbutton.effect); + + if (guibeacon$powerbutton.tier < 3) { + BeaconSelector.effect = i; + } + + this.buttonList.clear(); + this.initGui(); + this.updateScreen(); + } + + } + + class PowerButtonCustom extends BeaconGui.Button { + private final Potion effect; + private final int tier; + + public PowerButtonCustom(int buttonId, int x, int y, Potion effectIn, int tierIn) { + super(buttonId, x, y, GuiContainer.INVENTORY_BACKGROUND, effectIn.getStatusIconIndex() % 8 * 18, 198 + effectIn.getStatusIconIndex() / 8 * 18); + this.effect = effectIn; + this.tier = tierIn; + } + + public void drawButtonForegroundLayer(int mouseX, int mouseY) { + String s = I18n.format(this.effect.getName()); + + if (this.tier >= 3 && this.effect != MobEffects.REGENERATION) { + s = s + " II"; + } + + BeaconGui.this.drawHoveringText(s, mouseX, mouseY); + } + } + + @SideOnly(Side.CLIENT) + static class Button extends GuiButton { + private final ResourceLocation iconTexture; + private final int iconX; + private final int iconY; + private boolean selected; + + protected Button(int buttonId, int x, int y, ResourceLocation iconTextureIn, int iconXIn, int iconYIn) { + super(buttonId, x, y, 22, 22, ""); + this.iconTexture = iconTextureIn; + this.iconX = iconXIn; + this.iconY = iconYIn; + } + + /** + * Draws this button to the screen. + */ + public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) { + if (this.visible) { + mc.getTextureManager().bindTexture(BEACON_GUI_TEXTURES); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height; + int j = 0; + + if (!this.enabled) { + j += this.width * 2; + } + else if (this.selected) { + j += this.width * 1; + } + else if (this.hovered) { + j += this.width * 3; + } + + this.drawTexturedModalRect(this.x, this.y, j, 219, this.width, this.height); + + if (!BEACON_GUI_TEXTURES.equals(this.iconTexture)) { + mc.getTextureManager().bindTexture(this.iconTexture); + } + + this.drawTexturedModalRect(this.x + 2, this.y + 2, this.iconX, this.iconY, 18, 18); + } + } + + public boolean isSelected() + { + return this.selected; + } + + public void setSelected(boolean selectedIn) + { + this.selected = selectedIn; + } + } +}