Skip to content

Commit

Permalink
new: server preview in direct connect
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Dec 15, 2021
1 parent 019a94d commit a1fdb58
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 12 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ version = mod_ver
group = "net.wyvest"
archivesBaseName = mod_name

sourceCompatibility = targetCompatibility = 1.8
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
compileJava.options.encoding = "UTF-8"

minecraft {
Expand Down Expand Up @@ -68,6 +68,7 @@ jar {
'ForceLoadAsMod': true,
"MixinConfigs": "mixins.redaction.json",
'TweakClass': 'gg.essential.loader.stage0.EssentialSetupTweaker',
'FMLAT': 'redaction_at.cfg',
'TweakOrder': '0'
)

Expand All @@ -93,6 +94,7 @@ processResources {
from(sourceSets.main.resources.srcDirs) {
exclude "mcmod.info"
}
rename '(.+_at.cfg)', 'META-INF/$1'
}

tasks.reobfJar.dependsOn tasks.shadowJar
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2G

# Define project properties.
mod_name=REDACTION
mod_ver=0.3.0
mod_ver=0.4.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.wyvest.redaction.mixin;

import net.minecraft.client.gui.*;
import net.minecraft.client.multiplayer.ServerData;
import net.wyvest.redaction.config.RedactionConfig;
import org.spongepowered.asm.mixin.Final;
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(GuiScreenServerList.class)
public class GuiScreenServerListMixin extends GuiScreen {
@Shadow @Final private GuiScreen field_146303_a;
@Shadow private GuiTextField field_146302_g;
private ServerListEntryNormal serverPreview;

@Inject(method = "initGui", at = @At("TAIL"))
private void initServerPreview(CallbackInfo ci) {
if (RedactionConfig.INSTANCE.getServerPreview()) {
serverPreview = new ServerListEntryNormal(((GuiMultiplayer) field_146303_a), new ServerData("", "", false));
}
}

@Inject(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiTextField;drawTextBox()V"))
private void drawServerPreview(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) {
if (RedactionConfig.INSTANCE.getServerPreview() && serverPreview != null) {
if (!serverPreview.getServerData().serverIP.equals(field_146302_g.getText())) {
serverPreview.getServerData().serverIP = field_146302_g.getText();
serverPreview.getServerData().serverName = field_146302_g.getText();
serverPreview.getServerData().field_78841_f = false;
}
serverPreview.drawEntry(0, width / 2 - 100, 30, 200, 35, mouseX, mouseY, false);
}
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/net/wyvest/redaction/Redaction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object Redaction {
private val particleGenerator = ParticleGenerator()

const val NAME = "REDACTION"
const val VERSION = "0.3.0"
const val VERSION = "0.4.0"
const val ID = "redaction"
val mc: Minecraft
get() = Minecraft.getMinecraft()
Expand Down
16 changes: 12 additions & 4 deletions src/main/kotlin/net/wyvest/redaction/config/RedactionConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ object RedactionConfig : Vigilant(File(Redaction.modDir, "${Redaction.ID}.toml")
)
var fixSkinRendering = true

@Property(
type = PropertyType.SWITCH,
name = "Server Preview in Direct Connect",
description = "Show a server preview in the direct connect GUI.",
category = "General"
)
var serverPreview = false

@Property(
type = PropertyType.SWITCH,
name = "Blackbar",
Expand Down Expand Up @@ -64,10 +72,6 @@ object RedactionConfig : Vigilant(File(Redaction.modDir, "${Redaction.ID}.toml")
max = 1000
)
var particles = 100
set(value) {
hasChanged = true
field = value
}

@Property(
type = PropertyType.SWITCH,
Expand All @@ -92,5 +96,9 @@ object RedactionConfig : Vigilant(File(Redaction.modDir, "${Redaction.ID}.toml")

init {
initialize()
registerListener("particles") { newValue: Int ->
particles = newValue
hasChanged = true
}
}
}
8 changes: 4 additions & 4 deletions src/main/kotlin/net/wyvest/redaction/hud/elements/BlackBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import net.minecraft.client.gui.ScaledResolution
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.ResourceLocation
import net.wyvest.redaction.Redaction
import net.wyvest.redaction.Redaction.mc
import net.wyvest.redaction.config.RedactionConfig
import net.wyvest.redaction.hud.Element
import net.wyvest.redaction.utils.GlUtil
Expand All @@ -23,7 +23,7 @@ class BlackBar : Element() {
private var entityplayer: EntityPlayer? = null

private val timer = Timer(25) {
if (entityplayer != null && Redaction.mc.thePlayer != null && Redaction.mc.theWorld != null && scaledResolution != null && partialTicks != null) {
if (entityplayer != null && mc.thePlayer != null && mc.theWorld != null && scaledResolution != null && partialTicks != null) {
data?.let {
val scaledHeight = scaledResolution!!.scaledHeight
val scaledWidth = scaledResolution!!.scaledWidth
Expand Down Expand Up @@ -66,9 +66,9 @@ class BlackBar : Element() {
data?.let {
scaledResolution = res
this.partialTicks = partialTicks
entityplayer = Redaction.mc.renderViewEntity as EntityPlayer
entityplayer = mc.renderViewEntity as EntityPlayer
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f)
Redaction.mc.textureManager.bindTexture(texPath)
mc.textureManager.bindTexture(texPath)
val scaledWidth = res.scaledWidth
val scaledHeight = res.scaledHeight
if (firstTime) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/net/wyvest/redaction/utils/StringUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ import org.apache.commons.lang3.StringUtils as ApacheStringUtils
* Adapted from Skytils under AGPLv3
* https://github.com/Skytils/SkytilsMod/blob/1.x/LICENSE.md
*/
fun String?.startsWithAny(vararg sequences: CharSequence?) = ApacheStringUtils.startsWithAny(this, *sequences)
fun String.startsWithAny(vararg sequences: CharSequence?) = ApacheStringUtils.startsWithAny(this, *sequences)
1 change: 1 addition & 0 deletions src/main/resources/mixins.redaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"refmap": "mixins.redaction.refmap.json",
"mixins": [
"GuiIngameMixin",
"GuiScreenServerListMixin",
"ImageBufferDownloadMixin"
],
"verbose": true
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/redaction_at.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public net.minecraft.client.gui.ServerListEntryNormal <init>(Lnet/minecraft/client/gui/GuiMultiplayer;Lnet/minecraft/client/multiplayer/ServerData;)V # constructor

0 comments on commit a1fdb58

Please sign in to comment.