Skip to content

Commit

Permalink
PresetBuilder for groovyscript! also some other stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
strubium committed Oct 15, 2024
1 parent 93122cc commit d413dcb
Show file tree
Hide file tree
Showing 6 changed files with 340 additions and 51 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ This mod also has a flexible API that other mods can use to add more information
* Features from TOP Extras
* View the Enchantment power of Bookshelf's
* View Inventory of Minecarts and Mules
* View how long the fuse of lit TNT has left
* View the time left until TNT explodes
* View how much water is in a Cauldron
* View what disk is playing in a Jukebox
* View a paintings name
* Fixes from TopFix
* Show fluid local name when playing on a server
* Show the fluid's local name when playing on a server
* Fixed chests not displaying the local names of GregTechCE items when playing on a server
* Updated gradle version from 2.7 to 4.5
* View more information with the Creative Probe
* A greatly improved config screen
* View all config categories, not just the client ones.
* Sub categories to help group things
* New theme presets
* Jade: based on the [mod](https://www.curseforge.com/minecraft/mc-mods/jade) of the same name
* Crazy: please don't use this, your eyeballs will thank me.
Expand All @@ -33,16 +36,25 @@ This mod also has a flexible API that other mods can use to add more information
* showDebugUUID (Default: False) If you want to see the UUID of an NPC with the Creative Probe
* probeNoteStackSize (Default: 1) Change the stack size of the One Probe Read Me.
* harvestLevels (Default: Stone-Vibranium) Add/remove lang keys for the harvest levels if say you have a block with a > 8 harvest level
* probeMaxChars (Default: 13) The max length to display in the probe, will be truncated
* showProbeConfigGUI (Default: true) If players can open the Config UI in the Probe/Note
* showProbeNoteGUI (Default: true) If players can open the Note UI in the Note
* probeNoteBlock (Default: minecraft:log) The block to use as the example in the probe config UI
* Replaced the hardcoded strings with language-translatable versions
* Updated ru_ru.lang (By: @bigenergy)
* New en_ud.lang
* New uk_ua.lang (By: @SKZGx)
* New zh_tw.lang (By: @HJ-zhtw)
* New de_de.lang (By: @TheScienceDemon)
* New zh_cn.lang and zh_tw.lang (Fully translated as of Dev-14)
* New ja_jp.lang (Fully translated as of Dev-15)
* Javadoc's for the random methods lying around to make working easier
* Many Progress Bars for slower computers (Almost impossible to see if you have a mid-teir computer)
* Improved config GUI
* API improvements
* New ProbeBase to simplify probe creation of new probes
* New PresetBuilder to simplify making new presets (And for GroovyScript compact!)
* Fixed isProbeInHand() checking for the wrong NBT tag
* Fixed isProbeHelmet() always checking NBT even though we know that our helmets are probe helmets

Note: Languages other than English may not be fully translated, feel free to submit a PR

Expand Down
151 changes: 103 additions & 48 deletions src/main/java/mcjty/theoneprobe/gui/GuiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import mcjty.theoneprobe.apiimpl.ProbeInfo;
import mcjty.theoneprobe.config.ConfigSetup;
import mcjty.theoneprobe.rendering.RenderHelper;
import mcjty.theoneprobe.setup.ModSetup;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
Expand All @@ -19,7 +18,6 @@
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.tuple.Pair;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -46,54 +44,111 @@ public class GuiConfig extends GuiScreen {
private static final ResourceLocation background = new ResourceLocation(TheOneProbe.MODID, "textures/gui/config.png");
private static final ResourceLocation scene = new ResourceLocation(TheOneProbe.MODID, "textures/gui/scene.png");

private static final List<Preset> presets = new ArrayList<>();

private List<HitBox> hitboxes = Collections.emptyList();

static {
presets.add(new Preset("Default", 0xff999999, 0x55006699, 2, 0));
presets.add(new Preset("WAILA", 0xff4503d0, 0xff000000, 1, 1));
presets.add(new Preset("Jade", 0xff323331, 0xff20261a, 1, 1));
presets.add(new Preset("Fully transparent", 0x00000000, 0x00000000, 0, 0));
presets.add(new Preset("Black & White", 0xffffffff, 0xff000000, 2, 0,
Pair.of(MODNAME, "white,italic"),
Pair.of(NAME, "white,bold"),
Pair.of(INFO, "white"),
Pair.of(INFOIMP, "white,bold"),
Pair.of(WARNING, "white"),
Pair.of(ERROR, "white,underline"),
Pair.of(OBSOLETE, "white,strikethrough"),
Pair.of(LABEL, "white,bold"),
Pair.of(OK, "white"),
Pair.of(PROGRESS, "white")
));
presets.add(new Preset("Crazy!", 0xff00ff00, 0x55ff0000, 2, 0,
Pair.of(MODNAME, "green"),
Pair.of(NAME, "yellow,bold"),
Pair.of(INFO, "cyan,bold"),
Pair.of(INFOIMP, "magenta,bold"),
Pair.of(WARNING, "orange,bold"),
Pair.of(ERROR, "red,bold"),
Pair.of(OBSOLETE, "gray,bold"),
Pair.of(LABEL, "blue,bold"),
Pair.of(OK, "green,bold"),
Pair.of(PROGRESS, "white,bold")
));
presets.add(new Preset("Soft Pastels", 0xffe0bbff, 0x00000000, 1, 1,
Pair.of(MODNAME, "pink,bold,italic")
));
presets.add(new Preset("Ocean Blue", 0xff003366, 0x556699cc, 2, 0,
Pair.of(MODNAME, "cyan"),
Pair.of(NAME, "light_blue,bold"),
Pair.of(INFO, "white"),
Pair.of(INFOIMP, "white,bold"),
Pair.of(WARNING, "yellow,bold"),
Pair.of(ERROR, "red,bold"),
Pair.of(OBSOLETE, "gray,bold,italic"),
Pair.of(LABEL, "aqua,bold"),
Pair.of(OK, "green,bold"),
Pair.of(PROGRESS, "white,bold")
));
// "Default" preset
new PresetBuilder()
.setName("Default")
.setBoxBorderColor(0xff999999)
.setBoxFillColor(0x55006699)
.setBoxThickness(2)
.setBoxOffset(0)
.build();

// "WAILA" preset
new PresetBuilder()
.setName("WAILA")
.setBoxBorderColor(0xff4503d0)
.setBoxFillColor(0xff000000)
.setBoxThickness(1)
.setBoxOffset(1)
.build();

// "Jade" preset
new PresetBuilder()
.setName("Jade")
.setBoxBorderColor(0xff323331)
.setBoxFillColor(0xff20261a)
.setBoxThickness(1)
.setBoxOffset(1)
.build();

// "Fully transparent" preset
new PresetBuilder()
.setName("Fully transparent")
.setBoxBorderColor(0x00000000)
.setBoxFillColor(0x00000000)
.setBoxThickness(0)
.setBoxOffset(0)
.build();

// "Black & White" preset
new PresetBuilder()
.setName("Black & White")
.setBoxBorderColor(0xffffffff)
.setBoxFillColor(0xff000000)
.setBoxThickness(2)
.setBoxOffset(0)
.addTextStyleClass(TextStyleClass.MODNAME, "white,italic")
.addTextStyleClass(TextStyleClass.NAME, "white,bold")
.addTextStyleClass(TextStyleClass.INFO, "white")
.addTextStyleClass(TextStyleClass.INFOIMP, "white,bold")
.addTextStyleClass(TextStyleClass.WARNING, "white")
.addTextStyleClass(TextStyleClass.ERROR, "white,underline")
.addTextStyleClass(TextStyleClass.OBSOLETE, "white,strikethrough")
.addTextStyleClass(TextStyleClass.LABEL, "white,bold")
.addTextStyleClass(TextStyleClass.OK, "white")
.addTextStyleClass(TextStyleClass.PROGRESS, "white")
.build();

// "Crazy!" preset
new PresetBuilder()
.setName("Crazy!")
.setBoxBorderColor(0xff00ff00)
.setBoxFillColor(0x55ff0000)
.setBoxThickness(2)
.setBoxOffset(0)
.addTextStyleClass(TextStyleClass.MODNAME, "green")
.addTextStyleClass(TextStyleClass.NAME, "yellow,bold")
.addTextStyleClass(TextStyleClass.INFO, "cyan,bold")
.addTextStyleClass(TextStyleClass.INFOIMP, "magenta,bold")
.addTextStyleClass(TextStyleClass.WARNING, "orange,bold")
.addTextStyleClass(TextStyleClass.ERROR, "red,bold")
.addTextStyleClass(TextStyleClass.OBSOLETE, "gray,bold")
.addTextStyleClass(TextStyleClass.LABEL, "blue,bold")
.addTextStyleClass(TextStyleClass.OK, "green,bold")
.addTextStyleClass(TextStyleClass.PROGRESS, "white,bold")
.build();

// "Soft Pastels" preset
new PresetBuilder()
.setName("Soft Pastels")
.setBoxBorderColor(0xffe0bbff)
.setBoxFillColor(0x00000000)
.setBoxThickness(1)
.setBoxOffset(1)
.addTextStyleClass(TextStyleClass.MODNAME, "pink,bold,italic")
.build();

// "Ocean Blue" preset
new PresetBuilder()
.setName("Ocean Blue")
.setBoxBorderColor(0xff003366)
.setBoxFillColor(0x556699cc)
.setBoxThickness(2)
.setBoxOffset(0)
.addTextStyleClass(TextStyleClass.MODNAME, "cyan")
.addTextStyleClass(TextStyleClass.NAME, "light_blue,bold")
.addTextStyleClass(TextStyleClass.INFO, "white")
.addTextStyleClass(TextStyleClass.INFOIMP, "white,bold")
.addTextStyleClass(TextStyleClass.WARNING, "yellow,bold")
.addTextStyleClass(TextStyleClass.ERROR, "red,bold")
.addTextStyleClass(TextStyleClass.OBSOLETE, "gray,bold,italic")
.addTextStyleClass(TextStyleClass.LABEL, "aqua,bold")
.addTextStyleClass(TextStyleClass.OK, "green,bold")
.addTextStyleClass(TextStyleClass.PROGRESS, "white,bold")
.build();
}


Expand Down Expand Up @@ -131,7 +186,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
hitboxes = new ArrayList<>();
RenderHelper.renderText(Minecraft.getMinecraft(), x, y, TextFormatting.GOLD + I18n.format("gui.theoneprobe.gui_note_config.title.presets"));
y += 12;
for (Preset preset : presets) {
for (Preset preset : PresetBuilder.getPresets()) {
y = addPreset(x, y, preset);
}

Expand Down
95 changes: 95 additions & 0 deletions src/main/java/mcjty/theoneprobe/gui/PresetBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package mcjty.theoneprobe.gui;

import mcjty.theoneprobe.api.TextStyleClass;
import org.apache.commons.lang3.tuple.Pair;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
* The Builder to make a new prest, basically for GroovyScript compact
*
* @since 10/15/2024
* @author strubium
*/
public class PresetBuilder {

private static final List<Preset> presets = new ArrayList<>();

private String name;
private int boxBorderColor = 0xFFFFFF; // default value
private int boxFillColor = 0x000000; // default value
private int boxThickness = 1; // default value
private int boxOffset = 0; // default value
private final Map<TextStyleClass, String> textStyleClasses = new HashMap<>();

public PresetBuilder() {}

/**
* Set the Name of the preset, can be a translation key
*/
public PresetBuilder setName(String name) {
this.name = name;
return this;
}

public PresetBuilder setBoxBorderColor(int color) {
this.boxBorderColor = color;
return this;
}

public PresetBuilder setBoxFillColor(int color) {
this.boxFillColor = color;
return this;
}

public PresetBuilder setBoxThickness(int thickness) {
this.boxThickness = thickness;
return this;
}

public PresetBuilder setBoxOffset(int offset) {
this.boxOffset = offset;
return this;
}

public PresetBuilder addTextStyleClass(TextStyleClass styleClass, String styleName) {
this.textStyleClasses.put(styleClass, styleName);
return this;
}

// Build method to construct the Preset object and add it to the static presets list
public Preset build() {
// Convert the Map entries to an array of Pair<TextStyleClass, String>
List<Pair<TextStyleClass, String>> stylePairs = textStyleClasses.entrySet()
.stream()
.map(entry -> Pair.of(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());

// Create the new Preset object
Preset preset = new Preset(
name,
boxBorderColor,
boxFillColor,
boxThickness,
boxOffset,
stylePairs.toArray(new Pair[0])
);

// Add the newly created preset to the static list
presets.add(preset);

return preset;
}

/**
* Get the ArrayList containing all the presets
*/
public static List<Preset> getPresets() {
return presets;
}
}
3 changes: 3 additions & 0 deletions src/main/java/mcjty/theoneprobe/items/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ private static boolean isProbeHelmet(ItemStack stack) {
if (stack.isEmpty()) {
return false;
}
if (stack.getItem() == diamondHelmetProbe || stack.getItem() == goldHelmetProbe || stack.getItem() == ironHelmetProbe) {
return true;
}
if (stack.getTagCompound() == null) {
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/mcjty/theoneprobe/probe/ProbeBase.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package mcjty.theoneprobe.probe;

import mcjty.theoneprobe.TheOneProbe;
import mcjty.theoneprobe.items.ModItems;
import mcjty.theoneprobe.setup.GuiProxy;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
Expand Down
Loading

0 comments on commit d413dcb

Please sign in to comment.