CraftTweaker support

This commit is contained in:
2023-08-30 19:10:58 +02:00
parent caf51f25a8
commit 50e0b5e774
13 changed files with 135 additions and 61 deletions

View File

@@ -1,6 +1,8 @@
<!-- modrinth_exclude.start -->
Trading Station
=============
<!-- modrinth_exclude.end -->
Item trading machine.
Made for modpacks. It doesn't add any recipe.
Features
@@ -11,7 +13,7 @@ Features
- Custom *Trading recipe*
- Indestructible variant for each station.
- Configurable consumption & progress.
- Mechanical station available with companion mod.
- Mechanical (Create Addon) station available with companion mod.
-
Trading recipe
---------------
@@ -23,13 +25,76 @@ Trading recipe
- `exclusiveTo` (optional). Required station. Defaults any. Possible values: `basic`, `powered`, `mechanical`
### Example (basic input & output)
```
{
"type": "trading_station:trading",
"ingredients": [
{"item": "minecraft:emerald", "count": 5}
],
"result": {
"item": "minecraft:diamond",
"count": 5
},
"processingTime": 500
}
```
### Example (output item with NBT)
```
{
"type": "trading_station:trading",
"ingredients": [
{"item": "minecraft:diamond", "count": 5}
],
"result": {
"item": "minecraft:enchanted_book",
"nbt": "{StoredEnchantments: [{id:\"looting\",lvl:3s}]}"
},
"processingTime": 100
}
```
### Example (biome requirement)
```
{
"type": "trading_station:trading",
"result": {
"item": "minecraft:diamond_sword",
"count": 1,
"nbt": "{Damage:0,Enchantments:[{id:\"mending\",lvl:1s}]}"
},
"ingredients": [
{
"item": "minecraft:diamond",
"count": 5
}
],
"processingTime": 100,
"biome": {
"name": "minecraft:plains"
}
}
```
### Example (exclusiveTo)
```
{
"type": "trading_station:trading",
"result": {
"item": "minecraft:diamond_sword",
"count": 1,
"nbt": "{Damage:0,Enchantments:[{id:\"sharpness\",lvl:1s}]}"
},
"ingredients": [
{
"item": "minecraft:diamond",
"count": 5
}
],
"processingTime": 100,
"exclusiveTo": [
"powered"
]
}
```
KubeJS 6.1 Integration
----------------------

View File

