Added a cloud height slider in video options

master
Wynd 2024-08-30 13:18:57 +03:00
parent 406fe6f861
commit 033d175097
7 changed files with 136 additions and 9 deletions

View File

@ -48,6 +48,8 @@ public class ModConfig {
"Enables furance minecarts to push forward the first minecart it comes in contact with");
public static final Option<Boolean> FURNACE_MINECART_CHUNK_LOADING = make("Enable furnace minecarts to load chunks", true,
"Name says it all, furnace minecarts will load chunks as they go on tracks.");
public static final Option<Double> CLOUDS_HEIGHT = make("Clouds Height", 0.0,
"Clouds height modifier, goes from 0.0, meaning the default 108 blocks height, to 1.0, meaning a 324 blocks height.");
public static final Option<Boolean> FIX_BOW_MODEL = make("Fix bow model", true,
"Makes the box model held by players and skeletons bigger and facing forward");

View File

@ -0,0 +1,79 @@
package xyz.pixelatedw.finalbeta;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widgets.Button;
public class ModSlider extends Button {
public float value = 1.0F;
public boolean dragged = false;
public final String defaultText;
private final IChanceValue changeEvent;
public ModSlider(int id, int x, int y, String label, float initialValue, IChanceValue changeEvent) {
super(id, x, y, 150, 20, label);
this.value = initialValue;
this.defaultText = label;
this.changeEvent = changeEvent;
this.text = this.defaultText + "" + String.format("%.2f", this.value);
}
@Override
protected int getYImage(boolean flag) {
return 0;
}
@Override
protected void postRender(Minecraft minecraft, int i, int j) {
if (this.visible) {
if (this.dragged) {
this.value = (float) (i - (this.x + 4)) / (float) (this.width - 8);
if (this.value < 0.0F) {
this.value = 0.0F;
}
if (this.value > 1.0F) {
this.value = 1.0F;
}
this.changeEvent.changeValue(this.value);
this.text = this.defaultText + "" + String.format("%.2f", this.value);
}
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.blit(this.x + (int) (this.value * (this.width - 8)), this.y, 0, 66, 4, 20);
this.blit(this.x + (int) (this.value * (this.width - 8)) + 4, this.y, 196, 66, 4, 20);
}
}
@Override
public boolean isMouseOver(Minecraft minecraft, int i, int j) {
if (super.isMouseOver(minecraft, i, j)) {
this.value = (float) (i - (this.x + 4)) / (float) (this.width - 8);
if (this.value < 0.0F) {
this.value = 0.0F;
}
if (this.value > 1.0F) {
this.value = 1.0F;
}
this.changeEvent.changeValue(this.value);
this.text = this.defaultText + "" + String.format("%.2f", this.value);
this.dragged = true;
return true;
} else {
return false;
}
}
@Override
public void mouseReleased(int i, int j) {
this.dragged = false;
}
public interface IChanceValue {
void changeValue(float value);
}
}

View File

@ -95,7 +95,7 @@ public class WyHelper {
// Slime slime = new Slime(player.level);
// slime.setPositionAndAngles(player.x, player.y + 0.5D, player.z, player.level.rand.nextFloat() * 360.0F, 0.0F);
// player.level.spawnEntity(slime);
// slime.setSize(10);
// slime.setSize(5);
// player.level.entities.stream().filter(e -> !(e instanceof Player)).forEach((e) -> ((net.minecraft.entity.Entity)e).remove());

View File

@ -0,0 +1,20 @@
package xyz.pixelatedw.finalbeta.mixin;
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;
import net.minecraft.level.dimension.Dimension;
import xyz.pixelatedw.finalbeta.ModConfig;
@Mixin(Dimension.class)
public class DimensionMixin {
private static final float CLOUD_HEIGHT = 108.0F;
@Inject(method = "getCloudHeight", at = @At("RETURN"), cancellable = true)
private void getCloudHeight(CallbackInfoReturnable<Float> cir) {
float height = CLOUD_HEIGHT + (CLOUD_HEIGHT * 2.0f * ModConfig.CLOUDS_HEIGHT.get().floatValue());
cir.setReturnValue(height);
}
}

View File

@ -4,6 +4,9 @@ import java.util.List;
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;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Screen;
@ -16,4 +19,11 @@ public class ScreenMixin {
@Shadow
public List buttons;
@Inject(method = "onClose", at = @At("HEAD"))
public void onClose(CallbackInfo ci) {
this.onCloseEvent();
}
public void onCloseEvent() {}
}

View File

@ -9,6 +9,7 @@ import net.minecraft.client.gui.screen.VideoSettingsScreen;
import net.minecraft.client.gui.widgets.Button;
import net.minecraft.client.resource.language.TranslationStorage;
import xyz.pixelatedw.finalbeta.ModConfig;
import xyz.pixelatedw.finalbeta.ModSlider;
@Mixin(VideoSettingsScreen.class)
public class VideoSettingsScreenMixin extends ScreenMixin {
@ -16,20 +17,34 @@ public class VideoSettingsScreenMixin extends ScreenMixin {
@Inject(method = "init", at = @At("TAIL"))
public void init(CallbackInfo ci) {
VideoSettingsScreen screen = (VideoSettingsScreen)(Object)this;
this.buttons.add(new Button(300, screen.width / 2 - 155, screen.height / 6 + 96, 150, 20, this.getCloudsLabel()));
this.buttons.add(new ModSlider(301, screen.width / 2 + 5, screen.height / 6 + 96, this.getCloudHeightLabel(), ModConfig.CLOUDS_HEIGHT.get().floatValue(), (val) -> ModConfig.CLOUDS_HEIGHT.set((double) val)));
}
@Inject(method = "buttonClicked", at = @At("HEAD"))
@Inject(method = "buttonClicked", at = @At("HEAD"), cancellable = true)
public void buttonClicked(Button btn, CallbackInfo ci) {
if(btn.active) {
if(btn.id == 300) {
if (btn.active) {
if (btn.id == 300) {
ModConfig.ENABLE_CLOUDS.set(!ModConfig.ENABLE_CLOUDS.get());
ci.cancel();
}
else if(btn.id == 301) {
ci.cancel();
}
}
}
@Override
public void onCloseEvent() {
}
private String getCloudsLabel() {
TranslationStorage i18n = TranslationStorage.getInstance();
return "Clouds: " + (ModConfig.ENABLE_CLOUDS.get() ? i18n.translate("options.on") : i18n.translate("options.off"));
}
private String getCloudHeightLabel() {
return "Clouds Height: ";
}
}

View File

@ -42,7 +42,8 @@
"RecipeRegistryMixin",
"SnowballMixin",
"EntityMixin",
"SlimeMixin"
"SlimeMixin",
"DimensionMixin"
],
"injectors": {
"defaultRequire": -1