Skip to content

Commit

Permalink
Added MineTweaker support to the Glyph system
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoxkk0 committed Mar 31, 2024
1 parent d433825 commit 3e8a2de
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ modName = NecroTempus

# This is a case-sensitive string to identify your mod. Convention is to use lower case.
modId = necrotempus
modVersion = 1.3
modVersion = 1.3.1
modGroup = io.github.cruciblemc.necrotempus

# WHY is there no version field?
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ public static CustomGlyphs getCandidate(char key) {
return GLYPHS_REGISTRY.get(key);
}

public static void register(CustomGlyphs customGlyphs){
GLYPHS_REGISTRY.put(customGlyphs.getTarget(), customGlyphs);
}

public static void unregister(CustomGlyphs customGlyphs){
GLYPHS_REGISTRY.remove(customGlyphs.getTarget());
}

public static void unregister(Character character){
GLYPHS_REGISTRY.remove(character);
}

@Override
public void onResourceManagerReload(IResourceManager resourceManager) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package io.github.cruciblemc.necrotempus.modules.features.glyphs.compat.crafttweaker;

import cpw.mods.fml.common.FMLCommonHandler;
import io.github.cruciblemc.necrotempus.Tags;
import io.github.cruciblemc.necrotempus.modules.features.glyphs.CustomGlyphs;
import io.github.cruciblemc.necrotempus.modules.features.glyphs.GlyphsRegistry;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import minetweaker.annotations.ModOnly;
import net.minecraft.util.ResourceLocation;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;

import static io.github.cruciblemc.necrotempus.modules.features.glyphs.CustomGlyphs.FitMode.NONE;

@ZenClass(value = "necrotempus.crafttweaker.Glyph")
@ModOnly(Tags.MODID)
public class Glyphs {

@ZenMethod
public static void register(String target, String resource, int horizontalPadding, int verticalPadding, int width, int height) {
MineTweakerAPI.apply(new GlyphCustomizeAddAction(target.charAt(0), new ResourceLocation(resource), horizontalPadding, verticalPadding, width, height));
}

@ZenMethod
public static void register(String target, String resource, int horizontalPadding, int verticalPadding, int width, int height, String fitMode) {
MineTweakerAPI.apply(new GlyphCustomizeAddAction(target.charAt(0), new ResourceLocation(resource), horizontalPadding, verticalPadding, width, height, fitMode, -1));
}

@ZenMethod
public static void register(String target, String resource, int horizontalPadding, int verticalPadding, int width, int height, String fitMode, int charWidth) {
MineTweakerAPI.apply(new GlyphCustomizeAddAction(target.charAt(0), new ResourceLocation(resource), horizontalPadding, verticalPadding, width, height, fitMode, charWidth));
}

@ZenMethod
public static void unregister(String target) {
MineTweakerAPI.apply(new GlyphCustomizeRemoveAction(target.charAt(0)));
}

public static class GlyphCustomizeRemoveAction implements IUndoableAction {

private final Character target;
private CustomGlyphs customGlyphs;

public GlyphCustomizeRemoveAction(Character target) {
this.target = target;
}

@Override
public void apply() {
if (FMLCommonHandler.instance().getSide().isClient()) {

customGlyphs = GlyphsRegistry.getCandidate(target);

if (customGlyphs != null)
GlyphsRegistry.unregister(customGlyphs);
}
}

@Override
public boolean canUndo() {
return FMLCommonHandler.instance().getSide().isClient() && customGlyphs != null;
}

@Override
public void undo() {
if (FMLCommonHandler.instance().getSide().isClient()) {
GlyphsRegistry.register(customGlyphs);
}
}

@Override
public String describe() {
return String.format("Removing Custom Glyph for character %s.", target);
}

@Override
public String describeUndo() {
return String.format(
"Registering Custom Glyph for character %s. (Width: %d, Height: %d, HPadding: %d, VPadding: %d, FitMode: %s, CharWidth: %d)",
customGlyphs.getTarget(),
customGlyphs.getWidth(),
customGlyphs.getHeight(),
customGlyphs.getHorizontalPadding(),
customGlyphs.getVerticalPadding(),
customGlyphs.getFitMode(),
customGlyphs.getCharWidth()
);
}

@Override
public Object getOverrideKey() {
return null;
}

}

public static class GlyphCustomizeAddAction implements IUndoableAction {

private final char target;
private final ResourceLocation resource;
private final int horizontalPadding;
private final int verticalPadding;
private final int width;
private final int height;
private CustomGlyphs.FitMode fitMode = NONE;
private int charWidth = -1;


public GlyphCustomizeAddAction(char target, ResourceLocation resource, int horizontalPadding, int verticalPadding, int width, int height) {
this.target = target;
this.resource = resource;
this.horizontalPadding = horizontalPadding;
this.verticalPadding = verticalPadding;
this.width = width;
this.height = height;
}

public GlyphCustomizeAddAction(char target, ResourceLocation resource, int horizontalPadding, int verticalPadding, int width, int height, String fitMode, int charWidth) {
this.target = target;
this.resource = resource;
this.horizontalPadding = horizontalPadding;
this.verticalPadding = verticalPadding;
this.width = width;
this.height = height;
this.charWidth = charWidth;
this.fitMode = CustomGlyphs.FitMode.parse(fitMode);
}

@Override
public boolean canUndo() {
return true;
}

@Override
public void apply() {
if (FMLCommonHandler.instance().getSide().isClient()) {

CustomGlyphs customGlyphs = new CustomGlyphs(target, resource, horizontalPadding, verticalPadding, width, height);

customGlyphs.setFitMode(fitMode);
customGlyphs.setCharWidth(charWidth);

GlyphsRegistry.register(customGlyphs);

}
}

@Override
public void undo() {
if (FMLCommonHandler.instance().getSide().isClient()) {
GlyphsRegistry.unregister(target);
}
}

@Override
public String describe() {
return String.format("Registering Custom Glyph for character %s. (Width: %d, Height: %d, HPadding: %d, VPadding: %d, FitMode: %s, CharWidth: %d)", target, width, height, horizontalPadding, verticalPadding, fitMode, charWidth);
}

@Override
public String describeUndo() {
return String.format("Removing Custom Glyph for character %s. (Width: %d, Height: %d, HPadding: %d, VPadding: %d, FitMode: %s, CharWidth: %d)", target, width, height, horizontalPadding, verticalPadding, fitMode, charWidth);
}

@Override
public Object getOverrideKey() {
return null;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import io.github.cruciblemc.necrotempus.NecroTempus;
import io.github.cruciblemc.necrotempus.modules.features.bossbar.compat.crafttweaker.ZenRegister;
import io.github.cruciblemc.necrotempus.modules.features.bossbar.compat.crafttweaker.BossBar;
import io.github.cruciblemc.necrotempus.modules.features.glyphs.compat.crafttweaker.Glyphs;
import minetweaker.MineTweakerAPI;

import java.util.Arrays;

public abstract class CommonProxy {

Expand All @@ -14,7 +18,7 @@ public void preInit(FMLPreInitializationEvent event) {

public void init(FMLInitializationEvent event) {
try {
ZenRegister.register();
Arrays.asList(BossBar.class, Glyphs.class).forEach(MineTweakerAPI::registerClass);
} catch (NoClassDefFoundError e) {
NecroTempus.getInstance().getLogger().warn("CraftTweaker is not available.");
}
Expand Down

0 comments on commit 3e8a2de

Please sign in to comment.