generated from Qalcyo-Archive/ForgeModTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize mixin update updater
- Loading branch information
Showing
13 changed files
with
174 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx4G | |
|
||
mod_name=DamageTint | ||
mod_id=damagetint | ||
mod_ver=3.1.0 | ||
mod_ver=3.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...damagetint/command/DamageTintCommand.java → ...damagetint/command/DamageTintCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/net/wyvest/damagetint/mixin/RendererLivingEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package net.wyvest.damagetint.mixin; | ||
|
||
import net.minecraft.client.renderer.entity.RendererLivingEntity; | ||
import net.minecraft.entity.EntityLivingBase; | ||
import net.wyvest.damagetint.config.Config; | ||
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.ModifyArg; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.awt.*; | ||
|
||
@Mixin(RendererLivingEntity.class) | ||
public class RendererLivingEntityMixin { | ||
private EntityLivingBase entitylivingbaseIn; | ||
|
||
@Inject(method = "setBrightness", at = @At("HEAD")) | ||
private void set(EntityLivingBase entitylivingbaseIn, float partialTicks, boolean combineTextures, CallbackInfoReturnable<Boolean> cir) { | ||
this.entitylivingbaseIn = entitylivingbaseIn; | ||
} | ||
|
||
@ModifyArg(method = "setBrightness", at = @At(value = "INVOKE", target = "Ljava/nio/FloatBuffer;put(F)Ljava/nio/FloatBuffer;", ordinal = 0)) | ||
private float getRedTint(float f) { | ||
if (Config.toggle) { | ||
if (Config.chroma) { | ||
return ((float) ((timeBasedChroma() >> 16) & 0xFF)) / 255; | ||
} else { | ||
return ((float) Config.color.getRed()) / 255; | ||
} | ||
} | ||
return f; | ||
} | ||
|
||
@ModifyArg(method = "setBrightness", at = @At(value = "INVOKE", target = "Ljava/nio/FloatBuffer;put(F)Ljava/nio/FloatBuffer;", ordinal = 1)) | ||
private float getGreenTint(float f) { | ||
if (Config.toggle) { | ||
if (Config.chroma) { | ||
return ((float) ((timeBasedChroma() >> 8) & 0xFF)) / 255; | ||
} else { | ||
return ((float) Config.color.getGreen()) / 255; | ||
} | ||
} | ||
return f; | ||
} | ||
|
||
@ModifyArg(method = "setBrightness", at = @At(value = "INVOKE", target = "Ljava/nio/FloatBuffer;put(F)Ljava/nio/FloatBuffer;", ordinal = 2)) | ||
private float getBlueTint(float f) { | ||
if (Config.toggle) { | ||
if (Config.chroma) { | ||
return ((float) (timeBasedChroma() & 0xFF)) / 255; | ||
} else { | ||
return ((float) Config.color.getBlue()) / 255; | ||
} | ||
} | ||
return f; | ||
} | ||
|
||
@ModifyArg(method = "setBrightness", at = @At(value = "INVOKE", target = "Ljava/nio/FloatBuffer;put(F)Ljava/nio/FloatBuffer;", ordinal = 3)) | ||
private float getAlphaTint(float f) { | ||
if (Config.toggle) { | ||
if (Config.fade) { | ||
float percent = 1.0F - (float) entitylivingbaseIn.hurtTime / (float) entitylivingbaseIn.maxHurtTime; | ||
percent = percent < 0.5F ? percent / 0.5F : (1.0F - percent) / 0.5F; | ||
return (float) Config.color.getAlpha() * percent / 255.0F; | ||
} else { | ||
return (float) Config.color.getAlpha() / 255.0F; | ||
} | ||
} | ||
return f; | ||
} | ||
|
||
public int timeBasedChroma() { | ||
return Color.HSBtoRGB((float) (System.currentTimeMillis() % (long) ((int) (10000.0F / (float) Config.speed))) / (10000.0F / (float) Config.speed), 1.0F, 1.0F); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/net/wyvest/damagetint/updater/DownloadGui.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package net.wyvest.damagetint.updater; | ||
|
||
import gg.essential.api.EssentialAPI; | ||
import gg.essential.api.gui.ConfirmationModalBuilder; | ||
import gg.essential.api.utils.Multithreading; | ||
import gg.essential.elementa.ElementaVersion; | ||
import gg.essential.elementa.WindowScreen; | ||
import kotlin.Unit; | ||
import net.wyvest.damagetint.DamageTint; | ||
|
||
import java.io.File; | ||
|
||
public class DownloadGui extends WindowScreen { | ||
public DownloadGui() { | ||
super(ElementaVersion.V1, true, true, true, -1); | ||
} | ||
|
||
@Override | ||
public void initScreen(int width, int height) { | ||
super.initScreen(width, height); | ||
EssentialAPI.getEssentialComponentFactory().build(makeModal()).setChildOf(getWindow()); | ||
} | ||
|
||
private ConfirmationModalBuilder makeModal() { | ||
ConfirmationModalBuilder builder = new ConfirmationModalBuilder(); | ||
builder.setText("Are you sure you want to update?"); | ||
builder.setSecondaryText("(This will update from v" + DamageTint.VER + " to " + Updater.latestTag + ")"); | ||
builder.setOnConfirm((wyvest) -> { | ||
restorePreviousScreen(); | ||
Multithreading.runAsync(() -> { | ||
if (Updater.download( | ||
Updater.updateUrl, | ||
new File( | ||
"mods/" + DamageTint.NAME + "-" + Updater.latestTag.substring(Updater.latestTag.indexOf("v")) + ".jar" | ||
) | ||
) && Updater.download( | ||
"https://github.com/Wyvest/Deleter/releases/download/v1.2/Deleter-1.2.jar", | ||
new File(DamageTint.modDir.getParentFile(), "Deleter-1.2.jar") | ||
) | ||
) { | ||
EssentialAPI.getNotifications() | ||
.push(DamageTint.NAME, "The ingame updater has successfully installed the newest version."); | ||
Updater.addShutdownHook(); | ||
Updater.shouldUpdate = false; | ||
} else { | ||
EssentialAPI.getNotifications().push( | ||
DamageTint.NAME, | ||
"The ingame updater has NOT installed the newest version as something went wrong." | ||
); | ||
} | ||
}); | ||
return Unit.INSTANCE; | ||
}); | ||
|
||
builder.setOnDeny(() -> { | ||
restorePreviousScreen(); | ||
return Unit.INSTANCE; | ||
}); | ||
|
||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.