diff --git a/build.gradle b/build.gradle index e6333ca..3c5e148 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,13 @@ import java.nio.charset.StandardCharsets plugins { - id 'fabric-loom' version '1.4-SNAPSHOT' + id 'fabric-loom' version '1.6-SNAPSHOT' id 'maven-publish' - id("com.modrinth.minotaur") version "2.8.4" + id("com.modrinth.minotaur") version "2.8.7" } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 +targetCompatibility = JavaVersion.VERSION_21 archivesBaseName = project.archives_base_name version = project.mod_version @@ -26,8 +26,8 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}") - modImplementation include("eu.pb4:polymer-core:0.7.1+1.20.4") - modImplementation include("xyz.nucleoid:server-translations-api:2.2.0+1.20.3-rc1") + modImplementation include("eu.pb4:polymer-core:0.8.0-beta.8+1.20.6") + modImplementation include("xyz.nucleoid:server-translations-api:2.3.0+1.20.5-rc2") } loom { @@ -43,7 +43,7 @@ processResources { } tasks.withType(JavaCompile).configureEach { - it.options.release = 17 + it.options.release = 21 } java { diff --git a/gradle.properties b/gradle.properties index 3874e1d..58b2aec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,9 @@ org.gradle.jvmargs=-Xmx1G -minecraft_version=1.20.4 -yarn_mappings=1.20.4+build.1 -loader_version=0.15.1 -fabric_version=0.91.2+1.20.4 -mod_version=1.0.13 +minecraft_version=1.20.6 +yarn_mappings=1.20.6+build.1 +loader_version=0.15.11 +fabric_version=0.97.8+1.20.6 +mod_version=1.0.14 maven_group=com.github.tatercertified archives_base_name=fabricautocrafter modrinth_id=wbqioEpc diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 744c64d..20db9ad 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/github/tatercertified/fabricautocrafter/AutoCrafter.java b/src/main/java/com/github/tatercertified/fabricautocrafter/AutoCrafter.java index 756f82e..dbff684 100644 --- a/src/main/java/com/github/tatercertified/fabricautocrafter/AutoCrafter.java +++ b/src/main/java/com/github/tatercertified/fabricautocrafter/AutoCrafter.java @@ -1,7 +1,7 @@ package com.github.tatercertified.fabricautocrafter; import eu.pb4.polymer.core.api.block.PolymerBlock; -import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockEntityProvider; import net.minecraft.block.BlockState; @@ -10,7 +10,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.stat.Stats; import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; import net.minecraft.util.ItemScatterer; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; @@ -22,12 +21,12 @@ public class AutoCrafter extends Block implements PolymerBlock, BlockEntityProvider { - protected AutoCrafter(FabricBlockSettings blockSettings) { + protected AutoCrafter(AbstractBlock.Settings blockSettings) { super(blockSettings); } @Override - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { if (world.isClient) { return ActionResult.SUCCESS; } else if (world.getBlockEntity(pos) instanceof CraftingTableBlockEntity entity) { @@ -38,8 +37,8 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt } @Override - public Block getPolymerBlock(BlockState state) { - return CRAFTING_TABLE; + public BlockState getPolymerBlockState(BlockState state) { + return CRAFTING_TABLE.getDefaultState(); } @Override diff --git a/src/main/java/com/github/tatercertified/fabricautocrafter/AutoCrafterMod.java b/src/main/java/com/github/tatercertified/fabricautocrafter/AutoCrafterMod.java index 61d4147..fd1c537 100644 --- a/src/main/java/com/github/tatercertified/fabricautocrafter/AutoCrafterMod.java +++ b/src/main/java/com/github/tatercertified/fabricautocrafter/AutoCrafterMod.java @@ -3,13 +3,12 @@ import eu.pb4.polymer.core.api.block.PolymerBlockUtils; import eu.pb4.polymer.core.api.item.PolymerBlockItem; import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.item.v1.FabricItemSettings; -import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; +import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; import net.minecraft.item.ItemGroups; import net.minecraft.item.Items; import net.minecraft.registry.Registries; @@ -21,9 +20,9 @@ public class AutoCrafterMod implements ModInitializer { public static final Identifier IDENTIFIER = new Identifier("autocrafter", "autocrafter"); - public static final Block BLOCK = new AutoCrafter(FabricBlockSettings.copyOf(Blocks.CRAFTING_TABLE).strength(2.5f, 2.5f)); - public static final BlockItem ITEM = new PolymerBlockItem(BLOCK, new FabricItemSettings(), Items.CRAFTING_TABLE); - public static final BlockEntityType TYPE = FabricBlockEntityTypeBuilder.create(CraftingTableBlockEntity::new, BLOCK).build(null); + public static final Block BLOCK = new AutoCrafter(AbstractBlock.Settings.copy(Blocks.CRAFTING_TABLE).strength(2.5f, 2.5f)); + public static final BlockItem ITEM = new PolymerBlockItem(BLOCK, new Item.Settings(), Items.CRAFTING_TABLE); + public static final BlockEntityType TYPE = BlockEntityType.Builder.create(CraftingTableBlockEntity::new, BLOCK).build(null); @Override public void onInitialize() { diff --git a/src/main/java/com/github/tatercertified/fabricautocrafter/CraftingTableBlockEntity.java b/src/main/java/com/github/tatercertified/fabricautocrafter/CraftingTableBlockEntity.java index 2faea00..bde2c2b 100644 --- a/src/main/java/com/github/tatercertified/fabricautocrafter/CraftingTableBlockEntity.java +++ b/src/main/java/com/github/tatercertified/fabricautocrafter/CraftingTableBlockEntity.java @@ -11,9 +11,9 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.recipe.*; +import net.minecraft.registry.RegistryWrapper; import net.minecraft.screen.ScreenHandler; import net.minecraft.text.Text; -import net.minecraft.util.Identifier; import net.minecraft.util.ItemScatterer; import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.math.BlockPos; @@ -21,8 +21,8 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.Optional; import static com.github.tatercertified.fabricautocrafter.AutoCrafterMod.TYPE; @@ -53,17 +53,19 @@ public CraftingInventory boundCraftingInventory(ScreenHandler handler) { } @Override - public void writeNbt(NbtCompound tag) { - super.writeNbt(tag); - Inventories.writeNbt(tag, inventory); - tag.put("Output", output.writeNbt(new NbtCompound())); + protected void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { + super.writeNbt(nbt, registryLookup); + Inventories.writeNbt(nbt, inventory, registryLookup); + if (!output.isEmpty()) { + nbt.put("Output", output.encode(registryLookup)); + } } @Override - public void readNbt(NbtCompound tag) { - super.readNbt(tag); - Inventories.readNbt(tag, inventory); - this.output = ItemStack.fromNbt(tag.getCompound("Output")); + protected void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { + super.readNbt(nbt, registryLookup); + Inventories.readNbt(nbt, inventory, registryLookup); + this.output = ItemStack.fromNbtOrEmpty(registryLookup, nbt.getCompound("Output")); } @Override @@ -71,6 +73,16 @@ protected Text getContainerName() { return Text.translatable("container.crafting"); } + @Override + protected DefaultedList getHeldStacks() { + return this.inventory; + } + + @Override + protected void setHeldStacks(DefaultedList inventory) { + this.inventory = inventory; + } + @Override protected ScreenHandler createScreenHandler(int id, PlayerInventory playerInventory) { final AutoCraftingTableContainer container = new AutoCraftingTableContainer(id, playerInventory, this); @@ -191,13 +203,13 @@ private Optional getCurrentRecipe() { if (getLastRecipe != null) { CraftingRecipe recipe = (CraftingRecipe) getLastRecipe.value(); - Map> craftingRecipes = manager.getAllOfType(RecipeType.CRAFTING); - if (craftingRecipes.containsKey(recipe) && craftingRecipes.get(recipe) != null) { - CraftingRecipe mapRecipe = craftingRecipes.get(recipe).value(); - if (mapRecipe != null && mapRecipe.matches(craftingInventory, world)) { - return Optional.of(recipe); - } - } + Collection> craftingRecipes = manager.getAllOfType(RecipeType.CRAFTING); + + return craftingRecipes.stream() + .filter(entry -> entry.value().equals(recipe)) + .map(RecipeEntry::value) + .filter(mapRecipe1 -> mapRecipe1.matches(craftingInventory, world)) + .findFirst(); } Optional> recipe = manager.getFirstMatch(RecipeType.CRAFTING, craftingInventory, world); @@ -221,9 +233,11 @@ private ItemStack craft() { current.decrement(1); } if (!remainingStack.isEmpty()) { + System.out.println("TEST1"); if (current.isEmpty()) { + System.out.println("TEST2"); inventory.set(i, remainingStack); - } else if (ItemStack.canCombine(current, remainingStack)) { + } else if (ItemStack.areItemsAndComponentsEqual(current, remainingStack)) { current.increment(remainingStack.getCount()); } else { ItemScatterer.spawn(world, pos.getX(), pos.getY(), pos.getZ(), remainingStack); diff --git a/src/main/java/com/github/tatercertified/fabricautocrafter/mixin/MixinHopperBlockEntity.java b/src/main/java/com/github/tatercertified/fabricautocrafter/mixin/MixinHopperBlockEntity.java index 5d45947..09ec13f 100644 --- a/src/main/java/com/github/tatercertified/fabricautocrafter/mixin/MixinHopperBlockEntity.java +++ b/src/main/java/com/github/tatercertified/fabricautocrafter/mixin/MixinHopperBlockEntity.java @@ -8,6 +8,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; /** @@ -57,7 +58,7 @@ private static boolean canInsertStack(Hopper hopper, ItemStack test) { if (hopper.isValid(i, test)) { var stack = hopper.getStack(i); if (stack.isEmpty() || (stack.getCount() < Math.min(stack.getMaxCount(), hopper.getMaxCountPerStack()) - && ItemStack.canCombine(stack, test))) return true; + && ItemStack.areItemsAndComponentsEqual(stack, test))) return true; } } return false; diff --git a/src/main/resources/act.accesswidener b/src/main/resources/act.accesswidener index 421db9f..463d655 100644 --- a/src/main/resources/act.accesswidener +++ b/src/main/resources/act.accesswidener @@ -1,2 +1,2 @@ accessWidener v1 named -accessible method net/minecraft/recipe/RecipeManager getAllOfType (Lnet/minecraft/recipe/RecipeType;)Ljava/util/Map; \ No newline at end of file +accessible method net/minecraft/recipe/RecipeManager getAllOfType (Lnet/minecraft/recipe/RecipeType;)Ljava/util/Collection; diff --git a/src/main/resources/data/autocrafter/recipes/autocrafter.json b/src/main/resources/data/autocrafter/recipes/autocrafter.json index f8c87a0..07315a2 100644 --- a/src/main/resources/data/autocrafter/recipes/autocrafter.json +++ b/src/main/resources/data/autocrafter/recipes/autocrafter.json @@ -14,6 +14,7 @@ } }, "result": { - "item": "autocrafter:autocrafter" + "count": 1, + "id": "autocrafter:autocrafter" } } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 001ca19..fd9675f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -24,7 +24,7 @@ "depends": { "fabricloader": "*", "fabric": "*", - "minecraft": ">=1.20.3", + "minecraft": ">=1.20.5", "java": ">=17" } }