From ec0c5bc24e3f537484513a85762eebc539475cdd Mon Sep 17 00:00:00 2001 From: glisco Date: Sat, 5 Nov 2022 01:38:11 +0100 Subject: [PATCH] clean up remainders loader, update for new transfer api --- gradle.properties | 10 ++--- .../block/ForgeControllerBlockEntity.java | 38 ++++++++++--------- .../AlloyForgeryGlobalRemaindersLoader.java | 10 ++--- .../alloyforgery/recipe/AlloyForgeRecipe.java | 18 ++++----- 4 files changed, 36 insertions(+), 40 deletions(-) diff --git a/gradle.properties b/gradle.properties index dbc5beb..7f65128 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/develop minecraft_base_version=1.19 -minecraft_version=1.19 -yarn_mappings=1.19+build.1 -loader_version=0.14.7 +minecraft_version=1.19.2 +yarn_mappings=1.19.2+build.28 +loader_version=0.14.10 # Mod Properties -mod_version=2.0.16 +mod_version=2.0.17 maven_group=wraith archives_base_name=wraith-alloy-forgery # Dependencies -fabric_version=0.57.0+1.19 +fabric_version=0.64.0+1.19.2 # https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/ rei_version=9.0.472 diff --git a/src/main/java/wraith/alloyforgery/block/ForgeControllerBlockEntity.java b/src/main/java/wraith/alloyforgery/block/ForgeControllerBlockEntity.java index c97348b..b3a16a3 100644 --- a/src/main/java/wraith/alloyforgery/block/ForgeControllerBlockEntity.java +++ b/src/main/java/wraith/alloyforgery/block/ForgeControllerBlockEntity.java @@ -32,7 +32,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; -import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; import wraith.alloyforgery.AlloyForgeScreenHandler; import wraith.alloyforgery.AlloyForgery; @@ -154,7 +153,7 @@ public void tick() { world.updateComparators(pos, getCachedState().getBlock()); - if (!verifyMultiblock()) { + if (!this.verifyMultiblock()) { this.currentSmeltTime = 0; final var currentState = world.getBlockState(pos); @@ -164,13 +163,13 @@ public void tick() { return; } - if (!getFuelStack().isEmpty()) { - final var fuelStack = getFuelStack(); + if (!this.getFuelStack().isEmpty()) { + final var fuelStack = this.getFuelStack(); final var fuelDefinition = ForgeFuelRegistry.getFuelForItem(fuelStack.getItem()); if (fuelDefinition != ForgeFuelRegistry.ForgeFuelDefinition.EMPTY && canAddFuel(fuelDefinition.fuel())) { - if (!ItemOps.emptyAwareDecrement(getFuelStack())) { + if (!ItemOps.emptyAwareDecrement(this.getFuelStack())) { setStack(11, fuelDefinition.hasReturnType() ? new ItemStack(fuelDefinition.returnType()) : ItemStack.EMPTY); } @@ -193,28 +192,28 @@ public void tick() { } if (!this.isEmpty()) { - final var recipeOptional = world.getRecipeManager().getFirstMatch(AlloyForgeRecipe.Type.INSTANCE, this, world); + final var recipeOptional = this.world.getRecipeManager().getFirstMatch(AlloyForgeRecipe.Type.INSTANCE, this, world); if (recipeOptional.isEmpty()) { this.currentSmeltTime = 0; } else { final var recipe = recipeOptional.get(); - if (recipe.getMinForgeTier() > forgeDefinition.forgeTier()) { + if (recipe.getMinForgeTier() > this.forgeDefinition.forgeTier()) { this.currentSmeltTime = 0; return; } final var outputStack = this.getStack(10); - final var recipeOutput = recipe.getOutput(forgeDefinition.forgeTier()); + final var recipeOutput = recipe.getOutput(this.forgeDefinition.forgeTier()); if (!outputStack.isEmpty() && !ItemOps.canStack(outputStack, recipeOutput)) { this.currentSmeltTime = 0; return; } - if (this.currentSmeltTime < forgeDefinition.maxSmeltTime()) { + if (this.currentSmeltTime < this.forgeDefinition.maxSmeltTime()) { - final float fuelRequirement = recipe.getFuelPerTick() * forgeDefinition.speedMultiplier(); + final float fuelRequirement = recipe.getFuelPerTick() * this.forgeDefinition.speedMultiplier(); if (this.fuel - fuelRequirement < 0) { this.currentSmeltTime = 0; return; @@ -227,7 +226,7 @@ public void tick() { AlloyForgery.FORGE_PARTICLES.spawn(world, Vec3d.of(pos), facing); } } else { - var remainderList = recipe.attemptToGetRemainders(this); + var remainderList = recipe.gatherRemainders(this); recipe.craft(this); @@ -247,7 +246,7 @@ public void tick() { } } - public void handleForgingRemainders(DefaultedList remainderList) { + private void handleForgingRemainders(DefaultedList remainderList) { for (int i = 0; i < remainderList.size(); ++i) { var inputStack = this.getStack(i); var remainderStack = remainderList.get(i); @@ -265,22 +264,20 @@ public void handleForgingRemainders(DefaultedList remainderList) { var insertStack = remainderStack.copy(); insertStack.setCount(excess); - if(!attemptToInsertIntoHopper(insertStack)){ + if(!this.attemptToInsertIntoHopper(insertStack)){ var frontForgePos = pos.offset(getCachedState().get(ForgeControllerBlock.FACING)); world.playSound(null, frontForgePos.getX(), frontForgePos.getY(), frontForgePos.getZ(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.BLOCKS, 1.0F, 0.2F); - ItemScatterer.spawn(world, frontForgePos.getX(), frontForgePos.getY(), frontForgePos.getZ(), insertStack); } } this.setStack(i, remainderStack); } else { - if(!attemptToInsertIntoHopper(remainderStack)){ + if(!this.attemptToInsertIntoHopper(remainderStack)){ var frontForgePos = pos.offset(getCachedState().get(ForgeControllerBlock.FACING)); world.playSound(null, frontForgePos.getX(), frontForgePos.getY(), frontForgePos.getZ(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.BLOCKS, 1.0F, 0.2F); - ItemScatterer.spawn(world, frontForgePos.getX(), frontForgePos.getY(), frontForgePos.getZ(), remainderStack); } } @@ -289,7 +286,7 @@ public void handleForgingRemainders(DefaultedList remainderList) { } @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public boolean attemptToInsertIntoHopper(ItemStack remainderStack){ + private boolean attemptToInsertIntoHopper(ItemStack remainderStack){ if (remainderStack.isEmpty()) return true; HopperBlockEntity blockEntity = null; @@ -351,7 +348,7 @@ public boolean verifyMultiblock() { return true; } - public static ImmutableList generateMultiblockPositions(BlockPos controllerPos, Direction controllerFacing) { + private static ImmutableList generateMultiblockPositions(BlockPos controllerPos, Direction controllerFacing) { final List posses = new ArrayList<>(); final BlockPos center = controllerPos.offset(controllerFacing.getOpposite()); @@ -444,6 +441,11 @@ protected boolean canInsert(FluidVariant variant) { protected boolean canExtract(FluidVariant variant) { return false; } + + @Override + public Iterator> iterator() { + return InsertionOnlyStorage.super.iterator(); + } } public static class Type extends BlockEntityType { diff --git a/src/main/java/wraith/alloyforgery/data/AlloyForgeryGlobalRemaindersLoader.java b/src/main/java/wraith/alloyforgery/data/AlloyForgeryGlobalRemaindersLoader.java index 6fe147a..03588ef 100644 --- a/src/main/java/wraith/alloyforgery/data/AlloyForgeryGlobalRemaindersLoader.java +++ b/src/main/java/wraith/alloyforgery/data/AlloyForgeryGlobalRemaindersLoader.java @@ -33,13 +33,9 @@ protected void apply(Map prepared, ResourceManager mana prepared.forEach((identifier, jsonElement) -> { try { if(jsonElement instanceof JsonObject jsonObject){ - if(!jsonObject.has("remainders")){ - throw new JsonSyntaxException("The Global Remainders file seems to be missing the needed remainders field."); - } - var remainders = new HashMap(); - for (var remainderEntry : jsonObject.getAsJsonObject("remainders").entrySet()) { + for (var remainderEntry : JsonHelper.getObject(jsonObject, "remainders").entrySet()) { var item = JsonHelper.asItem(new JsonPrimitive(remainderEntry.getKey()), remainderEntry.getKey()); if (remainderEntry.getValue().isJsonObject()) { @@ -53,10 +49,10 @@ protected void apply(Map prepared, ResourceManager mana AlloyForgeRecipe.addRemainders(remainders); } else { - throw new JsonSyntaxException("JsonElement wasn't a JsonObject meaning it is malformed"); + throw new JsonSyntaxException("Expected alloy forge remainders definition to be a json object"); } } catch (IllegalArgumentException | JsonParseException exception) { - LOGGER.error("[AlloyForgerRemainders]: Parsing error loading recipe {}", identifier, exception); + LOGGER.error("[AlloyForgeRemainders]: Parsing error loading recipe {}", identifier, exception); } }); } diff --git a/src/main/java/wraith/alloyforgery/recipe/AlloyForgeRecipe.java b/src/main/java/wraith/alloyforgery/recipe/AlloyForgeRecipe.java index 1f10ec8..c497142 100644 --- a/src/main/java/wraith/alloyforgery/recipe/AlloyForgeRecipe.java +++ b/src/main/java/wraith/alloyforgery/recipe/AlloyForgeRecipe.java @@ -28,7 +28,7 @@ public class AlloyForgeRecipe implements Recipe { - private static final Map GLOBAL_RECIPE_REMAINDER = new HashMap<>(); + private static final Map GLOBAL_REMAINDERS = new HashMap<>(); private static final List INPUT_SLOT_INDICES = IntStream.rangeClosed(0, 9).boxed().toList(); @@ -84,7 +84,7 @@ public void finishRecipe(PendingRecipeData pendingData) { } public static void addRemainders(Map remainders){ - GLOBAL_RECIPE_REMAINDER.putAll(remainders); + GLOBAL_REMAINDERS.putAll(remainders); } @Override @@ -157,22 +157,20 @@ public Map getIngredientsMap() { @Override public ItemStack craft(Inventory inventory) { - tryBind(inventory).forEach(inventory::removeStack); - + this.tryBind(inventory).forEach(inventory::removeStack); return ItemStack.EMPTY; } @Nullable - public DefaultedList attemptToGetRemainders(Inventory inventory) { + public DefaultedList gatherRemainders(Inventory inventory) { final var remainders = DefaultedList.ofSize(inventory.size(), ItemStack.EMPTY); - final var owoRemainders = RecipeRemainderStorage.has(this.getId()) ? RecipeRemainderStorage.get(this.getId()) : Map.of(); - if(owoRemainders.isEmpty() && GLOBAL_RECIPE_REMAINDER.isEmpty()) return null; + if(owoRemainders.isEmpty() && GLOBAL_REMAINDERS.isEmpty()) return null; var setAnyRemainders = false; - for (int i : tryBind(inventory).keySet()) { + for (int i : this.tryBind(inventory).keySet()) { var item = inventory.getStack(i).getItem(); if (!owoRemainders.isEmpty()) { @@ -181,8 +179,8 @@ public DefaultedList attemptToGetRemainders(Inventory inventory) { remainders.set(i, owoRemainders.get(item).copy()); setAnyRemainders = true; - } else if(GLOBAL_RECIPE_REMAINDER.containsKey(item)){ - remainders.set(i, GLOBAL_RECIPE_REMAINDER.get(item).copy()); + } else if(GLOBAL_REMAINDERS.containsKey(item)){ + remainders.set(i, GLOBAL_REMAINDERS.get(item).copy()); setAnyRemainders = true; }