From 963f66bf4df11ec9de552f50f1d5d65bae9ace0f Mon Sep 17 00:00:00 2001 From: Lorenz Date: Fri, 15 Jul 2022 15:59:56 +0200 Subject: add STRG + A, C, V, X support --- .../skyhanni/mixins/MixinGuiContainer.java | 48 ---- .../skyhanni/mixins/MixinNetHandlerPlayClient.java | 24 -- .../skyhanni/mixins/MixinNetworkManager.java | 20 -- .../hannibal2/skyhanni/mixins/MixinRenderItem.java | 41 ---- .../skyhanni/mixins/MixinRenderManager.java | 19 -- .../transformers/MixinNetHandlerPlayClient.java | 24 ++ .../mixins/transformers/MixinNetworkManager.java | 20 ++ .../mixins/transformers/MixinRenderItem.java | 41 ++++ .../mixins/transformers/MixinRenderManager.java | 19 ++ .../mixins/transformers/gui/MixinGuiContainer.java | 48 ++++ .../gui/inventory/GuiEditSignMixin.java | 265 +++++++++++++++++++++ .../tileentity/TileEntitySignMixin.java | 63 +++++ .../java/at/hannibal2/skyhanni/sign/IEditSign.java | 7 + .../at/hannibal2/skyhanni/sign/IModifiedSign.java | 19 ++ .../hannibal2/skyhanni/sign/LorenzSignUtils.java | 64 +++++ .../hannibal2/skyhanni/sign/SignSelectionList.java | 241 +++++++++++++++++++ .../skyhanni/sign/SkyBlockEventHandler.java | 7 + .../skyhanni/sign/SkyBlockcatiaConfig.java | 7 + .../at/hannibal2/skyhanni/sign/TextInputUtil.java | 202 ++++++++++++++++ 19 files changed, 1027 insertions(+), 152 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/MixinGuiContainer.java delete mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/MixinNetHandlerPlayClient.java delete mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/MixinNetworkManager.java delete mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/MixinRenderItem.java delete mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/MixinRenderManager.java create mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNetHandlerPlayClient.java create mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNetworkManager.java create mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderItem.java create mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderManager.java create mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiContainer.java create mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/inventory/GuiEditSignMixin.java create mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/transformers/tileentity/TileEntitySignMixin.java create mode 100644 src/main/java/at/hannibal2/skyhanni/sign/IEditSign.java create mode 100644 src/main/java/at/hannibal2/skyhanni/sign/IModifiedSign.java create mode 100644 src/main/java/at/hannibal2/skyhanni/sign/LorenzSignUtils.java create mode 100644 src/main/java/at/hannibal2/skyhanni/sign/SignSelectionList.java create mode 100644 src/main/java/at/hannibal2/skyhanni/sign/SkyBlockEventHandler.java create mode 100644 src/main/java/at/hannibal2/skyhanni/sign/SkyBlockcatiaConfig.java create mode 100644 src/main/java/at/hannibal2/skyhanni/sign/TextInputUtil.java (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/MixinGuiContainer.java b/src/main/java/at/hannibal2/skyhanni/mixins/MixinGuiContainer.java deleted file mode 100644 index 18997c33b..000000000 --- a/src/main/java/at/hannibal2/skyhanni/mixins/MixinGuiContainer.java +++ /dev/null @@ -1,48 +0,0 @@ -package at.hannibal2.skyhanni.mixins; - -import at.hannibal2.skyhanni.mixinhooks.GuiContainerHook; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.inventory.Slot; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(GuiContainer.class) -public abstract class MixinGuiContainer extends GuiScreen { - - @Unique - private final GuiContainerHook hook = new GuiContainerHook(this); - - @Inject(method = "keyTyped", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;closeScreen()V", shift = At.Shift.BEFORE), cancellable = true) - private void closeWindowPressed(CallbackInfo ci) { - hook.closeWindowPressed(ci); - } - - @Inject(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;color(FFFF)V", ordinal = 1)) - private void backgroundDrawn(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { - hook.backgroundDrawn(mouseX, mouseY, partialTicks, ci); - } - - @Inject(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/inventory/GuiContainer;drawGuiContainerForegroundLayer(II)V", shift = At.Shift.AFTER)) - private void onForegroundDraw(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { - hook.foregroundDrawn(mouseX, mouseY, partialTicks, ci); - } - - @Inject(method = "drawSlot", at = @At("HEAD"), cancellable = true) - private void onDrawSlot(Slot slot, CallbackInfo ci) { - hook.onDrawSlot(slot, ci); - } - - @Inject(method = "drawSlot", at = @At("RETURN"), cancellable = true) - private void onDrawSlotPost(Slot slot, CallbackInfo ci) { - hook.onDrawSlotPost(slot, ci); - } - - @Inject(method = "handleMouseClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/PlayerControllerMP;windowClick(IIIILnet/minecraft/entity/player/EntityPlayer;)Lnet/minecraft/item/ItemStack;"), cancellable = true) - private void onMouseClick(Slot slot, int slotId, int clickedButton, int clickType, CallbackInfo ci) { - hook.onMouseClick(slot, slotId, clickedButton, clickType, ci); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/MixinNetHandlerPlayClient.java b/src/main/java/at/hannibal2/skyhanni/mixins/MixinNetHandlerPlayClient.java deleted file mode 100644 index 3e91bdfe3..000000000 --- a/src/main/java/at/hannibal2/skyhanni/mixins/MixinNetHandlerPlayClient.java +++ /dev/null @@ -1,24 +0,0 @@ -package at.hannibal2.skyhanni.mixins; - -import at.hannibal2.skyhanni.mixinhooks.NetHandlerPlayClientHookKt; -import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.client.network.NetHandlerPlayClient; -import net.minecraft.network.Packet; -import net.minecraft.network.play.INetHandlerPlayClient; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(value = NetHandlerPlayClient.class, priority = 1001) -public abstract class MixinNetHandlerPlayClient implements INetHandlerPlayClient { - - @Shadow - private WorldClient clientWorldController; - - @Inject(method = "addToSendQueue", at = @At("HEAD"), cancellable = true) - private void onSendPacket(Packet packet, CallbackInfo ci) { - NetHandlerPlayClientHookKt.onSendPacket(packet, ci); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/MixinNetworkManager.java b/src/main/java/at/hannibal2/skyhanni/mixins/MixinNetworkManager.java deleted file mode 100644 index 83f7f51bb..000000000 --- a/src/main/java/at/hannibal2/skyhanni/mixins/MixinNetworkManager.java +++ /dev/null @@ -1,20 +0,0 @@ -package at.hannibal2.skyhanni.mixins; - -import at.hannibal2.skyhanni.mixinhooks.NetworkManagerHookKt; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelInboundHandler; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.Packet; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(value = NetworkManager.class, priority = 1001) -public abstract class MixinNetworkManager extends SimpleChannelInboundHandler> { - - @Inject(method = "channelRead0", at = @At("HEAD"), cancellable = true) - private void onReceivePacket(ChannelHandlerContext context, Packet packet, CallbackInfo ci) { - NetworkManagerHookKt.onReceivePacket(context, packet, ci); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/MixinRenderItem.java b/src/main/java/at/hannibal2/skyhanni/mixins/MixinRenderItem.java deleted file mode 100644 index e2dc8926c..000000000 --- a/src/main/java/at/hannibal2/skyhanni/mixins/MixinRenderItem.java +++ /dev/null @@ -1,41 +0,0 @@ -package at.hannibal2.skyhanni.mixins; - -import at.hannibal2.skyhanni.mixinhooks.RenderItemHookKt; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(RenderItem.class) -public abstract class MixinRenderItem { - - // @Inject(method = "renderItemIntoGUI", at = @At("HEAD")) - // private void renderRarity(ItemStack stack, int x, int y, CallbackInfo ci) { - // RenderItemHookKt.renderRarity(stack, x, y, ci); - // } - - @Inject(method = "renderItemOverlayIntoGUI", at = @At("RETURN")) - private void renderItemOverlayPost(FontRenderer fr, ItemStack stack, int xPosition, int yPosition, String text, CallbackInfo ci) { - RenderItemHookKt.renderItemOverlayPost(fr, stack, xPosition, yPosition, text, ci); - } - - // @Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/resources/model/IBakedModel;)V", at = @At(value = "INVOKE", target = "net/minecraft/client/renderer/GlStateManager.scale(FFF)V", shift = At.Shift.AFTER)) - // private void renderItemPre(ItemStack stack, IBakedModel model, CallbackInfo ci) { - // RenderItemHookKt.renderItemPre(stack, model, ci); - // } - // - // @Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/resources/model/IBakedModel;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderItem;renderEffect(Lnet/minecraft/client/resources/model/IBakedModel;)V", shift = At.Shift.BEFORE), cancellable = true) - // private void modifyGlintRendering(ItemStack stack, IBakedModel model, CallbackInfo ci) { - // RenderItemHookKt.modifyGlintRendering(stack, model, ci); - // } - - @Inject(method = "renderEffect", at = @At("HEAD"), cancellable = true) - public void onRenderEffect(CallbackInfo ci) { - if (RenderItemHookKt.getSkipGlint()) { - ci.cancel(); - } - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/MixinRenderManager.java b/src/main/java/at/hannibal2/skyhanni/mixins/MixinRenderManager.java deleted file mode 100644 index f57786a9b..000000000 --- a/src/main/java/at/hannibal2/skyhanni/mixins/MixinRenderManager.java +++ /dev/null @@ -1,19 +0,0 @@ -package at.hannibal2.skyhanni.mixins; - -import at.hannibal2.skyhanni.mixinhooks.RenderManagerHookKt; -import net.minecraft.client.renderer.culling.ICamera; -import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraft.entity.Entity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(RenderManager.class) -public class MixinRenderManager { - - @Inject(method = "shouldRender", at = @At("HEAD"), cancellable = true) - private void shouldRender(Entity entityIn, ICamera camera, double camX, double camY, double camZ, CallbackInfoReturnable cir) { - RenderManagerHookKt.shouldRender(entityIn, camera, camX, camY, camZ, cir); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNetHandlerPlayClient.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNetHandlerPlayClient.java new file mode 100644 index 000000000..0d48fae00 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNetHandlerPlayClient.java @@ -0,0 +1,24 @@ +package at.hannibal2.skyhanni.mixins.transformers; + +import at.hannibal2.skyhanni.mixinhooks.NetHandlerPlayClientHookKt; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.network.NetHandlerPlayClient; +import net.minecraft.network.Packet; +import net.minecraft.network.play.INetHandlerPlayClient; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = NetHandlerPlayClient.class, priority = 1001) +public abstract class MixinNetHandlerPlayClient implements INetHandlerPlayClient { + + @Shadow + private WorldClient clientWorldController; + + @Inject(method = "addToSendQueue", at = @At("HEAD"), cancellable = true) + private void onSendPacket(Packet packet, CallbackInfo ci) { + NetHandlerPlayClientHookKt.onSendPacket(packet, ci); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNetworkManager.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNetworkManager.java new file mode 100644 index 000000000..d67243a8c --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNetworkManager.java @@ -0,0 +1,20 @@ +package at.hannibal2.skyhanni.mixins.transformers; + +import at.hannibal2.skyhanni.mixinhooks.NetworkManagerHookKt; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = NetworkManager.class, priority = 1001) +public abstract class MixinNetworkManager extends SimpleChannelInboundHandler> { + + @Inject(method = "channelRead0", at = @At("HEAD"), cancellable = true) + private void onReceivePacket(ChannelHandlerContext context, Packet packet, CallbackInfo ci) { + NetworkManagerHookKt.onReceivePacket(context, packet, ci); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderItem.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderItem.java new file mode 100644 index 000000000..36be30414 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderItem.java @@ -0,0 +1,41 @@ +package at.hannibal2.skyhanni.mixins.transformers; + +import at.hannibal2.skyhanni.mixinhooks.RenderItemHookKt; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.item.ItemStack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(RenderItem.class) +public abstract class MixinRenderItem { + + // @Inject(method = "renderItemIntoGUI", at = @At("HEAD")) + // private void renderRarity(ItemStack stack, int x, int y, CallbackInfo ci) { + // RenderItemHookKt.renderRarity(stack, x, y, ci); + // } + + @Inject(method = "renderItemOverlayIntoGUI", at = @At("RETURN")) + private void renderItemOverlayPost(FontRenderer fr, ItemStack stack, int xPosition, int yPosition, String text, CallbackInfo ci) { + RenderItemHookKt.renderItemOverlayPost(fr, stack, xPosition, yPosition, text, ci); + } + + // @Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/resources/model/IBakedModel;)V", at = @At(value = "INVOKE", target = "net/minecraft/client/renderer/GlStateManager.scale(FFF)V", shift = At.Shift.AFTER)) + // private void renderItemPre(ItemStack stack, IBakedModel model, CallbackInfo ci) { + // RenderItemHookKt.renderItemPre(stack, model, ci); + // } + // + // @Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/resources/model/IBakedModel;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderItem;renderEffect(Lnet/minecraft/client/resources/model/IBakedModel;)V", shift = At.Shift.BEFORE), cancellable = true) + // private void modifyGlintRendering(ItemStack stack, IBakedModel model, CallbackInfo ci) { + // RenderItemHookKt.modifyGlintRendering(stack, model, ci); + // } + + @Inject(method = "renderEffect", at = @At("HEAD"), cancellable = true) + public void onRenderEffect(CallbackInfo ci) { + if (RenderItemHookKt.getSkipGlint()) { + ci.cancel(); + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderManager.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderManager.java new file mode 100644 index 000000000..122c7732e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderManager.java @@ -0,0 +1,19 @@ +package at.hannibal2.skyhanni.mixins.transformers; + +import at.hannibal2.skyhanni.mixinhooks.RenderManagerHookKt; +import net.minecraft.client.renderer.culling.ICamera; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.entity.Entity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(RenderManager.class) +public class MixinRenderManager { + + @Inject(method = "shouldRender", at = @At("HEAD"), cancellable = true) + private void shouldRender(Entity entityIn, ICamera camera, double camX, double camY, double camZ, CallbackInfoReturnable cir) { + RenderManagerHookKt.shouldRender(entityIn, camera, camX, camY, camZ, cir); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiContainer.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiContainer.java new file mode 100644 index 000000000..57add8571 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiContainer.java @@ -0,0 +1,48 @@ +package at.hannibal2.skyhanni.mixins.transformers.gui; + +import at.hannibal2.skyhanni.mixinhooks.GuiContainerHook; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.inventory.Slot; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(GuiContainer.class) +public abstract class MixinGuiContainer extends GuiScreen { + + @Unique + private final GuiContainerHook hook = new GuiContainerHook(this); + + @Inject(method = "keyTyped", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;closeScreen()V", shift = At.Shift.BEFORE), cancellable = true) + private void closeWindowPressed(CallbackInfo ci) { + hook.closeWindowPressed(ci); + } + + @Inject(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;color(FFFF)V", ordinal = 1)) + private void backgroundDrawn(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { + hook.backgroundDrawn(mouseX, mouseY, partialTicks, ci); + } + + @Inject(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/inventory/GuiContainer;drawGuiContainerForegroundLayer(II)V", shift = At.Shift.AFTER)) + private void onForegroundDraw(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { + hook.foregroundDrawn(mouseX, mouseY, partialTicks, ci); + } + + @Inject(method = "drawSlot", at = @At("HEAD"), cancellable = true) + private void onDrawSlot(Slot slot, CallbackInfo ci) { + hook.onDrawSlot(slot, ci); + } + + @Inject(method = "drawSlot", at = @At("RETURN"), cancellable = true) + private void onDrawSlotPost(Slot slot, CallbackInfo ci) { + hook.onDrawSlotPost(slot, ci); + } + + @Inject(method = "handleMouseClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/PlayerControllerMP;windowClick(IIIILnet/minecraft/entity/player/EntityPlayer;)Lnet/minecraft/item/ItemStack;"), cancellable = true) + private void onMouseClick(Slot slot, int slotId, int clickedButton, int clickType, CallbackInfo ci) { + hook.onMouseClick(slot, slotId, clickedButton, clickType, ci); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/inventory/GuiEditSignMixin.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/inventory/GuiEditSignMixin.java new file mode 100644 index 000000000..6777a124d --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/inventory/GuiEditSignMixin.java @@ -0,0 +1,265 @@ +package at.hannibal2.skyhanni.mixins.transformers.gui.inventory; + + +import at.hannibal2.skyhanni.sign.*; +import net.minecraft.block.Block; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiEditSign; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.util.ChatComponentText; +import org.lwjgl.input.Keyboard; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.At.Shift; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.io.IOException; +import java.util.List; + +@Mixin(GuiEditSign.class) +public class GuiEditSignMixin extends GuiScreen implements IEditSign { + private final GuiEditSign that = (GuiEditSign) (Object) this; + private TextInputUtil textInputUtil; + private SignSelectionList globalSelector; + + @Shadow + private int editLine; + + @Shadow + private int updateCounter; + + private static TileEntitySign getTileSign(GuiEditSign editSign) { + return LorenzSignUtils.getTileSign(editSign); + } + + @Inject(method = "initGui()V", at = @At("RETURN")) + private void initGui(CallbackInfo info) { +// this.textInputUtil = new TextInputUtil(this.fontRendererObj, () -> ((IModifiedSign) this.that.tileSign).getText(this.editLine).getUnformattedText(), text -> ((IModifiedSign) this.that.tileSign).setText(this.editLine, new ChatComponentText(text)), 90); + this.textInputUtil = new TextInputUtil(this.fontRendererObj, () -> ((IModifiedSign) getTileSign(this.that)).getText(this.editLine).getUnformattedText(), text -> ((IModifiedSign) getTileSign(this.that)).setText(this.editLine, new ChatComponentText(text)), 90); + + if (SkyBlockEventHandler.isSkyBlock && SkyBlockcatiaConfig.enableSignSelectionList) { + List list = null; + String title = null; + + if (this.isAuctionStartBidSign()) { + list = SignSelectionList.AUCTION_STARTING_BID_PRICES; + title = "Select price"; + } + if (this.isAuctionPrice()) { + list = SignSelectionList.AUCTION_BID_PRICES; + title = "Select bid price"; + } + if (this.isAuctionQuery()) { + list = SignSelectionList.AUCTION_QUERIES; + title = "Select query"; + } + if (this.isBankWithdraw()) { + list = SignSelectionList.BANK_WITHDRAW; + title = "Select withdraw"; + } + if (this.isBankDeposit()) { + list = SignSelectionList.BANK_DEPOSIT; + title = "Select deposit"; + } + if (this.isBazaarOrder()) { + list = SignSelectionList.BAZAAR_ORDER; + title = "Select bazaar order"; + } + if (this.isBazaarPrice()) { + list = SignSelectionList.BAZAAR_PRICE; + title = "Select bazaar price"; + } + if (list != null && title != null) { + this.globalSelector = new SignSelectionList(this.mc, this.width + 200, this.height, 64, this.height - 64, list, title); + } + } + } + + @Inject(method = "onGuiClosed()V", cancellable = true, at = @At("HEAD")) + private void onGuiClosed(CallbackInfo info) { + if (SkyBlockcatiaConfig.enableSignSelectionList) { + Keyboard.enableRepeatEvents(false); + + if (SkyBlockEventHandler.isSkyBlock) { +// String text = this.that.tileSign.signText[0].getUnformattedText(); + String text = getTileSign(this.that).signText[0].getUnformattedText(); + +// if (!StringUtils.isNullOrEmpty(text)) +// { +// if (NumberUtils.isNumericWithKM(text) && (!SkyBlockcatiaSettings.INSTANCE.auctionBidConfirm && this.isAuctionPrice() || this.isAuctionStartBidSign() || this.isBazaarPrice() || this.isBankWithdraw() || this.isBankDeposit())) +// { +// this.globalSelector.add(text); +// } +// else if (NumberUtils.isNumeric(text) && this.isBazaarOrder()) +// { +// this.globalSelector.add(text); +// } +// else if (this.isAuctionQuery()) +// { +// this.globalSelector.add(text); +// } +// } + } +// if (!(SkyBlockcatiaSettings.INSTANCE.auctionBidConfirm && this.isAuctionPrice())) { +//// SignSelectionList.processSignData(this.that.tileSign); +// SignSelectionList.processSignData(getTileSign(this.that)); +// } + info.cancel(); + } + } + + @Inject(method = "actionPerformed(Lnet/minecraft/client/gui/GuiButton;)V", cancellable = true, at = @At(value = "INVOKE", target = "net/minecraft/tileentity/TileEntitySign.markDirty()V", shift = Shift.AFTER)) + private void actionPerformed(GuiButton button, CallbackInfo info) throws IOException { +// if (SkyBlockcatiaSettings.INSTANCE.auctionBidConfirm) +// { +// String text = this.that.tileSign.signText[0].getUnformattedText(); +// +// if (!StringUtils.isNullOrEmpty(text) && NumberUtils.isNumeric(text) && this.isAuctionPrice()) +// { +// int price = Integer.parseInt(text); +// +// if (price >= SkyBlockcatiaSettings.INSTANCE.auctionBidConfirmValue) +// { +// this.mc.displayGuiScreen(new GuiYesNo(this, LangUtils.translate("message.bid_confirm_title"), LangUtils.translate("message.bid_confirm"), 201)); +// info.cancel(); +// } +// else +// { +// this.that.tileSign.markDirty(); +// SignSelectionList.processSignData(this.that.tileSign); +// this.globalSelector.add(text); +// } +// } +// } + } + + @Inject(method = "keyTyped(CI)V", cancellable = true, at = @At("HEAD")) + private void keyTyped(char typedChar, int keyCode, CallbackInfo info) throws IOException { + if (SkyBlockcatiaConfig.enableOverwriteSignEditing) { + this.textInputUtil.insert(typedChar); + this.keyPressed(keyCode); + info.cancel(); + } + } + + @Inject(method = "drawScreen(IIF)V", cancellable = true, at = @At("HEAD")) + private void drawScreenPre(int mouseX, int mouseY, float partialTicks, CallbackInfo info) { + if (SkyBlockcatiaConfig.enableOverwriteSignEditing) { + this.drawDefaultBackground(); +// this.drawCenteredString(this.fontRendererObj, LangUtils.translate("sign.edit"), this.width / 2, 40, 16777215); + this.drawCenteredString(this.fontRendererObj, "Sign Edit", this.width / 2, 40, 16777215); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.pushMatrix(); + GlStateManager.translate(this.width / 2d, 0.0F, 50.0F); + float f = 93.75F; + GlStateManager.scale(-f, -f, -f); + GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F); +// Block block = this.that.tileSign.getBlockType(); + Block block = getTileSign(this.that).getBlockType(); + + if (block == Blocks.standing_sign) { +// float f1 = this.that.tileSign.getBlockMetadata() * 360 / 16.0F; + float f1 = getTileSign(this.that).getBlockMetadata() * 360 / 16.0F; + GlStateManager.rotate(f1, 0.0F, 1.0F, 0.0F); + GlStateManager.translate(0.0F, -1.0625F, 0.0F); + } else { +// int i = this.that.tileSign.getBlockMetadata(); + int i = getTileSign(this.that).getBlockMetadata(); + float f2 = 0.0F; + + if (i == 2) { + f2 = 180.0F; + } + + if (i == 4) { + f2 = 90.0F; + } + + if (i == 5) { + f2 = -90.0F; + } + GlStateManager.rotate(f2, 0.0F, 1.0F, 0.0F); + GlStateManager.translate(0.0F, -1.0625F, 0.0F); + } +// ((IModifiedSign) this.that.tileSign).setSelectionState(this.editLine, this.textInputUtil.getSelectionStart(), this.textInputUtil.getSelectionEnd(), this.updateCounter / 6 % 2 == 0); + ((IModifiedSign) getTileSign(this.that)).setSelectionState(this.editLine, this.textInputUtil.getSelectionStart(), this.textInputUtil.getSelectionEnd(), this.updateCounter / 6 % 2 == 0); +// TileEntityRendererDispatcher.instance.renderTileEntityAt(this.that.tileSign, -0.5D, -0.75D, -0.5D, 0.0F); + TileEntityRendererDispatcher.instance.renderTileEntityAt(getTileSign(this.that), -0.5D, -0.75D, -0.5D, 0.0F); +// ((IModifiedSign) this.that.tileSign).resetSelectionState(); + ((IModifiedSign) getTileSign(this.that)).resetSelectionState(); + GlStateManager.popMatrix(); + super.drawScreen(mouseX, mouseY, partialTicks); + + if (SkyBlockEventHandler.isSkyBlock && SkyBlockcatiaConfig.enableSignSelectionList && this.globalSelector != null) { + this.globalSelector.drawScreen(mouseX, mouseY, partialTicks); + } + info.cancel(); + } + } + + @Inject(method = "drawScreen(IIF)V", cancellable = true, at = @At("RETURN")) + private void drawScreenPost(int mouseX, int mouseY, float partialTicks, CallbackInfo info) { + if (!SkyBlockcatiaConfig.enableOverwriteSignEditing && SkyBlockEventHandler.isSkyBlock && SkyBlockcatiaConfig.enableSignSelectionList && this.globalSelector != null) { + this.globalSelector.drawScreen(mouseX, mouseY, partialTicks); + } + } + + @Override + public TextInputUtil getTextInputUtil() { + return this.textInputUtil; + } + + @Override + public SignSelectionList getSignSelectionList() { + return this.globalSelector; + } + + private boolean keyPressed(int keyCode) { + if (keyCode == Keyboard.KEY_UP) { + this.editLine = this.editLine - 1 & 3; + this.textInputUtil.moveCaretToEnd(); + return true; + } else if (keyCode != Keyboard.KEY_DOWN && keyCode != Keyboard.KEY_RETURN && keyCode != Keyboard.KEY_NUMPADENTER) { + return this.textInputUtil.handleSpecialKey(keyCode); + } else { + this.editLine = this.editLine + 1 & 3; + this.textInputUtil.moveCaretToEnd(); + return true; + } + } + + private boolean isAuctionStartBidSign() { +// return this.that.tileSign.signText[2].getUnformattedText().equals("Your auction") && this.that.tileSign.signText[3].getUnformattedText().equals("starting bid"); + return getTileSign(this.that).signText[2].getUnformattedText().equals("Your auction") && getTileSign(this.that).signText[3].getUnformattedText().equals("starting bid"); + } + + private boolean isAuctionPrice() { + return getTileSign(this.that).signText[2].getUnformattedText().equals("auction bid") && getTileSign(this.that).signText[3].getUnformattedText().equals("amount"); + } + + private boolean isBazaarPrice() { + return getTileSign(this.that).signText[2].getUnformattedText().equals("Enter price") && getTileSign(this.that).signText[3].getUnformattedText().equals("big nerd"); + } + + private boolean isAuctionQuery() { + return getTileSign(this.that).signText[3].getUnformattedText().equals("Enter query"); + } + + private boolean isBankWithdraw() { + return getTileSign(this.that).signText[2].getUnformattedText().equals("Enter the amount") && getTileSign(this.that).signText[3].getUnformattedText().equals("to withdraw"); + } + + private boolean isBankDeposit() { + return getTileSign(this.that).signText[2].getUnformattedText().equals("Enter the amount") && getTileSign(this.that).signText[3].getUnformattedText().equals("to deposit"); + } + + private boolean isBazaarOrder() { + return getTileSign(this.that).signText[2].getUnformattedText().equals("Enter amount") && getTileSign(this.that).signText[3].getUnformattedText().equals("to order"); + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/tileentity/TileEntitySignMixin.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/tileentity/TileEntitySignMixin.java new file mode 100644 index 000000000..0863def9a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/tileentity/TileEntitySignMixin.java @@ -0,0 +1,63 @@ +package at.hannibal2.skyhanni.mixins.transformers.tileentity; + +import at.hannibal2.skyhanni.sign.IModifiedSign; +import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.util.IChatComponent; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(TileEntitySign.class) +public class TileEntitySignMixin implements IModifiedSign +{ + private final TileEntitySign that = (TileEntitySign) (Object) this; + private int selectionStart = -1; + private int selectionEnd = -1; + private boolean caretVisible; + + @Override + public IChatComponent getText(int line) + { + return this.that.signText[line]; + } + + @Override + public void setText(int line, IChatComponent component) + { + this.that.signText[line] = component; + } + + @Override + public void setSelectionState(int currentRow, int selectionStart, int selectionEnd, boolean caretVisible) + { + this.that.lineBeingEdited = currentRow; + this.selectionStart = selectionStart; + this.selectionEnd = selectionEnd; + this.caretVisible = caretVisible; + } + + @Override + public void resetSelectionState() + { + this.that.lineBeingEdited = -1; + this.selectionStart = -1; + this.selectionEnd = -1; + this.caretVisible = false; + } + + @Override + public boolean getCaretVisible() + { + return this.caretVisible; + } + + @Override + public int getSelectionStart() + { + return this.selectionStart; + } + + @Override + public int getSelectionEnd() + { + return this.selectionEnd; + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/sign/IEditSign.java b/src/main/java/at/hannibal2/skyhanni/sign/IEditSign.java new file mode 100644 index 000000000..278ec7224 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/sign/IEditSign.java @@ -0,0 +1,7 @@ +package at.hannibal2.skyhanni.sign; + +public interface IEditSign { + TextInputUtil getTextInputUtil(); + + SignSelectionList getSignSelectionList(); +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/sign/IModifiedSign.java b/src/main/java/at/hannibal2/skyhanni/sign/IModifiedSign.java new file mode 100644 index 000000000..38375d5ac --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/sign/IModifiedSign.java @@ -0,0 +1,19 @@ +package at.hannibal2.skyhanni.sign; + +import net.minecraft.util.IChatComponent; + +public interface IModifiedSign { + IChatComponent getText(int line); + + void setText(int line, IChatComponent component); + + void setSelectionState(int currentRow, int selectionStart, int selectionEnd, boolean caretVisible); + + void resetSelectionState(); + + boolean getCaretVisible(); + + int getSelectionStart(); + + int getSelectionEnd(); +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/sign/LorenzSignUtils.java b/src/main/java/at/hannibal2/skyhanni/sign/LorenzSignUtils.java new file mode 100644 index 000000000..5b450a734 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/sign/LorenzSignUtils.java @@ -0,0 +1,64 @@ +package at.hannibal2.skyhanni.sign; + +import net.minecraft.client.gui.inventory.GuiEditSign; +import net.minecraft.tileentity.TileEntitySign; + +import java.lang.reflect.Field; + +public class LorenzSignUtils { + + private static boolean once = false; + private static Field field = null; + //(field_146848_f) class net.minecraft.client.gui.inventory.GuiEditSign + + public static TileEntitySign getTileSign(GuiEditSign editSign) { + +// Field field1 = ReflectionHelper.findField(editSign.getClass(), "editSign"); +// ObfuscationReflectionHelper.getPrivateValue(editSign.getClass(), editSign, 0) + + if (field != null) { + try { + return (TileEntitySign) field.get(editSign); + } catch (IllegalAccessException e) { + throw new RuntimeException("hidden", e); + } + } + + if (once) { + throw new RuntimeException("hidden"); + } + once = true; + + try { + Class aClass = editSign.getClass(); +// System.out.println(""); +// System.out.println(""); +// System.out.println(""); + for (Field field : aClass.getDeclaredFields()) { + String name = field.getName(); + Class fieldDeclaringClass = field.getDeclaringClass(); +// System.out.println(""); +// System.out.println("(" + name + ") " + fieldDeclaringClass); + + field.setAccessible(true); + Object o = field.get(editSign); + if (o instanceof TileEntitySign) { +// System.out.println("DONE!!!!!"); + LorenzSignUtils.field = field; + return (TileEntitySign) o; + } + +// System.out.println(""); + } + +// System.out.println(""); +// System.out.println(""); +// System.out.println(""); + Field field = aClass.getDeclaredField("tileSign"); + field.setAccessible(true); + return (TileEntitySign) field.get(editSign); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException("can not refactor getTileSign! (" + e.getMessage() + ")", e); + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/sign/SignSelectionList.java b/src/main/java/at/hannibal2/skyhanni/sign/SignSelectionList.java new file mode 100644 index 000000000..c9c963cee --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/sign/SignSelectionList.java @@ -0,0 +1,241 @@ +package at.hannibal2.skyhanni.sign; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.client.gui.GuiListExtended; +import net.minecraft.client.gui.inventory.GuiEditSign; +import net.minecraft.client.network.NetHandlerPlayClient; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.network.play.client.C12PacketUpdateSign; +import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ResourceLocation; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class SignSelectionList extends GuiListExtended +{ + public static final List AUCTION_STARTING_BID_PRICES = new ArrayList<>(); + public static final List AUCTION_BID_PRICES = new ArrayList<>(); + public static final List AUCTION_QUERIES = new ArrayList<>(); + public static final List BANK_WITHDRAW = new ArrayList<>(); + public static final List BANK_DEPOSIT = new ArrayList<>(); + public static final List BAZAAR_ORDER = new ArrayList<>(); + public static final List BAZAAR_PRICE = new ArrayList<>(); + private int selectedSlotIndex = -1; + private final List list; + private final String title; + + public SignSelectionList(Minecraft mc, int width, int height, int top, int bottom, List list, String title) + { + super(mc, width, height, top, bottom, 16); + this.list = list; + this.title = title; + + if (this.getSize() > 5) + { + this.list.remove(0); + } + Collections.reverse(this.list); + } + + @Override + protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY) + { + this.selectedSlotIndex = slotIndex; + } + + @Override + public IGuiListEntry getListEntry(int index) + { + return this.list.stream().distinct().collect(Collectors.toList()).get(index); + } + + @Override + protected int getSize() + { + return this.list.stream().distinct().collect(Collectors.toList()).size(); + } + + @Override + protected boolean isSelected(int index) + { + return index == this.selectedSlotIndex; + } + + @Override + protected void drawContainerBackground(Tessellator tessellator) {} + + @Override + protected void overlayBackground(int startY, int endY, int startAlpha, int endAlpha) {} + + @Override + public int getListWidth() + { + return 100; + } + + @Override + public int getSlotHeight() + { + return 10; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) + { + if (this.field_178041_q) + { + this.mouseX = mouseX; + this.mouseY = mouseY; + this.drawBackground(); + this.bindAmountScrolled(); + GlStateManager.disableLighting(); + GlStateManager.disableFog(); + Tessellator tessellator = Tessellator.getInstance(); + this.drawContainerBackground(tessellator); + int k = this.left + this.width / 2 - this.getListWidth() / 2 + 2; + int l = this.top + 4 - (int)this.amountScrolled; + + if (this.hasListHeader) + { + this.drawListHeader(k, l, tessellator); + } + + this.drawSelectionBox(k, l, mouseX, mouseY); + this.mc.fontRendererObj.drawString(this.title + ":", k, l - 12, 16777215); + GlStateManager.disableDepth(); + this.overlayBackground(0, this.top, 255, 255); + this.overlayBackground(this.bottom, this.height, 255, 255); + this.func_148142_b(mouseX, mouseY); + } + GlStateManager.enableDepth(); + } + + public void add(String value) + { + this.list.add(new Entry(value)); + } + + public static void clearAll() + { + SignSelectionList.AUCTION_STARTING_BID_PRICES.clear(); + SignSelectionList.AUCTION_BID_PRICES.clear(); + SignSelectionList.AUCTION_QUERIES.clear(); + SignSelectionList.BANK_WITHDRAW.clear(); + SignSelectionList.BANK_DEPOSIT.clear(); + SignSelectionList.BAZAAR_ORDER.clear(); + SignSelectionList.BAZAAR_PRICE.clear(); + } + + public static class Entry implements GuiListExtended.IGuiListEntry + { + private final Minecraft mc; + private final String value; + private long lastClicked; + + public Entry(String value) + { + this.mc = Minecraft.getMinecraft(); + this.value = value; + } + + @Override + public void setSelected(int p_178011_1_, int p_178011_2_, int p_178011_3_) {} + + @Override + public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) + { + this.mc.fontRendererObj.drawString(this.value, x + 2, y + 2, 16777215); + } + + @Override + public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY) + { +// TileEntitySign sign = ((GuiEditSign)this.mc.currentScreen).tileSign; +// TileEntitySign sign = ().tileSign; + TileEntitySign sign = LorenzSignUtils.getTileSign((GuiEditSign)this.mc.currentScreen); + sign.markDirty(); + + if (Minecraft.getSystemTime() - this.lastClicked < 250L) + { +// if (SkyBlockcatiaSettings.INSTANCE.auctionBidConfirm && NumberUtils.isNumeric(this.value)) +// { +// int price = Integer.parseInt(this.value); +// +// if (price >= SkyBlockcatiaSettings.INSTANCE.auctionBidConfirmValue) +// { +// this.mc.displayGuiScreen(new GuiYesNo(this.mc.currentScreen, LangUtils.translate("message.bid_confirm_title"), LangUtils.translate("message.bid_confirm"), 201)); +// } +// else +// { +// SignSelectionList.processSignData(sign); +// this.mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); +// this.mc.displayGuiScreen(null); +// } +// } +// else +// { + SignSelectionList.processSignData(sign); + this.mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); + this.mc.displayGuiScreen(null); +// } + } + + sign.signText[0] = new ChatComponentText(this.value); + + if (this.mc.currentScreen instanceof IEditSign) + { + ((IEditSign)this.mc.currentScreen).getTextInputUtil().moveCaretToEnd(); + } + this.lastClicked = Minecraft.getSystemTime(); + return false; + } + + @Override + public void mouseReleased(int slotIndex, int x, int y, int mouseEvent, int relativeX, int relativeY) {} + + @Override + public boolean equals(Object obj) + { + if (!(obj instanceof Entry)) + { + return false; + } + if (obj == this) + { + return true; + } + Entry other = (Entry) obj; + return new EqualsBuilder().append(this.value, other.value).isEquals(); + } + + @Override + public int hashCode() + { + return new HashCodeBuilder().append(this.value).toHashCode(); + } + + public String getValue() + { + return this.value; + } + } + + public static void processSignData(TileEntitySign sign) + { + NetHandlerPlayClient nethandlerplayclient = Minecraft.getMinecraft().getNetHandler(); + + if (nethandlerplayclient != null) + { + nethandlerplayclient.addToSendQueue(new C12PacketUpdateSign(sign.getPos(), sign.signText)); + } + sign.setEditable(true); + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/sign/SkyBlockEventHandler.java b/src/main/java/at/hannibal2/skyhanni/sign/SkyBlockEventHandler.java new file mode 100644 index 000000000..6934e5820 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/sign/SkyBlockEventHandler.java @@ -0,0 +1,7 @@ +package at.hannibal2.skyhanni.sign; + +import at.hannibal2.skyhanni.utils.LorenzUtils; + +public class SkyBlockEventHandler { + public static boolean isSkyBlock = LorenzUtils.INSTANCE.getInSkyblock(); +} diff --git a/src/main/java/at/hannibal2/skyhanni/sign/SkyBlockcatiaConfig.java b/src/main/java/at/hannibal2/skyhanni/sign/SkyBlockcatiaConfig.java new file mode 100644 index 000000000..2bd80e8df --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/sign/SkyBlockcatiaConfig.java @@ -0,0 +1,7 @@ +package at.hannibal2.skyhanni.sign; + +public class SkyBlockcatiaConfig { + public static boolean enableOverwriteSignEditing = true; + public static boolean enableSignSelectionList = false; +} + diff --git a/src/main/java/at/hannibal2/skyhanni/sign/TextInputUtil.java b/src/main/java/at/hannibal2/skyhanni/sign/TextInputUtil.java new file mode 100644 index 000000000..a66b31327 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/sign/TextInputUtil.java @@ -0,0 +1,202 @@ +package at.hannibal2.skyhanni.sign; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.util.ChatAllowedCharacters; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.MathHelper; +import org.lwjgl.input.Keyboard; + +import java.util.function.Consumer; +import java.util.function.Supplier; + +public class TextInputUtil { + private final FontRenderer fontRenderer; + private final Supplier stringSupplier; + private final Consumer stringConsumer; + private final int maxLength; + private int selectionStart; + private int selectionEnd; + + public TextInputUtil(FontRenderer fontRenderer, Supplier stringSupplier, Consumer stringConsumer, int maxLength) { + this.fontRenderer = fontRenderer; + this.stringSupplier = stringSupplier; + this.stringConsumer = stringConsumer; + this.maxLength = maxLength; + this.moveCaretToEnd(); + } + + public boolean insert(char typedChar) { + if (ChatAllowedCharacters.isAllowedCharacter(typedChar)) { + this.insert(Character.toString(typedChar)); + } + return true; + } + + private void insert(String typedChar) { + if (this.selectionEnd != this.selectionStart) { + this.deleteSelectedText(); + } + + String s = this.stringSupplier.get(); + this.selectionStart = MathHelper.clamp_int(this.selectionStart, 0, s.length()); + String s1 = new StringBuilder(s).insert(this.selectionStart, typedChar).toString(); + + if (this.fontRenderer.getStringWidth(s1) <= this.maxLength) { + this.stringConsumer.accept(s1); + this.selectionEnd = this.selectionStart = Math.min(s1.length(), this.selectionStart + typedChar.length()); + } + } + + public boolean handleSpecialKey(int keyCode) { + String s = this.stringSupplier.get(); + + if (GuiScreen.isKeyComboCtrlA(keyCode)) { + this.selectionEnd = 0; + this.selectionStart = s.length(); + return true; + } else if (GuiScreen.isKeyComboCtrlC(keyCode)) { + GuiScreen.setClipboardString(this.getSelectedText()); + return true; + } else if (GuiScreen.isKeyComboCtrlV(keyCode)) { + this.insert(ChatAllowedCharacters.filterAllowedCharacters(EnumChatFormatting.getTextWithoutFormattingCodes(GuiScreen.getClipboardString().replaceAll("\\r", "")))); + this.selectionEnd = this.selectionStart; + return true; + } else if (GuiScreen.isKeyComboCtrlX(keyCode)) { + GuiScreen.setClipboardString(this.getSelectedText()); + this.deleteSelectedText(); + return true; + } else { + switch (keyCode) { + case Keyboard.KEY_BACK: + if (!s.isEmpty()) { + if (this.selectionEnd != this.selectionStart) { + this.deleteSelectedText(); + } else if (this.selectionStart > 0) { + s = new StringBuilder(s).deleteCharAt(Math.max(0, this.selectionStart - 1)).toString(); + this.selectionEnd = this.selectionStart = Math.max(0, this.selectionStart - 1); + this.stringConsumer.accept(s); + } + } + return true; + case Keyboard.KEY_DELETE: + if (!s.isEmpty()) { + if (this.selectionEnd != this.selectionStart) { + this.deleteSelectedText(); + } else if (this.selectionStart < s.length()) { + s = new StringBuilder(s).deleteCharAt(Math.max(0, this.selectionStart)).toString(); + this.stringConsumer.accept(s); + } + } + return true; + case Keyboard.KEY_LEFT: + int j = this.fontRenderer.getBidiFlag() ? 1 : -1; + if (GuiScreen.isCtrlKeyDown()) { + this.selectionStart = this.findWordEdge(s, j, this.selectionStart); + } else { + this.selectionStart = Math.max(0, Math.min(s.length(), this.selectionStart + j)); + } + if (!GuiScreen.isShiftKeyDown()) { + this.selectionEnd = this.selectionStart; + } + return true; + case Keyboard.KEY_RIGHT: + int i = this.fontRenderer.getBidiFlag() ? -1 : 1; + if (GuiScreen.isCtrlKeyDown()) { + this.selectionStart = this.findWordEdge(s, i, this.selectionStart); + } else { + this.selectionStart = Math.max(0, Math.min(s.length(), this.selectionStart + i)); + } + if (!GuiScreen.isShiftKeyDown()) { + this.selectionEnd = this.selectionStart; + } + return true; + case Keyboard.KEY_HOME: + this.selectionStart = 0; + if (!GuiScreen.isShiftKeyDown()) { + this.selectionEnd = this.selectionStart; + } + return true; + case Keyboard.KEY_END: + this.selectionStart = this.stringSupplier.get().length(); + if (!GuiScreen.isShiftKeyDown()) { + this.selectionEnd = this.selectionStart; + } + return true; + default: + return false; + } + } + } + + private String getSelectedText() { + String s = this.stringSupplier.get(); + int i = Math.min(this.selectionStart, this.selectionEnd); + int j = Math.max(this.selectionStart, this.selectionEnd); + return s.substring(i, j); + } + + private void deleteSelectedText() { + if (this.selectionEnd != this.selectionStart) { + String s = this.stringSupplier.get(); + int i = Math.min(this.selectionStart, this.selectionEnd); + int j = Math.max(this.selectionStart, this.selectionEnd); + String s1 = s.substring(0, i) + s.substring(j); + this.selectionStart = i; + this.selectionEnd = this.selectionStart; + this.stringConsumer.accept(s1); + } + } + + public void moveCaretToEnd() { + this.selectionEnd = this.selectionStart = this.stringSupplier.get().length(); + } + + public int getSelectionStart() { + return this.selectionStart; + } + + public int getSelectionEnd() { + return this.selectionEnd; + } + + private int findWordEdge(String text, int bidiFlag, int selectionStart) { + int i = selectionStart; + boolean flag = bidiFlag < 0; + int j = Math.abs(bidiFlag); + + for (int k = 0; k < j; ++k) { + if (flag) { + while (i > 0 && (text.charAt(i - 1) == ' ' || text.charAt(i - 1) == '\n')) { + --i; + } + while (i > 0 && text.charAt(i - 1) != ' ' && text.charAt(i - 1) != '\n') { + --i; + } + } else { + int l = text.length(); + int i1 = text.indexOf(32, i); + int j1 = text.indexOf(10, i); + + if (i1 == -1 && j1 == -1) { + i = -1; + } else if (i1 != -1 && j1 != -1) { + i = Math.min(i1, j1); + } else if (i1 != -1) { + i = i1; + } else { + i = j1; + } + + if (i == -1) { + i = l; + } else { + while (i < l && (text.charAt(i) == ' ' || text.charAt(i) == '\n')) { + ++i; + } + } + } + } + return i; + } +} \ No newline at end of file -- cgit