Skip to content

Commit

Permalink
- Some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Meloweh committed Nov 20, 2021
1 parent 5b094f7 commit 81188e7
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 98 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ minecraft_version=1.17.1
yarn_mappings=1.17.1+build.46
loader_version=0.11.6
# Mod Properties
mod_version=v1.7.0mel_3
mod_version=v1.7.0-meloweh-alpha.3
maven_group=adris.altoclef
archives_base_name=altoclef
# Dependencies
Expand Down
53 changes: 0 additions & 53 deletions src/main/java/adris/altoclef/tasks/CraftInInventoryTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,9 @@
import adris.altoclef.AltoClef;
import adris.altoclef.TaskCatalogue;
import adris.altoclef.tasks.resources.CollectRecipeCataloguedResourcesTask;
import adris.altoclef.tasks.slot.ClickSlotTask;
import adris.altoclef.tasks.slot.EnsureFreeInventorySlotTask;
import adris.altoclef.tasks.slot.MoveItemToSlotTask;
import adris.altoclef.tasks.slot.ThrowSlotTask;
import adris.altoclef.tasksystem.Task;
import adris.altoclef.trackers.InventoryTracker;
import adris.altoclef.util.*;
import adris.altoclef.util.slots.CraftingTableSlot;
import adris.altoclef.util.slots.PlayerSlot;
import adris.altoclef.util.slots.Slot;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeManager;
import net.minecraft.recipe.book.RecipeBook;
import net.minecraft.recipe.book.RecipeBookCategory;
import net.minecraft.screen.CraftingScreenHandler;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.util.collection.DefaultedList;

import java.util.*;

/**
* Crafts an item within the 2x2 inventory crafting grid.
Expand All @@ -38,9 +16,6 @@ public class CraftInInventoryTask extends ResourceTask {
private final boolean _collect;
private final boolean _ignoreUncataloguedSlots;
private boolean _fullCheckFailed = false;
private long idleTicks = 0;
private boolean lackingMatierals = false;
private boolean invChanged = false;
private long missingTicks = 0;

public CraftInInventoryTask(ItemTarget target, CraftingRecipe recipe, boolean collect, boolean ignoreUncataloguedSlots) {
Expand All @@ -64,38 +39,17 @@ protected void onResourceStart(AltoClef mod) {
_fullCheckFailed = false;
}

int ix = 0;
@Override
protected Task onResourceTick(AltoClef mod) {
ItemTarget toGet = _itemTargets[0];

//System.out.println(ix++);
//missingCount(mod);
/*
//RecipeManager.deserialize()
Recipe r = RecipesUtils.getRecipeWithOutput(new ItemStack(Items.OAK_PLANKS));
DefaultedList<Ingredient> l = r.getIngredients();
l.forEach(e -> Arrays.stream(e.getMatchingStacks()).forEach(a -> System.out.println(a.getItem().getName().toString())));
*/
//if (_collect && !mod.getInventoryTracker().hasRecipeMaterialsOrTarget(new RecipeTarget(toGet, _recipe)) || idleTicks > 300 && lackingMatierals && !invChanged) {
//System.out.println(isFullyCapableToCraft(mod, _recipe));
if (!mod.getInventoryTracker().isFullyCapableToCraft(mod, _recipe) && mod.getInventoryTracker().hasRecipeMaterialsOrTarget(new RecipeTarget(toGet, _recipe))) {
this.missingTicks++;
} else {
this.missingTicks = 0;
}

//System.out.println(this.missingTicks + " --- " + mod.getInventoryTracker().hasRecipeMaterialsOrTarget(new RecipeTarget(toGet, _recipe)));

/*
if (this.missingTicks > 150) {
System.out.println("H: " + (Utils.isNull(getMissingItemTarget(mod)) ? "null" : (Utils.isNull(getMissingItemTarget(mod).getMatches()) ? "null2" : getMissingItemTarget(mod).getMatches()[0].getName().toString())));
return null;
//return TaskCatalogue.getItemTask(new ItemTarget(Items.OAK_PLANKS, 2));
}*/

