add gui for beaconselector

This commit is contained in:
Bella 2020-03-24 11:55:53 -04:00
parent ef70e7a201
commit e63334182a
No known key found for this signature in database
GPG Key ID: 815562EA23BFE344
3 changed files with 186 additions and 38 deletions

View File

@ -1,12 +1,18 @@
package me.zeroeightsix.kami.mixin.client; package me.zeroeightsix.kami.mixin.client;
import com.mojang.authlib.GameProfile;
import me.zeroeightsix.kami.KamiMod; import me.zeroeightsix.kami.KamiMod;
import me.zeroeightsix.kami.event.events.PlayerMoveEvent; import me.zeroeightsix.kami.event.events.PlayerMoveEvent;
import me.zeroeightsix.kami.module.ModuleManager; import me.zeroeightsix.kami.module.ModuleManager;
import me.zeroeightsix.kami.util.BeaconGui;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.MoverType; 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.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; 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. * Created by 086 on 12/12/2017.
*/ */
@Mixin(EntityPlayerSP.class) @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")) @Redirect(method = "onLivingUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;closeScreen()V"))
public void closeScreen(EntityPlayerSP entityPlayerSP) { public void closeScreen(EntityPlayerSP entityPlayerSP) {
@ -29,25 +39,20 @@ public class MixinEntityPlayerSP {
if (ModuleManager.isModuleEnabled("PortalChat")) return; 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) { * Author: TBM
// MoverType type = args.get(0); */
// double x = args.get(1);< @Inject(method = "displayGUIChest", at = @At("HEAD"), cancellable = true)
// double y = args.get(2); public void onDisplayGUIChest(IInventory chestInventory, CallbackInfo ci) {
// double z = args.get(3); if (ModuleManager.getModuleByName("BeaconSelector").isEnabled()) {
// PlayerMoveEvent event = new PlayerMoveEvent(type, x, y, z); if (chestInventory instanceof IInteractionObject) {
// KamiMod.EVENT_BUS.post(event); if ("minecraft:beacon".equals(((IInteractionObject)chestInventory).getGuiID())) {
// if (event.isCancelled()) { Minecraft.getMinecraft().displayGuiScreen(new BeaconGui(this.inventory, chestInventory));
// x = y = z = 0; ci.cancel();
// } else { }
// x = event.getX(); }
// y = event.getY(); }
// z = event.getZ(); }
// }
// args.set(1, x);
// args.set(2, y);
// args.set(3, z);
// }
@Inject(method = "move", at = @At("HEAD"), cancellable = true) @Inject(method = "move", at = @At("HEAD"), cancellable = true)
public void move(MoverType type, double x, double y, double z, CallbackInfo info) { public void move(MoverType type, double x, double y, double z, CallbackInfo info) {

View File

@ -17,25 +17,11 @@ import net.minecraft.network.play.client.CPacketCustomPayload;
/*** /***
* Created by 0x2E | PretendingToCode * 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") @Module.Info(name = "BeaconSelector", category = Module.Category.MISC, description = "Choose any of the 5 beacon effects regardless of beacon base height")
public class BetterBeacons extends Module { public class BeaconSelector extends Module {
private Setting<Effects> effects = register(Settings.e("Effect", Effects.SPEED)); public static int effect = -1;
private boolean doCancelPacket = true; 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 @EventHandler
public Listener<PacketEvent.Send> packetListener = new Listener<>(event -> { public Listener<PacketEvent.Send> packetListener = new Listener<>(event -> {
if (event.getPacket() instanceof CPacketCustomPayload && ((CPacketCustomPayload) event.getPacket()).getChannelName().equals("MC|Beacon") && doCancelPacket) { if (event.getPacket() instanceof CPacketCustomPayload && ((CPacketCustomPayload) event.getPacket()).getChannelName().equals("MC|Beacon") && doCancelPacket) {
@ -50,7 +36,7 @@ public class BetterBeacons extends Module {
event.cancel(); event.cancel();
PacketBuffer buf = new PacketBuffer(Unpooled.buffer()); PacketBuffer buf = new PacketBuffer(Unpooled.buffer());
buf.writeInt(getPotionID()); buf.writeInt(effect);
buf.writeInt(k1); buf.writeInt(k1);
Wrapper.getPlayer().connection.sendPacket(new CPacketCustomPayload("MC|Beacon", buf)); Wrapper.getPlayer().connection.sendPacket(new CPacketCustomPayload("MC|Beacon", buf));

View File

@ -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;
}
}
}