@@ -298,18 +298,18 @@ if(System.getenv('MODRINTH_TOKEN') != null) {
modrinth {
token = System.getenv("MODRINTH_TOKEN")
projectId = "mechanical_trading_station"
versionNumber = "${mod_version}"
projectId = "trading-station"
versionNumber = "${version}"
versionName = "${display_name} - v${mod_version} for Minecraft ${minecraft_version}"
versionType = "release" // This is the default -- can also be `beta` or `alpha`
uploadFile = tasks.jarJar // With Loom, this MUST be set to `remapJar` instead of `jar`!
gameVersions = ["${minecraft_version}"] // Must be an array, even with only one version
loaders = ["forge"] // Must also be an array - no need to specify this if you're using Loom or ForgeGradle
dependencies { // A special DSL for creating dependencies
optional.project "create"
optional.project "kubejs"
optional.project "jei"
optional.project "crafttweaker"
}
changelog = rootProject.file("changes/${minecraft_version}-${mod_version}.md").text
syncBodyFrom = rootProject.file("README.md").text
}
tasks.modrinth.dependsOn(tasks.modrinthSyncBody)
@@ -323,7 +323,7 @@ if(System.getenv('MODRINTH_TOKEN') != null) {
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}
publishing {
/*publishing {
publications {
mavenJava(MavenPublication) {
artifact jar
@@ -334,4 +334,27 @@ publishing {
url "file://${project.projectDir}/mcmodsrepo"
}
}
}
}*/
publishing {
// other settings of publication
publications {
mavenJava(MavenPublication) {
artifact jar
}
}
repositories {
maven {
name = "Gitea"
url = uri("https://git.fosil.eu/api/packages/oier/maven")
credentials(HttpHeaderCredentials) {
name = "Authorization"
value = "token ${System.getenv("FOSIL_TOKEN")}"
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
}

2
changes/1.19.2-0.1.1.md Normal file
View File

@@ -0,0 +1,2 @@
- Fixed recipe filtering.
- Added examples to documentation.

1
changes/1.19.2-0.1.2.md Normal file
View File

@@ -0,0 +1 @@
- CraftTweaker support.

View File

@@ -3,7 +3,7 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
mod_version=0.1.0
mod_version=0.1.2
modid=trading_station
author=oierbravo
display_name=Trading Station
@@ -42,7 +42,7 @@ kubejs_version=1902.6.1-build.348
jade_id = 3960379
ct_enabled = false
ct_enabled = true
ct_minecraft_version = 1.19.2
ct_version = 10.1.40
ct_annotation_processor_version = 3.0.0.10

View File

@@ -14,7 +14,7 @@ public class TradingRecipeHandler implements IRecipeHandler<TradingRecipe>{
@Override
public String dumpToCommandString(IRecipeManager<? super TradingRecipe> manager, TradingRecipe recipe) {
return manager.getCommandString() + recipe.toString() + recipe.getOutput() + "[" + recipe.getIngredient() + "]";
return manager.getCommandString() + recipe.toString() + recipe.getResultItem() + "[" + recipe.getIngredients() + "]";
}
@Override
public <U extends Recipe<?>> boolean doesConflict(IRecipeManager<? super TradingRecipe> manager, TradingRecipe firstRecipe, U secondRecipe) {

View File

@@ -6,13 +6,23 @@ import com.blamejared.crafttweaker.api.action.recipe.ActionAddRecipe;
import com.blamejared.crafttweaker.api.annotation.ZenRegister;
import com.blamejared.crafttweaker.api.fluid.IFluidStack;
import com.blamejared.crafttweaker.api.ingredient.IIngredient;
import com.blamejared.crafttweaker.api.item.IItemStack;
import com.blamejared.crafttweaker.api.recipe.manager.base.IRecipeManager;
import com.oierbravo.trading_station.TradingStation;
import com.oierbravo.trading_station.content.trading_recipe.BiomeCondition;
import com.oierbravo.trading_station.content.trading_recipe.ExclusiveToCondition;
import com.oierbravo.trading_station.content.trading_recipe.TradingRecipe;
import com.oierbravo.trading_station.content.trading_recipe.TradingRecipeBuilder;
import net.minecraft.core.NonNullList;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeType;
import org.openzen.zencode.java.ZenCodeType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ZenRegister
@ZenCodeType.Name("mods.trading_station.TradingManager")
//@Document("mods/trading_station/melting")
@@ -33,10 +43,24 @@ public class TradingRecipeManager implements IRecipeManager<TradingRecipe> {
* @docParam heatLevel 2
*/
@ZenCodeType.Method
public void addRecipe(String name, IFluidStack output, IIngredient input, int processingTime, int heatLevel ){
public void addRecipe(String name, IItemStack output, IIngredient[] itemInputs, int processingTime, String biome, String[] exclusiveTo ){
name = fixRecipeName(name);
ResourceLocation resourceLocation = new ResourceLocation(TradingStation.MODID, name);
CraftTweakerAPI.apply(new ActionAddRecipe<>( this, new TradingRecipe(resourceLocation, output.getInternal(), input.asVanillaIngredient(), processingTime, heatLevel)));
TradingRecipeBuilder builder = new TradingRecipeBuilder(resourceLocation);
List<Ingredient> ingredients = new ArrayList();
Arrays.stream(itemInputs).forEach((iIngredient) -> {
ingredients.add(iIngredient.asVanillaIngredient());
});
builder.withItemIngredients((Ingredient[])ingredients.toArray(new Ingredient[0]));
builder.withSingleItemOutput(output.asItemLike());
builder.processingTime(processingTime);
builder.withBiomeCondition(BiomeCondition.fromString(biome));
builder.exclusiveTo(ExclusiveToCondition.fromList(List.of(exclusiveTo)));
TradingRecipe recipe = builder.build();
CraftTweakerAPI.apply(new ActionAddRecipe<>(this, recipe));
}
@Override

View File

@@ -4,6 +4,7 @@ import net.minecraft.core.NonNullList;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.ItemLike;
import net.minecraftforge.common.crafting.conditions.ICondition;
import java.util.ArrayList;
@@ -31,6 +32,9 @@ public class TradingRecipeBuilder {
params.result = output;
return this;
}
public TradingRecipeBuilder withSingleItemOutput(ItemLike output) {
return withSingleItemOutput(new ItemStack(output));
}
public TradingRecipeBuilder processingTime(int time) {
params.processingTime = time;

View File

@@ -29,8 +29,6 @@ public interface ITradingStationBlockEntity {
ItemStack getTargetItemStack();
BlockPos getBlockPos();
void setPreferedItem(ItemStack itemStack);
void setItemStack(int slot, ItemStack itemStack, ItemStackSyncS2CPacket.SlotType slotType);

View File

@@ -55,8 +55,6 @@ public class ModRecipes {
}
public static List<TradingRecipe> getAllRecipesForMachine(Level pLevel, Biome biome, String machineType) {
if(pLevel.isClientSide())
return NonNullList.create();
return pLevel.getRecipeManager().getAllRecipesFor(TradingRecipe.Type.INSTANCE).stream()
.filter((tradingRecipe -> tradingRecipe.matchesBiome(biome, pLevel)))
.filter((tradingRecipe -> tradingRecipe.matchesExclusiveTo(machineType)))

View File

@@ -1,11 +0,0 @@
{
"type": "trading_station:trading",
"ingredients": [
{"item": "minecraft:emerald", "count": 5}
],
"result": {
"item": "minecraft:diamond",
"count": 5
},
"processingTime": 500
}

View File

@@ -1,11 +0,0 @@
{
"type": "trading_station:trading",
"ingredients": [
{"item": "minecraft:diamond", "count": 5}
],
"result": {
"item": "minecraft:enchanted_book",
"nbt": "{StoredEnchantments: [{id:\"looting\",lvl:3s}]}"
},
"processingTime": 100
}

View File

@@ -1,19 +0,0 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"S S",
"S S",
"NSN"
],
"key": {
"N": {
"item": "minecraft:iron_nugget"
},
"S": {
"tag": "forge:stone"
}
},
"result": {
"item": "trading_station:trading_station"
}
}