Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions gradle/ieaddon.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,9 @@ repositories {
name "CurseForge"
url "https://minecraft.curseforge.com/api/maven/"
}

maven {
name "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
package pl.pabilo8.immersiveintelligence.api.crafting;

import blusunrize.immersiveengineering.api.crafting.IngredientStack;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import pl.pabilo8.immersiveintelligence.api.crafting.recipe.IIMultiblockRecipe;
import pl.pabilo8.immersiveintelligence.api.crafting.recipe.IIRecipeLayout;
import pl.pabilo8.immersiveintelligence.api.crafting.recipe.IIRecipeLayoutBuilder;
import pl.pabilo8.immersiveintelligence.common.IIConfigHandler.IIConfig.Machines.Coagulator;
import pl.pabilo8.immersiveintelligence.common.IILogger;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

/**
* @author Pabilo8 (pabilo@iiteam.net)
* @since 08.08.2019
*/
public class CoagulatorRecipe extends IIMultiblockRecipe
{
private static HashMap<Predicate<ItemStack>, Integer> bucketTimeMap = new HashMap<>();
private static List<DryingInformation> dryingInformation = new ArrayList<>();
public final FluidStack fluidInput, coagulantInput;
public final ItemStack itemOutput;

Expand All @@ -38,19 +42,36 @@ public CoagulatorRecipe(ItemStack itemOutput, FluidStack fluidInput, FluidStack
setDryingTime(this.itemOutput, dryingTime);
}

private static void setDryingTime(ItemStack output, int dryingTime)
private static void setDryingTime(ItemStack outputStack, int dryingTime)
{
Optional<Predicate<ItemStack>> found = bucketTimeMap.keySet().stream().filter(predicate -> predicate.test(output)).findFirst();
found.ifPresent(itemStackPredicate -> bucketTimeMap.remove(itemStackPredicate));
bucketTimeMap.put(output::isItemEqual, dryingTime);
for(DryingInformation information : dryingInformation)
if(information.outputPredicate.matchesItemStackIgnoringSize(outputStack))
{
information.time = dryingTime;
return;
}

IngredientStack outputPredicate = new IngredientStack(outputStack);
Optional<CoagulatorRecipe> first = streamRecipes(CoagulatorRecipe.class)
.filter(recipe -> outputPredicate.matchesItemStack(recipe.itemOutput))
.findFirst();

assert first.isPresent();

IILogger.error("Could not find drying information for stack "+outputStack);
dryingInformation.add(new DryingInformation(outputPredicate, first.get().fluidInput, dryingTime));
}

public static int getDryingTimeFor(ItemStack stack)
@Nonnull
public static DryingInformation getDryingInformationFor(ItemStack outputStack)
{
for(Predicate<ItemStack> predicate : bucketTimeMap.keySet())
if(predicate.test(stack))
return bucketTimeMap.get(predicate);
return Coagulator.bucketTime;
for(DryingInformation information : dryingInformation)
if(information.outputPredicate.matchesItemStackIgnoringSize(outputStack))
return information;

IILogger.error("Could not find drying information for stack "+outputStack);
return new DryingInformation(new IngredientStack(ItemStack.EMPTY),
new FluidStack(FluidRegistry.WATER, 1000), Coagulator.bucketTime);
}

@Nullable
Expand All @@ -66,4 +87,33 @@ protected IIRecipeLayout initRecipeLayout()
.withPowerInfo()
.build();
}

public static class DryingInformation
{
private final IngredientStack outputPredicate;
private final FluidStack fluid;
private int time;

public DryingInformation(IngredientStack outputPredicate, FluidStack fluid, int time)
{
this.outputPredicate = outputPredicate;
this.fluid = fluid;
this.time = time;
}

public IngredientStack getOutputPredicate()
{
return outputPredicate;
}

public FluidStack getFluid()
{
return fluid;
}

public int getTime()
{
return time;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,32 @@
import pl.pabilo8.immersiveintelligence.api.utils.tools.IPrecisionTool;
import pl.pabilo8.immersiveintelligence.common.IIConfigHandler.IIConfig.Machines.PrecisionAssembler;
import pl.pabilo8.immersiveintelligence.common.IIContent;
import pl.pabilo8.immersiveintelligence.common.util.amt.IIAnimation;
import pl.pabilo8.immersiveintelligence.common.util.IIReference;
import pl.pabilo8.immersiveintelligence.common.util.ResLoc;
import pl.pabilo8.immersiveintelligence.common.util.sound.IISoundAnimation;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Objects;

/**
* @author Pabilo8 (pabilo@iiteam.net)
* @since 08.08.2019
*/
public class PrecisionAssemblerRecipe extends IIMultiblockRecipe
{
public static HashMap<String, IPrecisionTool> toolMap = new HashMap<>();
private static HashMap<String, PrecisionToolInfo> TOOL_MAP = new HashMap<>();

public final ItemStack output, trashOutput;
public final IngredientStack[] inputs;
public final String[] tools;
private final String[] animations;
public final String toolHash;

public IISoundAnimation soundAnimation;
public IIAnimation animation;

public PrecisionAssemblerRecipe(ItemStack itemOutput, ItemStack trash, Object[] itemInputs, String[] tools, String[] animations, int energy, float timeMultiplier)
{
Expand All @@ -52,12 +57,13 @@ public PrecisionAssemblerRecipe(ItemStack itemOutput, ItemStack trash, Object[]
String[] split = animation.split(" ");
if(split.length < 2||split[0]==null)
continue;
if(toolMap.containsKey(split[0]))
processDuration += toolMap.get(split[0]).getWorkTime(split[0]);
if(TOOL_MAP.containsKey(split[0]))
processDuration += TOOL_MAP.get(split[0]).getWorkTime()+(PrecisionAssembler.toolMoveTime*2);
}

//Sort the tools for easier detection
this.toolHash = buildToolHash(tools);
this.animations = animations;
this.tools = tools;

setTimeAndEnergy((int)(processDuration*timeMultiplier), energy);
Expand All @@ -70,6 +76,11 @@ protected void loadClientSideContent()

}

public String[] getAnimations()
{
return animations;
}

public static String buildToolHash(String[] tools)
{
Arrays.sort(tools, String.CASE_INSENSITIVE_ORDER);
Expand All @@ -79,15 +90,30 @@ public static String buildToolHash(String[] tools)
return sb.toString();
}

public static void registerToolType(String name, IPrecisionTool tool)
public static PrecisionToolInfo[] toolsFromHash(String toolHash)
{
return Arrays.stream(toolHash.split(";"))
.map(PrecisionAssemblerRecipe::getToolByName)
.filter(Objects::nonNull)
.toArray(PrecisionToolInfo[]::new);
}

public static void registerToolType(IPrecisionTool tool, PrecisionToolInfo toolInfo)
{
TOOL_MAP.put(toolInfo.getToolName(), toolInfo);
}

@Nullable
public static PrecisionToolInfo getToolByName(String name)
{
toolMap.put(name, tool);
return TOOL_MAP.get(name);
}

@Nonnull
public static ItemStack getExampleToolStack(String name)
{
if(toolMap.containsKey(name))
return toolMap.get(name).getToolPresentationStack(name);
if(TOOL_MAP.containsKey(name))
return TOOL_MAP.get(name).getToolPresentationStack();
return ItemStack.EMPTY;
}

Expand All @@ -109,9 +135,8 @@ protected IIRecipeLayout initRecipeLayout()
for(int i = 0; i < 3; i++)
{
ItemStack tool = ItemStack.EMPTY;
if(tools.length > i&&PrecisionAssemblerRecipe.toolMap.containsKey(tools[i]))
tool = PrecisionAssemblerRecipe.toolMap.get(tools[i])
.getToolPresentationStack(tools[i]);
if(tools.length > i&&PrecisionAssemblerRecipe.TOOL_MAP.containsKey(tools[i]))
tool = getExampleToolStack(tools[i]);
builder.withSlot(50+i*20, 44, tool, IOType.INPUT, "frame"+i);
}

Expand All @@ -123,4 +148,48 @@ protected IIRecipeLayout initRecipeLayout()
.withPowerInfo()
.build();
}

@ParametersAreNonnullByDefault
public static class PrecisionToolInfo
{
private String toolName;
private ResLoc toolModelRes;
private ItemStack toolPresentationStack;
private int workTime;

public PrecisionToolInfo(String toolName, ItemStack toolPresentationStack, int workTime)
{
this(toolName, toolPresentationStack, workTime,
IIReference.RES_BLOCK_MODEL.with("multiblock/precision_assembler/tools/", toolName).withExtension(ResLoc.EXT_OBJ)
);
}

public PrecisionToolInfo(String toolName, ItemStack toolPresentationStack, int workTime, ResLoc toolModelRes)
{
this.toolName = toolName;
this.toolModelRes = toolModelRes;
this.toolPresentationStack = toolPresentationStack;
this.workTime = workTime;
}

public String getToolName()
{
return toolName;
}

public ResLoc getToolModelRes()
{
return toolModelRes;
}

public ItemStack getToolPresentationStack()
{
return toolPresentationStack;
}

public int getWorkTime()
{
return workTime;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package pl.pabilo8.immersiveintelligence.api.utils.tools;


import blusunrize.immersiveengineering.common.util.ItemNBTHelper;
import net.minecraft.item.ItemStack;

import static pl.pabilo8.immersiveintelligence.common.util.IIReference.NBT_DAMAGE;

/**
* @author Pabilo8 (pabilo@iiteam.net)
* @ii-approved 0.3.1
Expand All @@ -12,9 +15,24 @@ public interface IMachineTool
{
String getToolID(ItemStack stack);

void damageTool(ItemStack stack, int amount);
default void damageTool(ItemStack stack, int amount)
{
if(!ItemNBTHelper.hasKey(stack, NBT_DAMAGE))
ItemNBTHelper.setInt(stack, NBT_DAMAGE, getToolMaxDamage(stack));

ItemNBTHelper.setInt(stack, NBT_DAMAGE, getToolDamage(stack)-amount);

int getToolDamage(ItemStack stack);
if(getToolDamage(stack) < 0)
stack.setCount(0);
}

default int getToolDamage(ItemStack stack)
{
if(!ItemNBTHelper.hasKey(stack, NBT_DAMAGE))
return getToolMaxDamage(stack);
return ItemNBTHelper.getInt(stack, NBT_DAMAGE);
}

int getToolMaxDamage(ItemStack stack);

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package pl.pabilo8.immersiveintelligence.api.utils.tools;

import net.minecraft.item.ItemStack;
import pl.pabilo8.immersiveintelligence.common.util.ResLoc;

import javax.annotation.Nonnull;
import pl.pabilo8.immersiveintelligence.api.crafting.PrecisionAssemblerRecipe.PrecisionToolInfo;

/**
* @author Pabilo8 (pabilo@iiteam.net)
Expand All @@ -13,11 +11,5 @@
*/
public interface IPrecisionTool extends IMachineTool
{
int getWorkTime(String toolName);

@Nonnull
ItemStack getToolPresentationStack(String toolName);

@Nonnull
ResLoc getToolModelRes(String toolName);
PrecisionToolInfo getInfo(ItemStack toolStack);
}
Loading
Loading