From 959672dae359435880b9d3672cc548fc38549435 Mon Sep 17 00:00:00 2001 From: fscan Date: Wed, 22 Nov 2017 21:09:26 +0100 Subject: [PATCH] Add CraftTweaker support (#3231) --- README.md | 52 +++++++ gradle/scripts/dependencies.gradle | 6 + src/main/java/appeng/core/AppEng.java | 2 + .../integration/IntegrationRegistry.java | 5 +- .../appeng/integration/IntegrationType.java | 12 +- .../abstraction/ICraftTweaker.java | 28 ++++ .../crafttweaker/AttunementRegistry.java | 132 +++++++++++++++++ .../modules/crafttweaker/CTModule.java | 130 +++++++++++++++++ .../modules/crafttweaker/CannonRegistry.java | 43 ++++++ .../modules/crafttweaker/GrinderRecipes.java | 127 ++++++++++++++++ .../crafttweaker/InscriberRecipes.java | 138 ++++++++++++++++++ .../modules/crafttweaker/SpatialRegistry.java | 61 ++++++++ 12 files changed, 734 insertions(+), 2 deletions(-) create mode 100644 src/main/java/appeng/integration/abstraction/ICraftTweaker.java create mode 100644 src/main/java/appeng/integration/modules/crafttweaker/AttunementRegistry.java create mode 100644 src/main/java/appeng/integration/modules/crafttweaker/CTModule.java create mode 100644 src/main/java/appeng/integration/modules/crafttweaker/CannonRegistry.java create mode 100644 src/main/java/appeng/integration/modules/crafttweaker/GrinderRecipes.java create mode 100644 src/main/java/appeng/integration/modules/crafttweaker/InscriberRecipes.java create mode 100644 src/main/java/appeng/integration/modules/crafttweaker/SpatialRegistry.java diff --git a/README.md b/README.md index 45cbe3f8..b676a233 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ * [Building](#building) * [Contribution](#contribution) * [API](#applied-energistics-2-api) +* [CraftTweaker](#applied-energistics-2-crafttweaker) * [Localization](#applied-energistics-2-localization) * [Credits](#credits) @@ -154,6 +155,57 @@ Where the __ are filled in with the correct version criteria; AE2 is available f An example string would be `appeng:appliedenergistics2:rv2-alpha-30:dev` +## Applied Energistics 2 CraftTweaker + +### Inscriber +Add a recipe. When `inscribe` is true the bottom and top inputs are not consumed. + + mods.appliedenergistics2.Inscriber.addRecipe(ItemStack output, ItemStack input, boolean inscribe, + @Optional ItemStack topInput, @Optional ItemStack bottomInput ); + +Remove all recipes for this output stack. + + mods.appliedenergistics2.Inscriber.removeRecipe(ItemStack output); + +### Grindstone +Add a recipe. + + mods.appliedenergistics2.Grinder.addRecipe( ItemStack output, ItemStack input, int turns, + @Optional ItemStack secondary1Output, @Optional float secondary1Chance, + @Optional ItemStack secondary2Output, @Optional float secondary2Chance); + +Remove recipes for this input. + + mods.appliedenergistics2.Grinder.removeRecipe(ItemStack input); + +### Spatial +Whitelist a TileEntity class for Spatial IO. + + mods.appliedenergistics2.Spatial.whitelistEntity( String fullEntityClassName ); + +### Attunement +Attune a ItemStack or ModID to a specific P2P-Tunnel type. ModID's are used as fallback when no ItemStack was found. + + mods.appliedenergistics2.Attunement.attuneME( ItemStack itemStack ); + mods.appliedenergistics2.Attunement.attuneME( String modID ); + mods.appliedenergistics2.Attunement.attuneItem( ItemStack itemStack ); + mods.appliedenergistics2.Attunement.attuneItem( String modID ); + mods.appliedenergistics2.Attunement.attuneFluid( ItemStack itemStack ); + mods.appliedenergistics2.Attunement.attuneFluid( String modID ); + mods.appliedenergistics2.Attunement.attuneRedstone( ItemStack itemStack ); + mods.appliedenergistics2.Attunement.attuneRedstone( String modID ); + mods.appliedenergistics2.Attunement.attuneRF( ItemStack itemStack ); + mods.appliedenergistics2.Attunement.attuneRF( String modID ); + mods.appliedenergistics2.Attunement.attuneIC2( ItemStack itemStack ); + mods.appliedenergistics2.Attunement.attuneIC2( String modID ); + mods.appliedenergistics2.Attunement.attuneLight( ItemStack itemStack ); + mods.appliedenergistics2.Attunement.attuneLight( String modID ); + +### Cannon +Add ammo types for the matter cannon. + + mods.appliedenergistics2.Cannon.registerAmmo( ItemStack itemStack, double weight ); + ## Applied Energistics 2 Localization ### English Text diff --git a/gradle/scripts/dependencies.gradle b/gradle/scripts/dependencies.gradle index a9b7708b..b4aeae56 100644 --- a/gradle/scripts/dependencies.gradle +++ b/gradle/scripts/dependencies.gradle @@ -58,6 +58,11 @@ repositories { name 'tehnut' url "http://tehnut.info/maven" } + + maven { // CraftTweaker + name 'jared maven' + url "http://maven.blamejared.com/" + } } configurations { @@ -77,6 +82,7 @@ dependencies { compileOnly "net.industrial-craft:industrialcraft-2:${ic2_version}:api" compileOnly "mcjty.theoneprobe:TheOneProbe-1.12:${top_version}:api" compileOnly "cofh:CoFHCore:${cofhcore_version}:deobf" + compileOnly "CraftTweaker2:CraftTweaker2-API:4.+" // at runtime, use the full JEI jar runtime "mezz.jei:jei_${minecraft_version}:${jei_version}" diff --git a/src/main/java/appeng/core/AppEng.java b/src/main/java/appeng/core/AppEng.java index 69a977b5..a1938a4e 100644 --- a/src/main/java/appeng/core/AppEng.java +++ b/src/main/java/appeng/core/AppEng.java @@ -189,6 +189,8 @@ public final class AppEng AppEng.proxy.preinit(); } + IntegrationRegistry.INSTANCE.preInit(); + if( versionCheckerConfig.isVersionCheckingEnabled() ) { final VersionChecker versionChecker = new VersionChecker( versionCheckerConfig ); diff --git a/src/main/java/appeng/integration/IntegrationRegistry.java b/src/main/java/appeng/integration/IntegrationRegistry.java index d805e3bf..b1e64c86 100644 --- a/src/main/java/appeng/integration/IntegrationRegistry.java +++ b/src/main/java/appeng/integration/IntegrationRegistry.java @@ -47,13 +47,16 @@ public enum IntegrationRegistry this.modules.add( new IntegrationNode( type.dspName, type.modID, type ) ); } - public void init() + public void preInit() { for( final IntegrationNode node : this.modules ) { node.call( IntegrationStage.PRE_INIT ); } + } + public void init() + { for( final IntegrationNode node : this.modules ) { node.call( IntegrationStage.INIT ); diff --git a/src/main/java/appeng/integration/IntegrationType.java b/src/main/java/appeng/integration/IntegrationType.java index 61ba97ab..3c804114 100644 --- a/src/main/java/appeng/integration/IntegrationType.java +++ b/src/main/java/appeng/integration/IntegrationType.java @@ -19,6 +19,7 @@ package appeng.integration; +import appeng.integration.modules.crafttweaker.CTModule; import appeng.integration.modules.ic2.IC2Module; import appeng.integration.modules.jei.JEIModule; import appeng.integration.modules.theoneprobe.TheOneProbeModule; @@ -73,7 +74,16 @@ public enum IntegrationType } }, - TESLA( IntegrationSide.BOTH, "Tesla", "tesla" ); + TESLA( IntegrationSide.BOTH, "Tesla", "tesla" ), + + CRAFTTWEAKER( IntegrationSide.BOTH, "CraftTweaker", "crafttweaker" ) + { + @Override + public IIntegrationModule createInstance() + { + return new CTModule(); + } + }; public final IntegrationSide side; public final String dspName; diff --git a/src/main/java/appeng/integration/abstraction/ICraftTweaker.java b/src/main/java/appeng/integration/abstraction/ICraftTweaker.java new file mode 100644 index 00000000..f608607a --- /dev/null +++ b/src/main/java/appeng/integration/abstraction/ICraftTweaker.java @@ -0,0 +1,28 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.abstraction; + + +import appeng.integration.IIntegrationModule; + + +public interface ICraftTweaker extends IIntegrationModule +{ + +} diff --git a/src/main/java/appeng/integration/modules/crafttweaker/AttunementRegistry.java b/src/main/java/appeng/integration/modules/crafttweaker/AttunementRegistry.java new file mode 100644 index 00000000..8bc7f4c6 --- /dev/null +++ b/src/main/java/appeng/integration/modules/crafttweaker/AttunementRegistry.java @@ -0,0 +1,132 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.crafttweaker; + + +import crafttweaker.api.item.IIngredient; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import appeng.api.AEApi; +import appeng.api.config.TunnelType; +import appeng.api.features.IP2PTunnelRegistry; + + +@ZenClass( "mods.appliedenergistics2.Attunement" ) +public class AttunementRegistry +{ + private AttunementRegistry() + { + } + + @ZenMethod + public static void attuneME( IIngredient itemStack ) + { + attune( itemStack, TunnelType.ME ); + } + + @ZenMethod + public static void attuneME( String modId ) + { + attune( modId, TunnelType.ME ); + } + + @ZenMethod + public static void attuneItem( IIngredient itemStack ) + { + attune( itemStack, TunnelType.ITEM ); + } + + @ZenMethod + public static void attuneItem( String modId ) + { + attune( modId, TunnelType.ITEM ); + } + + @ZenMethod + public static void attuneFluid( IIngredient itemStack ) + { + attune( itemStack, TunnelType.FLUID ); + } + + @ZenMethod + public static void attuneFluid( String modId ) + { + attune( modId, TunnelType.FLUID ); + } + + @ZenMethod + public static void attuneRedstone( IIngredient itemStack ) + { + attune( itemStack, TunnelType.REDSTONE ); + } + + @ZenMethod + public static void attuneRedstone( String modId ) + { + attune( modId, TunnelType.REDSTONE ); + } + + @ZenMethod + public static void attuneRF( IIngredient itemStack ) + { + attune( itemStack, TunnelType.FE_POWER ); + } + + @ZenMethod + public static void attuneRF( String modId ) + { + attune( modId, TunnelType.FE_POWER ); + } + + @ZenMethod + public static void attuneIC2( IIngredient itemStack ) + { + attune( itemStack, TunnelType.IC2_POWER ); + } + + @ZenMethod + public static void attuneIC2( String modId ) + { + attune( modId, TunnelType.IC2_POWER ); + } + + @ZenMethod + public static void attuneLight( IIngredient itemStack ) + { + attune( itemStack, TunnelType.LIGHT ); + } + + @ZenMethod + public static void attuneLight( String modId ) + { + attune( modId, TunnelType.LIGHT ); + } + + private static void attune( IIngredient itemStack, TunnelType type ) + { + IP2PTunnelRegistry registry = AEApi.instance().registries().p2pTunnel(); + CTModule.toStacks( itemStack ).ifPresent( c -> c.forEach( i -> registry.addNewAttunement( i, type ) ) ); + } + + private static void attune( String modid, TunnelType type ) + { + AEApi.instance().registries().p2pTunnel().addNewAttunement( modid, type ); + } +} diff --git a/src/main/java/appeng/integration/modules/crafttweaker/CTModule.java b/src/main/java/appeng/integration/modules/crafttweaker/CTModule.java new file mode 100644 index 00000000..a6ca9231 --- /dev/null +++ b/src/main/java/appeng/integration/modules/crafttweaker/CTModule.java @@ -0,0 +1,130 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.crafttweaker; + + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; +import net.minecraftforge.oredict.OreDictionary; + +import crafttweaker.CraftTweakerAPI; +import crafttweaker.IAction; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; + +import appeng.integration.abstraction.ICraftTweaker; +import appeng.util.Platform; + + +public class CTModule implements ICraftTweaker +{ + static final List MODIFICATIONS = new ArrayList<>(); + + @Override + public void preInit() + { + CraftTweakerAPI.registerClass( GrinderRecipes.class ); + CraftTweakerAPI.registerClass( InscriberRecipes.class ); + CraftTweakerAPI.registerClass( SpatialRegistry.class ); + CraftTweakerAPI.registerClass( AttunementRegistry.class ); + CraftTweakerAPI.registerClass( CannonRegistry.class ); + } + + @Override + public void postInit() + { + MODIFICATIONS.forEach( CraftTweakerAPI::apply ); + } + + public static ItemStack toStack( IItemStack iStack ) + { + if( iStack == null ) + { + return ItemStack.EMPTY; + } + else + { + return (ItemStack) iStack.getInternal(); + } + } + + public static List toStackExpand( IItemStack iStack ) + { + if( iStack == null ) + { + return Collections.emptyList(); + } + else + { + ItemStack is = (ItemStack) iStack.getInternal(); + if( !is.isItemStackDamageable() && is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) + { + NonNullList ret = NonNullList.create(); + is.getItem().getSubItems( CreativeTabs.SEARCH, ret ); + return ret.stream().map( i -> new ItemStack( i.getItem(), iStack.getAmount(), i.getItemDamage() ) ).collect( Collectors.toList() ); + } + else + { + return Collections.singletonList( is ); + } + } + } + + public static Optional> toStacks( IIngredient ingredient ) + { + if( ingredient == null ) + { + return Optional.empty(); + } + Set ret = new TreeSet<>( CTModule::compareItemStacks ); + ingredient.getItems().stream().map( CTModule::toStackExpand ).forEach( ret::addAll ); + if( ret.isEmpty() ) + { + return Optional.empty(); + } + return Optional.of( ret ); + } + + private static int compareItemStacks( ItemStack a, ItemStack b ) + { + if( Platform.itemComparisons().isSameItem( a, b ) ) + { + return 0; + } + if( a == null ) + { + return -1; + } + if( b == null ) + { + return 1; + } + return System.identityHashCode( a ) - System.identityHashCode( b ); + } +} diff --git a/src/main/java/appeng/integration/modules/crafttweaker/CannonRegistry.java b/src/main/java/appeng/integration/modules/crafttweaker/CannonRegistry.java new file mode 100644 index 00000000..8b64999a --- /dev/null +++ b/src/main/java/appeng/integration/modules/crafttweaker/CannonRegistry.java @@ -0,0 +1,43 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.crafttweaker; + + +import crafttweaker.api.item.IIngredient; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import appeng.api.AEApi; +import appeng.api.features.IMatterCannonAmmoRegistry; + + +@ZenClass( "mods.appliedenergistics2.Cannon" ) +public class CannonRegistry +{ + private CannonRegistry() + { + } + + @ZenMethod + public static void registerAmmo( IIngredient itemStack, double weight ) + { + IMatterCannonAmmoRegistry registry = AEApi.instance().registries().matterCannon(); + CTModule.toStacks( itemStack ).ifPresent( c -> c.forEach( i -> registry.registerAmmo( i, weight ) ) ); + } +} diff --git a/src/main/java/appeng/integration/modules/crafttweaker/GrinderRecipes.java b/src/main/java/appeng/integration/modules/crafttweaker/GrinderRecipes.java new file mode 100644 index 00000000..5d7eb4ad --- /dev/null +++ b/src/main/java/appeng/integration/modules/crafttweaker/GrinderRecipes.java @@ -0,0 +1,127 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.crafttweaker; + + +import java.util.Collection; +import java.util.Collections; + +import net.minecraft.item.ItemStack; + +import crafttweaker.IAction; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import appeng.api.AEApi; +import appeng.api.features.IGrinderRecipe; +import appeng.api.features.IGrinderRecipeBuilder; + + +@ZenClass( "mods.appliedenergistics2.Grinder" ) +public class GrinderRecipes +{ + private GrinderRecipes() + { + } + + @ZenMethod + public static void addRecipe( IItemStack output, IIngredient input, int turns, @stanhebben.zenscript.annotations.Optional IItemStack secondary1Output, @stanhebben.zenscript.annotations.Optional Float secondary1Chance, @stanhebben.zenscript.annotations.Optional IItemStack secondary2Output, @stanhebben.zenscript.annotations.Optional Float secondary2Chance ) + { + Collection inStacks = CTModule.toStacks( input ).orElse( Collections.emptySet() ); + + for( ItemStack inStack : inStacks ) + { + IGrinderRecipeBuilder builder = AEApi.instance().registries().grinder().builder(); + builder.withInput( inStack ) + .withOutput( CTModule.toStack( output ) ) + .withTurns( turns ); + + final ItemStack s1 = CTModule.toStack( secondary1Output ); + if( !s1.isEmpty() ) + { + builder.withFirstOptional( s1, secondary1Chance == null ? 1.0f : secondary1Chance ); + } + final ItemStack s2 = CTModule.toStack( secondary2Output ); + if( !s2.isEmpty() ) + { + builder.withFirstOptional( s2, secondary2Chance == null ? 1.0f : secondary2Chance ); + } + CTModule.MODIFICATIONS.add( new Add( builder.build() ) ); + } + } + + @ZenMethod + public static void removeRecipe( IIngredient input ) + { + for( ItemStack inStack : CTModule.toStacks( input ).orElse( Collections.emptySet() ) ) + { + CTModule.MODIFICATIONS.add( new Remove( inStack ) ); + } + } + + private static class Add implements IAction + { + private final IGrinderRecipe entry; + + private Add( IGrinderRecipe entry ) + { + this.entry = entry; + } + + @Override + public void apply() + { + AEApi.instance().registries().grinder().addRecipe( entry ); + } + + @Override + public String describe() + { + return "Adding Grinder Entry for " + entry.getInput().getDisplayName(); + } + } + + private static class Remove implements IAction + { + private final ItemStack stack; + + private Remove( ItemStack stack ) + { + this.stack = stack; + } + + @Override + public void apply() + { + IGrinderRecipe recipe = AEApi.instance().registries().grinder().getRecipeForInput( stack ); + if( recipe != null ) + { + AEApi.instance().registries().grinder().removeRecipe( recipe ); + } + } + + @Override + public String describe() + { + return "Removing Grinder Entry for " + stack.getDisplayName(); + } + } +} diff --git a/src/main/java/appeng/integration/modules/crafttweaker/InscriberRecipes.java b/src/main/java/appeng/integration/modules/crafttweaker/InscriberRecipes.java new file mode 100644 index 00000000..313d6ff7 --- /dev/null +++ b/src/main/java/appeng/integration/modules/crafttweaker/InscriberRecipes.java @@ -0,0 +1,138 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.crafttweaker; + + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.stream.Collectors; + +import net.minecraft.item.ItemStack; + +import crafttweaker.IAction; +import crafttweaker.api.item.IIngredient; +import crafttweaker.api.item.IItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import appeng.api.AEApi; +import appeng.api.features.IInscriberRecipe; +import appeng.api.features.IInscriberRecipeBuilder; +import appeng.api.features.IInscriberRegistry; +import appeng.api.features.InscriberProcessType; + + +@ZenClass( "mods.appliedenergistics2.Inscriber" ) +public class InscriberRecipes +{ + private InscriberRecipes() + { + } + + @ZenMethod + public static void addRecipe( IItemStack output, IIngredient input, boolean inscribe, @stanhebben.zenscript.annotations.Optional IIngredient top, @stanhebben.zenscript.annotations.Optional IIngredient bottom ) + { + Optional> inStacks = CTModule.toStacks( input ); + if( !inStacks.isPresent() ) + { + return; + } + + Collection topList = CTModule.toStacks( top ).orElse( Collections.singleton( ItemStack.EMPTY ) ); + Collection bottomList = CTModule.toStacks( bottom ).orElse( Collections.singleton( ItemStack.EMPTY ) ); + + for( ItemStack topStack : topList ) + { + for( ItemStack bottomStack : bottomList ) + { + final IInscriberRecipeBuilder builder = AEApi.instance().registries().inscriber().builder(); + builder.withProcessType( inscribe ? InscriberProcessType.INSCRIBE : InscriberProcessType.PRESS ) + .withOutput( CTModule.toStack( output ) ) + .withInputs( inStacks.get() ); + + if( !topStack.isEmpty() ) + { + builder.withTopOptional( topStack ); + } + if( !bottomStack.isEmpty() ) + { + builder.withBottomOptional( bottomStack ); + } + CTModule.MODIFICATIONS.add( new Add( builder.build() ) ); + } + } + } + + @ZenMethod + public static void removeRecipe( IItemStack output ) + { + CTModule.MODIFICATIONS.add( new Remove( (ItemStack) output.getInternal() ) ); + } + + private static class Add implements IAction + { + private final IInscriberRecipe entry; + + private Add( IInscriberRecipe entry ) + { + this.entry = entry; + } + + @Override + public void apply() + { + AEApi.instance().registries().inscriber().addRecipe( entry ); + } + + @Override + public String describe() + { + return "Adding Inscriber Entry for " + entry.getOutput().getDisplayName(); + } + } + + private static class Remove implements IAction + { + private final ItemStack stack; + + private Remove( ItemStack stack ) + { + this.stack = stack; + } + + @Override + public void apply() + { + final IInscriberRegistry inscriber = AEApi.instance().registries().inscriber(); + inscriber.getRecipes() + .stream() + .filter( r -> r.getOutput().isItemEqual( this.stack ) ) + .collect( Collectors.toList() ) + .forEach( inscriber::removeRecipe ); + } + + @Override + public String describe() + { + return "Removing Inscriber Entry for " + stack.getDisplayName(); + } + } + +} diff --git a/src/main/java/appeng/integration/modules/crafttweaker/SpatialRegistry.java b/src/main/java/appeng/integration/modules/crafttweaker/SpatialRegistry.java new file mode 100644 index 00000000..d92e9c4b --- /dev/null +++ b/src/main/java/appeng/integration/modules/crafttweaker/SpatialRegistry.java @@ -0,0 +1,61 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.crafttweaker; + + +import net.minecraft.tileentity.TileEntity; + +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import appeng.api.AEApi; +import appeng.core.AELog; + + +@ZenClass( "mods.appliedenergistics2.Spatial" ) +public class SpatialRegistry +{ + private SpatialRegistry() + { + } + + @ZenMethod + public static void whitelistEntity( String entityClassName ) + { + Class entityClass = loadClass( entityClassName ); + if( entityClass != null ) + { + AEApi.instance().registries().movable().whiteListTileEntity( entityClass ); + } + } + + @SuppressWarnings( "unchecked" ) + private static Class loadClass( String className ) + { + try + { + return (Class) Class.forName( className ); + } + catch( Exception e ) + { + AELog.warn( e, "Failed to load TileEntity class '" + className + "'" ); + } + return null; + } +}