if (this.missingTicks > 150) {
//System.out.println("H: " + (Utils.isNull(getMissingItemTarget(mod)) ? "null" : (Utils.isNull(getMissingItemTarget(mod).getMatches()) ? "null2" : getMissingItemTarget(mod).getMatches()[0].getName().toString())));
if (Utils.isNull(mod.getInventoryTracker().getMissingItemTarget(mod, _recipe))) {
this.missingTicks = 0;
return null;
Expand All @@ -107,10 +61,6 @@ protected Task onResourceTick(AltoClef mod) {
}

if (_collect && !mod.getInventoryTracker().hasRecipeMaterialsOrTarget(new RecipeTarget(toGet, _recipe)) /*|| this.missingTicks > 250*//*!isFullyCapableToCraft(mod, _recipe)*/) {
// Collect recipe materials
//System.out.println("Y");
//if (this.missingTicks > 150) return TaskCatalogue.getItemTask(new ItemTarget(Items.OAK_LOG));

setDebugState("Collecting materials");
return collectRecipeSubTask(mod);
}
Expand All @@ -121,11 +71,8 @@ protected Task onResourceTick(AltoClef mod) {
}

setDebugState("Crafting in inventory... for " + toGet);
//System.out.println("CraftGenericTask");

return new CraftGenericTask(_recipe);
//return new CraftGenericTask(_recipe, collectRecipeSubTask(mod));
//craftInstant(mod, _recipe);
}

@Override
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/adris/altoclef/tasks/CraftInTableTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ protected boolean isContainerOpen(AltoClef mod) {

@Override
protected Task containerSubTask(AltoClef mod) {
//Debug.logMessage("GOT TO TABLE. Crafting...");

_craftResetTimer.setInterval(mod.getModSettings().getContainerItemMoveDelay() * 10 + CRAFT_RESET_TIMER_BONUS_SECONDS);
if (_craftResetTimer.elapsed()) {
Debug.logMessage("Refreshing crafting table.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ protected Task onTick(AltoClef mod) {
}
}

/*
if (storeInChestTaskDataPackage.getFeedback().equals(TaskDataPackage.Feedback.CHEST_LOST)
&& !(MinecraftClient.getInstance().world.getBlockState(chestPos).getBlock() instanceof ChestBlock)) {
return new PlaceBlockTask(chestPos, Blocks.CHEST);
}*/

storeInChestTaskDataPackage.setFinished(false);
return storeInTargetChestTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ protected List<ResourceTask> getSquashed(List<CraftInTableTask> tasks) {
targetRecipies.addAll(Arrays.asList(task.getRecipeTargets()));
}

//Debug.logMessage("Squashed " + targetRecipies.size());

return Collections.singletonList(new CraftInTableTask(targetRecipies.toArray(RecipeTarget[]::new)));
}
}
30 changes: 9 additions & 21 deletions src/main/java/adris/altoclef/trackers/InventoryTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
import adris.altoclef.util.baritone.BaritoneHelper;
import adris.altoclef.util.slots.*;
import baritone.utils.ToolSet;
import com.sun.jna.platform.win32.WinDef;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.*;
import net.minecraft.recipe.Ingredient;
Expand All @@ -39,11 +37,8 @@ public class InventoryTracker extends Tracker {
private int _emptySlots = 0;
private int _foodPoints = 0;

private long depthCounter = 0;
private boolean firstInvTimeElapsed = false;

//private long craftingTicks = 0;
//private boolean lackingRecipyMaterials = false;
//private long depthCounter = 0;
//private boolean firstInvTimeElapsed = false;

public final int getItemCountOfSlot(final Slot slot) {
if (Utils.isNull(slot)) return -1;
Expand All @@ -54,7 +49,7 @@ public final int getItemCountOfSlot(final Slot slot) {
}

//TODO: Needs reset if generic crafting process stopped
private Map<Long, DepthAttributes> depthAttributesMap = new HashMap<>();
//private Map<Long, DepthAttributes> depthAttributesMap = new HashMap<>();

public ItemTarget getMissingItemTarget(final AltoClef mod, final CraftingRecipe _recipe) {
final InventoryTracker inventory = mod.getInventoryTracker();
Expand Down Expand Up @@ -98,8 +93,8 @@ public ItemTarget getMissingItemTarget(final AltoClef mod, final CraftingRecipe
}

count = (int)Math.ceil(count / _recipe.getSlotCount());

//System.out.println(count + " --- " + mod.getInventoryTracker().getItemCount(toFill));

if (count > inventory.getItemCount(toFill) && inventory.getItemCount(toFill) > 0) {
return new ItemTarget(toFill, count);
}
Expand All @@ -114,11 +109,8 @@ private final boolean hasIngredientInAnyDepth(final Ingredient ingredient, final
for (final ItemStack itemStack : ingredient.getMatchingStacks()) {
if (Utils.isNull(itemStack)) continue;
if (Utils.isNull(itemStack.getItem())) continue;

//System.out.println(itemStack.getItem().getName().toString());
if (isSlotInAnyDepthSatisfiable(new ItemTarget(itemStack.getItem()/*, itemStack.getCount()*/), mod, blacklist, previouslyBlacklisted)) return true;
}
//System.out.println("is false");
return false;
}

Expand All @@ -133,11 +125,10 @@ private final boolean isSlotInList(final Slot slot, final List<Slot> list) {
//we can limit blacklisting to one stack = 64 since crafting slots are limited to it anyway.
private final boolean blacklistSatisfyingSlots(final List<Slot> blacklist, final List<Slot> previouslyBlacklisted, final ItemTarget itemTarget, final AltoClef mod) {
final List<Slot> slots = mod.getInventoryTracker().getInventorySlotsWithItem(itemTarget);
int size = 1; //itemTarget.getTargetCount();
int size = 1;

for (final Slot slot : slots) {
if (size > getItemCountOfSlotsInBlacklist(blacklist, mod)) {
//if (!blacklist.stream().anyMatch(e -> e.getInventorySlot() == slot.getInventorySlot())) {
if (!isSlotInList(slot, blacklist) && !isSlotInList(slot, previouslyBlacklisted)) {
blacklist.add(slot);
}
Expand All @@ -147,17 +138,12 @@ private final boolean blacklistSatisfyingSlots(final List<Slot> blacklist, final
}

return false;
//slots.removeIf(e -> mod.getInventoryTracker().getItemCount() >=)
}

private final boolean isSlotInAnyDepthSatisfiable(final ItemTarget itemTarget, final AltoClef mod, final List<Slot> blacklist, final List<Slot> previouslyBlacklisted) {
//System.out.println("tcount: " + itemTarget.getTargetCount());
//if (mod.getInventoryTracker().getItemCount(itemTarget) >= itemTarget.getTargetCount()) return true;

//coding style with side effect returns "is it satisfied"?
if (blacklistSatisfyingSlots(blacklist, previouslyBlacklisted, itemTarget, mod)) return true;

//Recursion may never terminates with false if "continue" when recipe equals null
for (final Item item : itemTarget.getMatches()) {
final Recipe recipe = RecipesUtils.getRecipeWithOutput(item.getDefaultStack());

Expand Down Expand Up @@ -191,6 +177,7 @@ public final boolean isFullyCapableToCraft(final AltoClef mod, final CraftingRec
return true;
}

/*
public boolean isFirstInvTimeElapsed() {
return this.firstInvTimeElapsed;
}
Expand Down Expand Up @@ -219,12 +206,13 @@ private class DepthAttributes {
public long craftingTicks = 0;
public boolean lackingRecipyMaterials = false;
public boolean prevInvTimeElapsed = false;
}
}*/

public InventoryTracker(TrackerManager manager) {
super(manager);
}

/*
public boolean loggedDepth() {
return depthAttributesMap.containsKey(depthCounter);
}
Expand Down Expand Up @@ -289,7 +277,7 @@ public final void resetCraftingTicks() {
public final boolean removeDepth() {
return !Utils.isNull(depthAttributesMap.remove(depthCounter));
}
}*/

private static Map<Item, Integer> getFuelTimeMap() {
if (_fuelTimeMap == null) {
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/adris/altoclef/util/InventoryWatcher.java

This file was deleted.

4 changes: 1 addition & 3 deletions src/main/java/adris/altoclef/util/RecipesUtils.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package adris.altoclef.util;

import adris.altoclef.AltoClef;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.CraftingRecipe;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeType;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

Expand All @@ -19,7 +17,7 @@
*
* @author Draco18s
*
* Modified by Meloweh
* Updated and modified by Meloweh
*
*/
public class RecipesUtils {
Expand Down

0 comments on commit 81188e7

Please sign in to comment.