Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
import slimeknights.mantle.block.entity.MantleBlockEntity;
import slimeknights.tconstruct.common.network.InventorySlotSyncPacket;
import slimeknights.tconstruct.common.network.TinkerNetwork;
import slimeknights.tconstruct.library.recipe.TinkerRecipeTypes;
import slimeknights.tconstruct.library.recipe.melting.IMeltingContainer;
import slimeknights.tconstruct.library.recipe.melting.IMeltingRecipe;

import javax.annotation.Nullable;
import java.util.Optional;
import java.util.function.Predicate;

/**
Expand All @@ -33,7 +31,9 @@ public class MeltingModule implements IMeltingContainer, ContainerData {
private static final int REQUIRED_TEMP = 2;

/** Tile entity containing this melting module */
private final MantleBlockEntity parent;
private final MantleBlockEntity be;
/** Melting Inventory containing this melting module */
private final MeltingModuleInventory inventory;
/** Function that accepts fluid output from this module */
private final Predicate<IMeltingRecipe> outputFunction;
/** Function that boosts the ores based on the rate type */
Expand Down Expand Up @@ -78,9 +78,9 @@ private void resetRecipe() {
*/
public void setStack(ItemStack newStack) {
// send a slot update to the client when items change, so we can update the TESR
Level world = parent.getLevel();
Level world = be.getLevel();
if (slotIndex != -1 && world != null && !world.isClientSide && !ItemStack.matches(stack, newStack)) {
TinkerNetwork.getInstance().sendToClientsAround(new InventorySlotSyncPacket(newStack, slotIndex, parent.getBlockPos()), world, parent.getBlockPos());
TinkerNetwork.getInstance().sendToClientsAround(new InventorySlotSyncPacket(newStack, slotIndex, be.getBlockPos()), world, be.getBlockPos());
}

// clear progress if setting to empty or the items do not match
Expand All @@ -103,7 +103,7 @@ public void setStack(ItemStack newStack) {
}
requiredTime = newTime;
requiredTemp = newTemp;
parent.setChangedFast();
be.setChangedFast();
}


Expand Down Expand Up @@ -165,7 +165,7 @@ public void coolItem() {
*/
@Nullable
private IMeltingRecipe findRecipe() {
Level world = parent.getLevel();
Level world = be.getLevel();
if (world == null) {
return null;
}
Expand All @@ -175,10 +175,11 @@ private IMeltingRecipe findRecipe() {
if (last != null && last.matches(this, world)) {
return last;
}

// if that fails, try to find a new recipe
Optional<IMeltingRecipe> newRecipe = world.getRecipeManager().getRecipeFor(TinkerRecipeTypes.MELTING.get(), this, world);
if (newRecipe.isPresent()) {
lastRecipe = newRecipe.get();
IMeltingRecipe newRecipe = inventory.findRecipe(this, lastRecipe);
if (newRecipe != null) {
lastRecipe = newRecipe;
return lastRecipe;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
import net.minecraft.nbt.Tag;
import net.minecraft.world.inventory.ContainerData;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemHandlerHelper;
import slimeknights.mantle.block.entity.MantleBlockEntity;
import slimeknights.tconstruct.library.recipe.TinkerRecipeTypes;
import slimeknights.tconstruct.library.recipe.melting.IMeltingContainer.IOreRate;
import slimeknights.tconstruct.library.recipe.melting.IMeltingRecipe;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Optional;
import java.util.function.Consumer;

/**
Expand All @@ -26,6 +30,8 @@ public class MeltingModuleInventory implements IItemHandlerModifiable {
private static final String TAG_ITEMS = "items";
private static final String TAG_SIZE = "size";

/** Last used recipe by any slot in the inventory */
private IMeltingRecipe lastInventoryRecipe;
Comment thread
ferriarnus marked this conversation as resolved.
Outdated
/** Parent tile entity */
private final MantleBlockEntity parent;
/** Fluid handler for outputs */
Expand Down Expand Up @@ -120,6 +126,25 @@ public int getRequiredTemp(int slot) {
return hasModule(slot) ? modules[slot].getRequiredTemp() : 0;
}

/**
* Finds a melting recipe
* @param module Melting Module asking for a recipe
* @param slotRecipe Last used Recipe of that slot
* @return Melting recipe found, or null if no match
*/
@Nullable
public IMeltingRecipe findRecipe(MeltingModule module, @Nullable IMeltingRecipe slotRecipe) {
Level world = parent.getLevel();
if (world == null) {
return null;
}
if (lastInventoryRecipe != null && slotRecipe != lastInventoryRecipe && lastInventoryRecipe.matches(module, world)) {
return lastInventoryRecipe;
}
Optional<IMeltingRecipe> newRecipe = world.getRecipeManager().getRecipeFor(TinkerRecipeTypes.MELTING.get(), module, world);
Comment thread
ferriarnus marked this conversation as resolved.
return newRecipe.orElse(null);
}


/* Sub modules */

Expand All @@ -134,7 +159,7 @@ public MeltingModule getModule(int slot) {
throw new IndexOutOfBoundsException();
}
if (modules[slot] == null) {
modules[slot] = new MeltingModule(parent, recipe -> tryFillTank(slot, recipe), oreRate, slot);
modules[slot] = new MeltingModule(parent, this, recipe -> tryFillTank(slot, recipe), oreRate, slot);
}
return modules[slot];
}
Expand Down