Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc bugs #341

Merged
merged 4 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,19 @@ public MachineInventoryLayout getInventoryLayout() {
}

protected boolean acceptSlotInput(int slot, ItemStack stack) {
return RecipeCaches.ALLOY_SMELTING.hasValidRecipeIf(getInventoryNN(), getInputsSlotAccess(), slot, stack);
if (getMode().canAlloy()) {
if (RecipeCaches.ALLOY_SMELTING.hasValidRecipeIf(getInventoryNN(), getInputsSlotAccess(), slot, stack)) {
return true;
}
}

if (getMode().canSmelt()) {
if (RecipeCaches.SMELTING.hasRecipe(List.of(stack))) {
return true;
}
}

return false;
}

@Override
Expand All @@ -183,18 +195,16 @@ protected boolean isActive() {
}

protected AlloySmeltingMachineTask createTask(Level level, AlloySmeltingRecipe.ContainerWrapper container, @Nullable AlloySmeltingRecipe recipe) {
return new AlloySmeltingMachineTask(level, getInventoryNN(), getEnergyStorage(), container, getOutputSlotAccess(), recipe);
return new AlloySmeltingMachineTask(level, getInventoryNN(), getEnergyStorage(), container, getInputsSlotAccess(), getOutputSlotAccess(), recipe);
}

protected static class AlloySmeltingMachineTask extends PoweredCraftingMachineTask<AlloySmeltingRecipe, AlloySmeltingRecipe.ContainerWrapper> {
public AlloySmeltingMachineTask(@NotNull Level level, MachineInventory inventory, IMachineEnergyStorage energyStorage,
AlloySmeltingRecipe.ContainerWrapper container, MultiSlotAccess outputSlots, @Nullable AlloySmeltingRecipe recipe) {
super(level, inventory, energyStorage, container, outputSlots, recipe);
}
private final MultiSlotAccess inputs;

public AlloySmeltingMachineTask(@NotNull Level level, MachineInventory inventory, IMachineEnergyStorage energyStorage,
AlloySmeltingRecipe.ContainerWrapper container, SingleSlotAccess outputSlot, @Nullable AlloySmeltingRecipe recipe) {
AlloySmeltingRecipe.ContainerWrapper container, MultiSlotAccess inputs, SingleSlotAccess outputSlot, @Nullable AlloySmeltingRecipe recipe) {
super(level, inventory, energyStorage, container, outputSlot, recipe);
this.inputs = inputs;
}

@Override
Expand All @@ -204,8 +214,8 @@ protected void onDetermineOutputs(AlloySmeltingRecipe recipe) {
CountedIngredient input = recipe.getInputs().get(0);

int inputCount = 0;
for (int i = INPUTS.size() - 1; i >= 0; i--) {
ItemStack itemStack = INPUTS.get(i).getItemStack(getInventory());
for (int i = inputs.size() - 1; i >= 0; i--) {
ItemStack itemStack = inputs.get(i).getItemStack(getInventory());
if (input.test(itemStack)) {
inputCount += Math.min(3 - inputCount, itemStack.getCount());
}
Expand All @@ -224,8 +234,8 @@ protected void consumeInputs(AlloySmeltingRecipe recipe) {
CountedIngredient input = recipe.getInputs().get(0);

int consumed = 0;
for (int i = INPUTS.size() - 1; i >= 0; i--) {
ItemStack itemStack = INPUTS.get(i).getItemStack(getInventory());
for (int i = inputs.size() - 1; i >= 0; i--) {
ItemStack itemStack = inputs.get(i).getItemStack(getInventory());
if (input.test(itemStack)) {
int consumedNow = Math.min(container.getInputsTaken() - consumed, itemStack.getCount());
itemStack.shrink(consumedNow);
Expand All @@ -238,7 +248,7 @@ protected void consumeInputs(AlloySmeltingRecipe recipe) {
boolean[] consumed = new boolean[3];

// Iterate over the slots
for (SingleSlotAccess slot : INPUTS.getAccesses()) {
for (SingleSlotAccess slot : this.inputs.getAccesses()) {
ItemStack stack = slot.getItemStack(inv);

// Iterate over the inputs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.enderio.machines.common.recipe;

import com.enderio.machines.common.init.MachineRecipes;
import com.enderio.machines.common.integrations.vanilla.VanillaAlloySmeltingRecipe;
import com.enderio.machines.common.utility.RecipeInputCache;
import net.minecraft.world.Container;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.SmeltingRecipe;
import net.minecraftforge.client.event.RecipesUpdatedEvent;
import net.minecraftforge.event.AddReloadListenerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
Expand All @@ -19,6 +22,9 @@ public class RecipeCaches {
public static final RecipeInputCache<AlloySmeltingRecipe.ContainerWrapper, AlloySmeltingRecipe> ALLOY_SMELTING
= new RecipeInputCache<>(MachineRecipes.ALLOY_SMELTING.type());

public static final RecipeInputCache<Container, SmeltingRecipe> SMELTING
= new RecipeInputCache<>(() -> RecipeType.SMELTING);

public static final RecipeInputCache<RecipeWrapper, PaintingRecipe> PAINTING
= new RecipeInputCache<>(MachineRecipes.PAINTING.type());

Expand All @@ -34,6 +40,7 @@ public class RecipeCaches {
@SubscribeEvent
public static void registerReloadListener(AddReloadListenerEvent event) {
ALLOY_SMELTING.markCacheDirty();
SMELTING.markCacheDirty();
PAINTING.markCacheDirty();
SAGMILLING.markCacheDirty();
SLICING.markCacheDirty();
Expand All @@ -43,6 +50,7 @@ public static void registerReloadListener(AddReloadListenerEvent event) {
@SubscribeEvent
public static void onRecipesUpdated(RecipesUpdatedEvent event) {
ALLOY_SMELTING.rebuildCache(event.getRecipeManager());
SMELTING.rebuildCache(event.getRecipeManager());
PAINTING.rebuildCache(event.getRecipeManager());
SAGMILLING.rebuildCache(event.getRecipeManager());
SLICING.rebuildCache(event.getRecipeManager());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraftforge.fml.util.thread.EffectiveSide;
Expand All @@ -16,7 +17,7 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;

public class RecipeInputCache<C extends Container, T extends MachineRecipe<C>> {
public class RecipeInputCache<C extends Container, T extends Recipe<C>> {
private final Supplier<RecipeType<T>> recipeType;
private final HashMap<Item, HashSet<T>> itemToRecipesCache;
private final HashMap<T, List<Ingredient>> recipeToIngredientCache;
Expand Down
23 changes: 0 additions & 23 deletions src/main/java/com/enderio/base/mixin/ItemStackMixin.java

This file was deleted.

1 change: 0 additions & 1 deletion src/main/resources/mixins.enderio.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"compatibilityLevel" : "JAVA_17",
"refmap" : "mixins.enderio.refmap.json",
"mixins" : [
"ItemStackMixin",
"LivingEntityMixin"
],
"client" : [
Expand Down