just a copy of petroleum right now

This commit is contained in:
jane 2020-12-19 18:30:50 -05:00
commit 183c81258a
88 changed files with 7405 additions and 0 deletions

View file

@ -0,0 +1,38 @@
package pm.j4.petroleum.mixin;
import java.util.List;
import java.util.Optional;
import net.minecraft.client.gui.hud.DebugHud;
import net.minecraft.client.util.math.MatrixStack;
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;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import pm.j4.petroleum.modules.splash.SplashText;
import pm.j4.petroleum.util.config.ConfigHolder;
import pm.j4.petroleum.util.config.ConfigManager;
/**
* The type Debug hud mixin.
*/
@Mixin(DebugHud.class)
public class DebugHudMixin {
/**
* Render text right.
*
* @param matrices the matrices
* @param ci the ci
* @param list the list
*/
@Inject(method = "renderLeftText",
at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/client/gui/hud/DebugHud;getLeftText()Ljava/util/List;"),
locals = LocalCapture.CAPTURE_FAILSOFT)
protected void renderTextRight(MatrixStack matrices, CallbackInfo ci, List<String> list) {
Optional<ConfigHolder> config = ConfigManager.getConfig();
if (config.isPresent() && config.get().isModuleEnabled("petroleum.splashtext")) {
list.add("[Petroleum] " + SplashText.get() + " loaded");
}
}
}

View file

@ -0,0 +1,19 @@
package pm.j4.petroleum.mixin;
import net.minecraft.client.gui.widget.EntryListWidget;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
/**
* The interface Entry list widget accessor.
*/
@Mixin(EntryListWidget.class)
public interface EntryListWidgetAccessor {
/**
* Is render selection boolean.
*
* @return the boolean
*/
@Accessor("renderSelection")
boolean isRenderSelection();
}

View file

@ -0,0 +1,89 @@
package pm.j4.petroleum.mixin;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.TranslatableText;
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 pm.j4.petroleum.modules.list.ModList;
import pm.j4.petroleum.util.config.ConfigHolder;
import pm.j4.petroleum.util.config.ConfigManager;
import pm.j4.petroleum.util.module.ModuleBase;
/**
* The type Mod list mixin.
*/
@Mixin(InGameHud.class)
public abstract class ModListMixin extends DrawableHelper {
/**
* The Scaled height.
*/
@Shadow
private int scaledHeight;
/**
* The Client.
*/
private final MinecraftClient client;
/**
* Gets font renderer.
*
* @return the font renderer
*/
@Shadow
public abstract TextRenderer getFontRenderer();
/**
* Instantiates a new Mod list mixin.
*
* @param client the client
*/
public ModListMixin(MinecraftClient client) {
this.client = client;
}
/**
* Render.
*
* @param matrices the matrices
* @param tickDelta the tick delta
* @param ci the ci
*/
@Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;F)V",
at = @At("HEAD"))
public void render(MatrixStack matrices, float tickDelta, CallbackInfo ci) {
Optional<ConfigHolder> config = ConfigManager.getConfig();
if (config.isPresent() &&
config.get().isModuleEnabled("petroleum.modlist") &&
!this.client.options.hudHidden &&
!this.client.options.debugEnabled) {
renderModuleList(matrices);
}
}
/**
* Render module list.
*
* @param matrices the matrices
*/
private void renderModuleList(MatrixStack matrices) {
List<ModuleBase> modules = ModList.getActive();
List<TranslatableText> activeModuleList = modules.stream().map(module -> module.getReadableName()).collect(Collectors.toList());
int fontHeight = this.getFontRenderer().fontHeight;
int startHeight = this.scaledHeight - (activeModuleList.size() * (fontHeight + 4));
for (int i = 0; i < activeModuleList.size(); i++) {
this.getFontRenderer().drawWithShadow(matrices, activeModuleList.get(i), 10, 10 + (i * (fontHeight + 4)), -1);
}
}
}

View file

