Skip to content

Commit

Permalink
Added RemapPrefixForJS annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed May 14, 2022
1 parent 4a219fa commit 7ee9dda
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 95 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ public abstract class DirectionMixin {
@RemapForJS("getZ")
public abstract int getStepZ();

@Shadow
@RemapForJS("getOpposite")
public abstract Direction getOpposite();

@Shadow
@RemapForJS("getIndex")
public abstract int get3DDataValue();
Expand All @@ -39,12 +35,4 @@ public float getPitch() {
Object o = this;
return o == Direction.UP ? 180F : o == Direction.DOWN ? 0F : 90F;
}

@Shadow
@RemapForJS("getClockWise")
public abstract Direction getClockWise();

@Shadow
@RemapForJS("getCounterClockWise")
public abstract Direction getCounterClockWise();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.latvian.mods.rhino.mod.core.mixin.common;

import dev.latvian.mods.rhino.util.RemapForJS;
import dev.latvian.mods.rhino.util.RemapPrefixForJS;
import dev.latvian.mods.rhino.util.SpecialEquality;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -11,19 +11,18 @@
/**
* @author LatvianModder
*/
@RemapPrefixForJS("rhino$")
@Mixin(value = ResourceKey.class, priority = 1001)
public abstract class ResourceKeyMixin implements SpecialEquality {
@Shadow
@Final
private ResourceLocation location;

@RemapForJS("getNamespace")
public String rhino_getNamespace() {
public String rhino$getNamespace() {
return location.getNamespace();
}

@RemapForJS("getPath")
public String rhino_getPath() {
public String rhino$getPath() {
return location.getPath();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
package dev.latvian.mods.rhino.mod.core.mixin.common;

import dev.latvian.mods.rhino.util.RemapForJS;
import dev.latvian.mods.rhino.util.SpecialEquality;
import net.minecraft.resources.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(value = ResourceLocation.class, priority = 1001)
public abstract class ResourceLocationMixin implements SpecialEquality {
@Shadow
@RemapForJS("getNamespace")
public abstract String getNamespace();

@Shadow
@RemapForJS("getPath")
public abstract String getPath();

@Override
public boolean specialEquals(Object o, boolean shallow) {
return equals(o instanceof ResourceLocation ? o : toString().equals(String.valueOf(o)));
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public String remapField(Class<?> from, Field field, String fieldName) {
return remap.value();
}

for (RemapPrefixForJS prefix : from.getAnnotationsByType(RemapPrefixForJS.class)) {
String p = prefix.value();

if (fieldName.length() > p.length() && fieldName.startsWith(p)) {
return fieldName.substring(p.length());
}
}

return "";
}

Expand All @@ -38,6 +46,16 @@ public String remapMethod(Class<?> from, Method method, String methodString) {
return remap.value();
}

String methodName = method.getName();

for (RemapPrefixForJS prefix : from.getAnnotationsByType(RemapPrefixForJS.class)) {
String p = prefix.value();

if (methodName.length() > p.length() && methodName.startsWith(p)) {
return methodName.substring(p.length());
}
}

return "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.latvian.mods.rhino.util;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Allows you to change field or method name on class scale with prefix
*
* @author LatvianModder
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Repeatable(RemapPrefixForJSRep.class)
public @interface RemapPrefixForJS {
String value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dev.latvian.mods.rhino.util;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Allows you to change field or method name on class scale with prefix
*
* @author LatvianModder
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface RemapPrefixForJSRep {
RemapPrefixForJS[] value();
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package dev.latvian.mods.rhino.test;

import dev.latvian.mods.rhino.Context;
import dev.latvian.mods.rhino.util.RemapPrefixForJS;
import dev.latvian.mods.unit.UnitContext;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RemapPrefixForJS("test1$")
@RemapPrefixForJS("test2$")
public class TestConsole {
private static ConsoleTheme theme;
public static StringBuilder consoleOutput = new StringBuilder();
Expand Down Expand Up @@ -58,12 +61,12 @@ public static List<String> getTestList() {
return new ArrayList<>(Arrays.asList(getTestArray()));
}

public static void setTheme(ConsoleTheme t) {
public static void test1$setTheme(ConsoleTheme t) {
info("Set theme to " + t);
theme = t;
}

public static ConsoleTheme getTheme() {
public static ConsoleTheme test2$getTheme() {
return theme;
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.daemon=false
mod_id=rhino
archives_base_name=rhino
maven_group=dev.latvian.mods
mod_version=1802.1.10
mod_version=1802.1.11
mod_author=LatvianModder
curseforge_id=416294
curseforge_type=release
Expand Down

0 comments on commit 7ee9dda

Please sign in to comment.