Skip to content

Commit

Permalink
start working on mixer recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Thepigcat76 committed Sep 14, 2024
1 parent 7739d9d commit 8a71eab
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.portingdeadmods.modjam.capabilities.power.IPowerStorage;
import com.portingdeadmods.modjam.capabilities.power.PowerStorage;
import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectList;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
Expand All @@ -32,7 +34,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.awt.*;
import java.util.List;
import java.util.Map;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
Expand Down Expand Up @@ -73,6 +75,7 @@ protected ItemStackHandler getItemStackHandler() {
protected FluidTank getFluidTank() {
return fluidTank;
}

protected FluidTank getSecondaryFluidTank() {
return fluidTank;
}
Expand Down Expand Up @@ -237,6 +240,19 @@ public void drop() {
return itemStacks;
}

public List<ItemStack> getItemHandlerStacksList() {
IItemHandler itemStackHandler = getItemHandler();

if (itemStackHandler == null) return null;

int slots = itemStackHandler.getSlots();
ObjectList<ItemStack> itemStacks = new ObjectArrayList<>(slots);
for (int i = 0; i < slots; i++) {
itemStacks.add(itemStackHandler.getStackInSlot(i));
}
return itemStacks;
}

public <T> T getHandlerOnSide(BlockCapability<T, @Nullable Direction> capability, SidedHandlerSupplier<T> handlerSupplier, Direction direction, T baseHandler) {
if (direction == null) {
return baseHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@

import com.portingdeadmods.modjam.api.blockentities.LaserBlockEntity;
import com.portingdeadmods.modjam.capabilities.IOActions;
import com.portingdeadmods.modjam.content.recipes.MixingRecipe;
import com.portingdeadmods.modjam.content.recipes.utils.MixingRecipeInput;
import com.portingdeadmods.modjam.registries.MJBlockEntityTypes;
import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.objects.ObjectSet;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.capabilities.BlockCapability;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.fluids.FluidStack;
import org.jetbrains.annotations.Nullable;

import java.util.Map;
import java.util.Optional;

public class MixerBlockEntity extends LaserBlockEntity {
public static final int OUTPUT_SLOT = 4;
private boolean active;

private float independentAngle;
Expand All @@ -23,9 +30,11 @@ public class MixerBlockEntity extends LaserBlockEntity {

public MixerBlockEntity(BlockPos blockPos, BlockState blockState) {
super(MJBlockEntityTypes.MIXER.get(), blockPos, blockState);
addFluidTank(1000);
addSecondaryFluidTank( 1000);
addItemHandler(5, (slot, stack) -> slot != 4);
// in
addFluidTank(1000);
// out
addSecondaryFluidTank(1000, fluidStack -> false);
}

@Override
Expand Down Expand Up @@ -72,7 +81,26 @@ public void commonTick() {
}

private void performRecipe() {
Optional<MixingRecipe> recipe = level.getRecipeManager()
.getRecipeFor(MixingRecipe.Type.INSTANCE, new MixingRecipeInput(getItemHandlerStacksList(), getFluidTank().getFluid()), level).map(RecipeHolder::value);
if (recipe.isPresent() && canInsertFluid(recipe.get().fluidResult()) && canInsertItem(recipe.get().result())) {

}
}

private boolean canInsertItem(ItemStack result) {
ItemStack stack = getItemHandler().getStackInSlot(OUTPUT_SLOT);
boolean itemMatches = result.isEmpty() || stack.isEmpty() || result.is(stack.getItem());
int stackLimit = stack.isEmpty() ? result.getMaxStackSize() : stack.getMaxStackSize();
boolean amountMatches = result.getCount() + stack.getCount() <= Math.min(stackLimit, getItemHandler().getSlotLimit(OUTPUT_SLOT));
return itemMatches && amountMatches;
}

private boolean canInsertFluid(FluidStack fluidStack) {
boolean fluidMatches = fluidStack.isEmpty() || getSecondaryFluidTank().isEmpty() || fluidStack.is(getSecondaryFluidTank().getFluid().getFluid());
int fluidAmount = getSecondaryFluidTank().getFluidAmount();
boolean amountMatches = fluidAmount + fluidStack.getAmount() <= getSecondaryFluidTank().getCapacity();
return fluidMatches && amountMatches;
}

public int getSpeed() {
Expand Down

0 comments on commit 8a71eab

Please sign in to comment.