@ -0,0 +1,42 @@
package pm.j4.petroleum.mixin;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.options.OptionsScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
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;
import pm.j4.petroleum.gui.POptionsScreen;
/**
* The type Options menu mixin.
*/
@Mixin(OptionsScreen.class)
public class OptionsMenuMixin extends Screen {
/**
* Instantiates a new Options menu mixin.
*
* @param title the title
*/
protected OptionsMenuMixin(Text title) {
super(title);
}
/**
* Init.
*
* @param ci the ci
*/
@Inject(at = @At(value = "TAIL"),
method = "init()V")
protected void init(CallbackInfo ci) {
this.addButton(new ButtonWidget(this.width / 2 - 75, this.height / 6 + 140, 150, 20, new TranslatableText("petroleum.options"), (buttonWidget) -> {
assert this.client != null;
this.client.openScreen(new POptionsScreen(this));
}));
}
}

View file

@ -0,0 +1,132 @@
package pm.j4.petroleum.mixin;
import java.util.Optional;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
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;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import pm.j4.petroleum.modules.splash.SplashText;
import pm.j4.petroleum.util.config.ConfigHolder;
import pm.j4.petroleum.util.config.ConfigManager;
/**
* Mixin attached to the TitleScreen.
* Currently, it is only used to display a string of text with the mod's version.
* Any other modules will likely extend the options screen or pause screen,
* so the module is unlikely to be used elsewhere.
*/
@Mixin(TitleScreen.class)
public class TitleScreenMixin extends Screen {
/**
* The Opacity.
*/
private double opacity = 0;
/**
* The Ascending.
*/
private boolean ascending = false;
/**
* Stub method.
* Since the mixin injects itself into the *actual* TitleScreen used by the game,
* this should never run.
*
* @param title the title
*/
protected TitleScreenMixin(Text title) {
super(title);
}
/**
* Mixin injection into the render method.
* It captures locals so that the text can be rendered alongside the
* screen fade-in.
* It injects before the call to @link com.mojang.bridge.game.GameVersion#getName() using INVOKE_ASSIGN,
* because attempting to use a regular invoke statement on @link net.minecraft.client.gui.DrawHelper#drawStringWithShadow()
* repeatedly failed.
* <p>
*
* @param matrices the matrices
* @param mouseX the mouse x
* @param mouseY the mouse y
* @param delta the delta
* @param ci the ci
* @param f the f
* @param i the
* @param j the j
* @param g the g
* @param l the l
*/
@Inject(method = "render",
at = @At(
value = "INVOKE_ASSIGN",
target = "Lcom/mojang/bridge/game/GameVersion;getName()Ljava/lang/String;",
ordinal = 0),
locals = LocalCapture.CAPTURE_FAILSOFT)
private void render(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci, float f, int i, int j, float g, int l) {
Optional<ConfigHolder> config = ConfigManager.getConfig();
if (config.isPresent() && config.get().isModuleEnabled("petroleum.splashtext")) {
drawStringWithShadow(matrices, this.textRenderer, SplashText.get(), 2, this.height - 20, blink(13108374) | l);
}
}
/**
* fades an integer color based on the values declared at the top of the class.
*
* @param color the integer representation of the color to fade. this should generally remain constant.
* @return the color, adjusted for "opacity". It's RGB and not RGBA, so it just lowers all color values.
*/
@SuppressWarnings("SameParameterValue")
private int blink(int color) {
/*
The Speed.
*/
int speed = 3;
/*
The Opacity max.
*/
double opacity_max = 1000;
if (ascending) {
opacity += speed;
if (opacity > opacity_max) {
opacity = opacity_max;
ascending = false;
}
} else {
opacity -= speed;
/*
The Opacity min.
*/
double opacity_min = 500;
if (opacity < opacity_min) {
opacity = opacity_min;
ascending = true;
}
}
double opacityD = (opacity / opacity_max);
/*
The R mask.
*/
int r_mask = 16711680;
int r = ((color & r_mask) / Integer.parseInt("010000", 16));
/*
The G mask.
*/
int g_mask = 65280;
int g = ((color & g_mask) / Integer.parseInt("000100", 16));
/*
The B mask.
*/
int b_mask = 255;
int b = ((color & b_mask));
return ((int) (r * opacityD) * Integer.parseInt("010000", 16)) |
((int) (g * opacityD) * Integer.parseInt("000100", 16)) |
((int) (b * opacityD));
}
}