Skip to content

Commit

Permalink
some reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
brachy84 committed May 8, 2024
1 parent 3a70f39 commit 6ea6614
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Collection<INamed> getRegistries() {
}

@UnmodifiableView
public Map<String, ?> getProperties() {
public Map<String, INamed> getProperties() {
return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,11 @@ public static void init() {
if (container.isLoaded()) {
container.onCompatLoaded(container);
container.get().initialize(container);
int i = 0;
ExpansionHelper.mixinConstProperty(ModSupport.class, container.getModId(), container.get(), false);
for (String s : container.getAliases()) {
ExpansionHelper.mixinConstProperty(ModSupport.class, s, container.get(), i++ > 0);
if (!container.getModId().equals(s)) {
ExpansionHelper.mixinConstProperty(ModSupport.class, s, container.get(), true);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ public Builder<T> documentation(String doc) {
}

public Builder<T> docOfType(String type) {
String mod = this.mod == null ? StringUtils.EMPTY : this.mod.getContainerName();
return documentation("returns a " + mod + " " + type);
String mod = this.mod == null ? StringUtils.EMPTY : this.mod.getContainerName() + ' ';
return documentation("returns a " + mod + type);
}

public void register() {
Expand All @@ -227,13 +227,6 @@ public void register() {
GameObjectHandler<T> goh = new GameObjectHandler<>(this.name, this.mod, this.handler, this.defaultValue,
this.returnType, this.paramTypes, this.completer, this.documentation);
GameObjectHandlerManager.registerGameObjectHandler(this.mod, goh);
if (this.mod != null) {
Class<?> clazz = this.mod.get().getClass();
for (Class<?>[] paramTypes : goh.paramTypes) {
ExpandoMetaClass emc = ExpansionHelper.getExpandoClass(clazz);
emc.registerInstanceMethod(new GohMetaMethod(goh, paramTypes, clazz, this.documentation));
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import com.cleanroommc.groovyscript.core.mixin.OreDictionaryAccessor;
import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient;
import com.cleanroommc.groovyscript.helper.ingredient.OreDictWildcardIngredient;
import com.cleanroommc.groovyscript.sandbox.expand.ExpansionHelper;
import com.cleanroommc.groovyscript.server.Completions;
import groovy.lang.ExpandoMetaClass;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
Expand Down Expand Up @@ -40,6 +42,13 @@ public class GameObjectHandlerManager {

static void registerGameObjectHandler(GroovyContainer<?> container, GameObjectHandler<?> goh) {
String key = goh.getName();
if (goh.getMod() != null) {
Class<?> clazz = goh.getMod().get().getClass();
for (Class<?>[] paramTypes : goh.getParamTypes()) {
ExpandoMetaClass emc = ExpansionHelper.getExpandoClass(clazz);
emc.registerInstanceMethod(new GohMetaMethod(goh, paramTypes, clazz));
}
}
if (handlerConflicts.containsKey(key)) {
handlerConflicts.get(key).add(goh);
} else if (handlers.containsKey(key)) {
Expand Down Expand Up @@ -91,7 +100,7 @@ public static void init() {
GameObjectHandler.builder("block", Block.class)
.parser(IGameObjectParser.wrapForgeRegistry(ForgeRegistries.BLOCKS))
.completer(ForgeRegistries.BLOCKS)
.docOfType("fluid stack")
.docOfType("block")
.register();
GameObjectHandler.builder("blockstate", IBlockState.class)
.parser(GameObjectHandlers::parseBlockState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ public class GohMetaMethod extends MetaMethod implements IDocumented {

private final GameObjectHandler<?> closure;
private final Class<?> owner;
private final String documentation;

GohMetaMethod(GameObjectHandler<?> closure, Class<?>[] nativeParamTypes, Class<?> owner, String documentation) {
GohMetaMethod(GameObjectHandler<?> closure, Class<?>[] nativeParamTypes, Class<?> owner) {
super(nativeParamTypes);
this.closure = closure;
this.nativeParamTypes = nativeParamTypes;
this.owner = owner;
this.documentation = documentation;
}

@Override
Expand Down Expand Up @@ -49,6 +47,6 @@ public Object invoke(Object object, Object[] arguments) {

@Override
public String getDocumentation() {
return documentation;
return this.closure.getDocumentation();
}
}

0 comments on commit 6ea6614

Please sign in to comment.