Skip to content

Commit

Permalink
Collapse metafactories into single classes
Browse files Browse the repository at this point in the history
Signed-off-by: TheSilkMiner <thesilkminer@outlook.com>
  • Loading branch information
TheSilkMiner committed Jun 18, 2022
1 parent 1933cc8 commit 154cd19
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.blamejared.contenttweaker.core.api.object.ObjectType;
import com.blamejared.contenttweaker.core.api.zen.object.Reference;
import com.blamejared.contenttweaker.core.zen.rt.ReferenceMetaFactory;
import com.blamejared.contenttweaker.core.zen.rt.CoreMetaFactory;
import com.blamejared.crafttweaker.api.CraftTweakerAPI;
import com.blamejared.crafttweaker.api.util.ParseUtil;
import com.blamejared.crafttweaker.api.zencode.IScriptLoader;
Expand Down Expand Up @@ -54,7 +54,7 @@ private static <R> TypeToken<R> checkToken(final TypeToken<R> token) {

@Override
public IPartialExpression compile(final ExpressionScope scope) throws CompileException {
final ParsedExpression metaFactory = ParseUtil.staticMemberExpression(this.position, ReferenceMetaFactory.ZEN_NAME);
final ParsedExpression metaFactory = ParseUtil.staticMemberExpression(this.position, CoreMetaFactory.ZEN_NAME);
final ParsedExpression of = new ParsedExpressionMember(this.position, metaFactory, "reference", null);
final ParsedCallArguments arguments = new ParsedCallArguments(this.generics(), this.arguments());
final ParsedExpression invocation = new ParsedExpressionCall(this.position, of, arguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.blamejared.contenttweaker.core.ContentTweakerCore;
import com.blamejared.contenttweaker.core.api.object.ObjectType;
import com.blamejared.contenttweaker.core.api.zen.bracket.BracketHelper;
import com.blamejared.contenttweaker.core.zen.rt.FactoryMetaFactory;
import com.blamejared.contenttweaker.core.zen.rt.CoreMetaFactory;
import com.blamejared.crafttweaker.api.CraftTweakerAPI;
import com.blamejared.crafttweaker.api.util.ParseUtil;
import com.blamejared.crafttweaker.api.zencode.IScriptLoader;
Expand Down Expand Up @@ -38,7 +38,7 @@ public BracketMetaFactoryExpression(final CodePosition position, final ObjectTyp

@Override
public IPartialExpression compile(final ExpressionScope scope) throws CompileException {
final ParsedExpression runtimeClass = ParseUtil.staticMemberExpression(this.position, FactoryMetaFactory.ZEN_NAME);
final ParsedExpression runtimeClass = ParseUtil.staticMemberExpression(this.position, CoreMetaFactory.ZEN_NAME);
final ParsedExpression factoryMethod = new ParsedExpressionMember(this.position, runtimeClass, "factory", null);
final ParsedCallArguments arguments = this.makeCall();
final ParsedExpression invocation = new ParsedExpressionCall(this.position, factoryMethod, arguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
import com.blamejared.contenttweaker.core.api.object.ObjectFactory;
import com.blamejared.contenttweaker.core.api.object.ObjectFactoryMapping;
import com.blamejared.contenttweaker.core.api.object.ObjectType;
import com.blamejared.contenttweaker.core.registry.MetaRegistry;
import com.blamejared.contenttweaker.core.api.object.ReferenceFactory;
import com.blamejared.contenttweaker.core.api.zen.ContentTweakerZenConstants;
import com.blamejared.contenttweaker.core.api.zen.object.Reference;
import com.blamejared.contenttweaker.core.registry.MetaRegistry;
import com.blamejared.crafttweaker.api.annotation.ZenRegister;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import org.openzen.zencode.java.ZenCodeType;

@ZenCodeType.Name(FactoryMetaFactory.ZEN_NAME)
@ZenCodeType.Name(CoreMetaFactory.ZEN_NAME)
@ZenRegister(loaders = ContentTweakerConstants.CONTENT_LOADER_ID)
public final class FactoryMetaFactory {
public static final String ZEN_NAME = ContentTweakerZenConstants.RT_PACKAGE + ".FactoryMetaFactory";
public final class CoreMetaFactory {
public static final String ZEN_NAME = ContentTweakerZenConstants.RT_PACKAGE + ".MetaFactory";

private FactoryMetaFactory() {}
private CoreMetaFactory() {}

@SuppressWarnings("unused") // Reified types need to exist, but we do not use them
@ZenCodeType.Method("factory")
Expand All @@ -29,4 +31,14 @@ public static <T, U extends ObjectFactory<T>> U factory(final Class<T> reifiedT,
final ObjectFactoryMapping<T, U> factoryClass = metaRegistry.factoryMappings().findMappingFor(type);
return factoryClass.of();
}

@SuppressWarnings("unused") // Reified types
@ZenCodeType.Method("reference")
public static <T, U extends Reference<T>> U reference(final Class<T> reifiedT, final Class<U> reifiedU, final ResourceLocation registryId, final ResourceLocation id) {
final MetaRegistry metaRegistry = ContentTweakerCore.core().metaRegistry();
final ResourceKey<? extends Registry<T>> key = ResourceKey.createRegistryKey(registryId);
final ObjectType<T> type = metaRegistry.objectTypes().get(key);
final ReferenceFactory<T, U> factory = metaRegistry.referenceFactories().findFactoryFor(type);
return factory.of(type, id);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.blamejared.contenttweaker.core.api.ContentTweakerConstants;
import com.blamejared.contenttweaker.core.api.object.ObjectHolder;
import com.blamejared.contenttweaker.core.api.resource.ResourceManager;
import com.blamejared.contenttweaker.core.zen.rt.FactoryMetaFactory;
import com.blamejared.contenttweaker.core.zen.rt.CoreMetaFactory;
import com.blamejared.contenttweaker.vanilla.api.resource.LootTable;
import com.blamejared.contenttweaker.vanilla.api.zen.ContentTweakerVanillaConstants;
import com.blamejared.contenttweaker.vanilla.api.zen.builder.item.BlockItemBuilder;
Expand Down Expand Up @@ -479,7 +479,7 @@ private BlockBehaviour.Properties make(

private void makeBlockItem(final BlockReference reference) {
// TODO("This references non-api: fix")
FactoryMetaFactory.factory(Item.class, ItemFactory.class, new ResourceLocation("item"))
CoreMetaFactory.factory(Item.class, ItemFactory.class, new ResourceLocation("item"))
.typed(BlockItemBuilder.class)
.block(reference)
.tab(this.tab)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.blamejared.contenttweaker.vanilla.api.zen.util.SoundTypeReference;
import com.blamejared.contenttweaker.vanilla.mixin.BlockBehaviorAccessor;
import com.blamejared.contenttweaker.vanilla.mixin.BlockBehaviorPropertiesAccessor;
import com.blamejared.contenttweaker.vanilla.zen.rt.MaterialColorMetaFactory;
import com.blamejared.contenttweaker.vanilla.zen.rt.VanillaMetaFactory;
import com.blamejared.crafttweaker.api.annotation.ZenRegister;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.SoundType;
Expand All @@ -29,7 +29,7 @@ public MaterialReference material() {
}

public BlockPropertyFunctions.MaterialColorFinder materialColor() {
return this.resolveProperties().contenttweaker$materialColor().andThen(it -> MaterialColorMetaFactory.factory(it.id, it.col))::apply;
return this.resolveProperties().contenttweaker$materialColor().andThen(it -> VanillaMetaFactory.materialColor(it.id, it.col))::apply;
}

public boolean hasCollision() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.blamejared.contenttweaker.vanilla.zen.bracket;

import com.blamejared.contenttweaker.vanilla.mixin.CreativeModeTabAccessor;
import com.blamejared.contenttweaker.vanilla.zen.rt.TabMetaFactory;
import com.blamejared.contenttweaker.vanilla.zen.rt.VanillaMetaFactory;
import com.blamejared.crafttweaker.api.util.ParseUtil;
import com.google.common.base.CaseFormat;
import net.minecraft.world.item.CreativeModeTab;
Expand Down Expand Up @@ -33,8 +33,8 @@ private static final class InvokeTabMetaFactoryExpression extends ParsedExpressi

@Override
public IPartialExpression compile(final ExpressionScope scope) throws CompileException {
final ParsedExpression runtimeClass = ParseUtil.staticMemberExpression(this.position, TabMetaFactory.ZEN_NAME);
final ParsedExpression factoryMethod = new ParsedExpressionMember(this.position, runtimeClass, "factory", null);
final ParsedExpression runtimeClass = ParseUtil.staticMemberExpression(this.position, VanillaMetaFactory.ZEN_NAME);
final ParsedExpression factoryMethod = new ParsedExpressionMember(this.position, runtimeClass, "tab", null);
final ParsedExpression name = new ParsedExpressionString(this.position, this.name, false);
final ParsedCallArguments arguments = new ParsedCallArguments(Collections.emptyList(), Collections.singletonList(name));
final ParsedExpression invocation = new ParsedExpressionCall(this.position, factoryMethod, arguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.blamejared.contenttweaker.core.api.zen.bracket.BracketHelper;
import com.blamejared.contenttweaker.vanilla.api.util.MaterialRegistry;
import com.blamejared.contenttweaker.vanilla.zen.rt.MaterialMetaFactory;
import com.blamejared.contenttweaker.vanilla.zen.rt.VanillaMetaFactory;
import com.blamejared.crafttweaker.api.util.ParseUtil;
import net.minecraft.resources.ResourceLocation;
import org.openzen.zencode.shared.CodePosition;
Expand Down Expand Up @@ -32,8 +32,8 @@ private static final class MaterialMetaFactoryExpression extends ParsedExpressio

@Override
public IPartialExpression compile(final ExpressionScope scope) throws CompileException {
final ParsedExpression runtimeClass = ParseUtil.staticMemberExpression(this.position, MaterialMetaFactory.ZEN_NAME);
final ParsedExpression factoryMethod = new ParsedExpressionMember(this.position, runtimeClass, "factory", null);
final ParsedExpression runtimeClass = ParseUtil.staticMemberExpression(this.position, VanillaMetaFactory.ZEN_NAME);
final ParsedExpression factoryMethod = new ParsedExpressionMember(this.position, runtimeClass, "material", null);
final ParsedExpression id = BracketHelper.locationArgument(this.position, this.id);
final ParsedCallArguments arguments = new ParsedCallArguments(Collections.emptyList(), Collections.singletonList(id));
final ParsedExpression invocation = new ParsedExpressionCall(this.position, factoryMethod, arguments);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.blamejared.contenttweaker.vanilla.zen.bracket;

import com.blamejared.contenttweaker.vanilla.zen.rt.MaterialColorMetaFactory;
import com.blamejared.contenttweaker.vanilla.zen.rt.VanillaMetaFactory;
import com.blamejared.crafttweaker.api.util.ParseUtil;
import com.google.common.base.Suppliers;
import it.unimi.dsi.fastutil.objects.Object2IntArrayMap;
Expand Down Expand Up @@ -35,8 +35,8 @@ private static final class MaterialColorMetaFactoryExpression extends ParsedExpr

@Override
public IPartialExpression compile(final ExpressionScope scope) throws CompileException {
final ParsedExpression runtimeClass = ParseUtil.staticMemberExpression(this.position, MaterialColorMetaFactory.ZEN_NAME);
final ParsedExpression factoryMethod = new ParsedExpressionMember(this.position, runtimeClass, "factory", null);
final ParsedExpression runtimeClass = ParseUtil.staticMemberExpression(this.position, VanillaMetaFactory.ZEN_NAME);
final ParsedExpression factoryMethod = new ParsedExpressionMember(this.position, runtimeClass, "materialColor", null);
final ParsedExpression id = new ParsedExpressionInt(this.position, Integer.toString((this.data >> 24) & 0xFF));
final ParsedExpression color = new ParsedExpressionInt(this.position, Integer.toString(this.data & 0xFFFFFF));
final ParsedCallArguments arguments = new ParsedCallArguments(Collections.emptyList(), Arrays.asList(id, color));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.blamejared.contenttweaker.core.api.zen.bracket.BracketHelper;
import com.blamejared.contenttweaker.vanilla.api.util.SoundTypeRegistry;
import com.blamejared.contenttweaker.vanilla.zen.rt.SoundTypeMetaFactory;
import com.blamejared.contenttweaker.vanilla.zen.rt.VanillaMetaFactory;
import com.blamejared.crafttweaker.api.util.ParseUtil;
import net.minecraft.resources.ResourceLocation;
import org.openzen.zencode.shared.CodePosition;
Expand Down Expand Up @@ -32,8 +32,8 @@ private static final class SoundTypeMetaFactoryExpression extends ParsedExpressi

@Override
public IPartialExpression compile(final ExpressionScope scope) throws CompileException {
final ParsedExpression runtimeClass = ParseUtil.staticMemberExpression(this.position, SoundTypeMetaFactory.ZEN_NAME);
final ParsedExpression factoryMethod = new ParsedExpressionMember(this.position, runtimeClass, "factory", null);
final ParsedExpression runtimeClass = ParseUtil.staticMemberExpression(this.position, VanillaMetaFactory.ZEN_NAME);
final ParsedExpression factoryMethod = new ParsedExpressionMember(this.position, runtimeClass, "soundType", null);
final ParsedExpression id = BracketHelper.locationArgument(position, this.id);
final ParsedCallArguments arguments = new ParsedCallArguments(Collections.emptyList(), Collections.singletonList(id));
final ParsedExpression invocation = new ParsedExpressionCall(this.position, factoryMethod, arguments);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 154cd19

Please sign in to comment.