Skip to content

Commit

Permalink
Merge pull request fr1kin#200 from fr1kin/breadcrumbs
Browse files Browse the repository at this point in the history
update from breadcrumbs branch
  • Loading branch information
babbaj authored Apr 26, 2020
2 parents d5e094a + 5ed7ed1 commit 96e357e
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 102 deletions.
13 changes: 9 additions & 4 deletions src/main/java/com/matt/forgehax/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import com.matt.forgehax.util.FileManager;
import com.matt.forgehax.util.command.CommandGlobal;
import com.matt.forgehax.util.mod.loader.ModManager;
import java.util.Optional;
import java.util.Scanner;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.PlayerControllerMP;
Expand All @@ -24,6 +21,10 @@
import net.minecraftforge.fml.client.FMLClientHandler;
import org.apache.logging.log4j.Logger;

import javax.annotation.Nullable;
import java.util.Optional;
import java.util.Scanner;

/**
* Created on 4/25/2017 by fr1kin
*/
Expand All @@ -48,7 +49,11 @@ public static FileManager getFileManager() {
public static Logger getLog() {
return LOGGER;
}


public static Entity getRenderEntity() {
return MC.getRenderViewEntity();
}

public static EntityPlayerSP getLocalPlayer() {
return MC.player;
}
Expand Down
88 changes: 43 additions & 45 deletions src/main/java/com/matt/forgehax/mods/AutoHotbarReplenish.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package com.matt.forgehax.mods;

import static com.matt.forgehax.Helper.getLocalPlayer;
import static com.matt.forgehax.Helper.getNetworkManager;

import com.matt.forgehax.util.command.Setting;
import com.matt.forgehax.util.entity.LocalPlayerInventory;
import com.matt.forgehax.util.entity.LocalPlayerInventory.InvItem;
import com.matt.forgehax.util.mod.Category;
import com.matt.forgehax.util.mod.ToggleMod;
import com.matt.forgehax.util.mod.loader.RegisterMod;
import com.matt.forgehax.util.task.TaskChain;
import java.util.Comparator;
import java.util.List;
import net.minecraft.inventory.ClickType;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.CPacketClickWindow;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;

import java.util.Comparator;
import java.util.List;

import static com.matt.forgehax.Helper.getLocalPlayer;
import static com.matt.forgehax.Helper.getNetworkManager;

@RegisterMod
public class AutoHotbarReplenish extends ToggleMod {

Expand Down Expand Up @@ -164,43 +165,41 @@ public void onTick(ClientTickEvent event) {
.filter(InvItem::nonNull)
.filter(this::isMonitoring)
.filter(item -> !isAboveThreshold(item))
.filter(
item ->
slots
.stream()
.filter(this::isMonitoring)
.filter(inv -> !inv.isItemDamageable() || isAboveThreshold(inv))
.anyMatch(item::isItemsEqual))
.filter(item ->
slots
.stream()
.filter(this::isMonitoring)
.filter(inv -> !inv.isItemDamageable() || isAboveThreshold(inv))
.anyMatch(item::isItemsEqual)
)
.max(Comparator.comparingInt(LocalPlayerInventory::getHotbarDistance))
.map(
hotbarItem ->
TaskChain.<Runnable>builder()
.then(
() -> {
// pick up item

verifyHotbar(hotbarItem);
click(
slots
.stream()
.filter(InvItem::nonNull)
.filter(this::isMonitoring)
.filter(hotbarItem::isItemsEqual)
.filter(inv -> !inv.isDamageable() || isAboveThreshold(inv))
.max(Comparator.comparingInt(this::getDamageOrCount))
.orElseThrow(RuntimeException::new),
0,
ClickType.PICKUP);
})
.then(
() -> {
// place item into hotbar

verifyHotbar(hotbarItem);
click(hotbarItem, 0, ClickType.PICKUP);
})
.then(this::tryPlacingHeldItem)
.build())
.map(hotbarItem ->
TaskChain.<Runnable>builder()
.then(() -> {
// pick up item

verifyHotbar(hotbarItem);
click(
slots
.stream()
.filter(InvItem::nonNull)
.filter(this::isMonitoring)
.filter(hotbarItem::isItemsEqual)
.filter(inv -> !inv.isDamageable() || isAboveThreshold(inv))
.max(Comparator.comparingInt(this::getDamageOrCount))
.orElseThrow(RuntimeException::new),
0,
ClickType.PICKUP
);
})
.then(() -> {
// place item into hotbar

verifyHotbar(hotbarItem);
click(hotbarItem, 0, ClickType.PICKUP);
})
.then(this::tryPlacingHeldItem)
.build())
.orElse(TaskChain.empty());
}

Expand Down Expand Up @@ -241,8 +240,8 @@ private static void clickWindow(
usedButtonIn,
modeIn,
clickedItemIn,
LocalPlayerInventory.getOpenContainer()
.getNextTransactionID(LocalPlayerInventory.getInventory())));
LocalPlayerInventory.getOpenContainer().getNextTransactionID(LocalPlayerInventory.getInventory()))
);
}

private static ItemStack click(InvItem item, int usedButtonIn, ClickType modeIn) {
Expand All @@ -254,8 +253,7 @@ private static ItemStack click(InvItem item, int usedButtonIn, ClickType modeIn)
item.getSlotNumber(),
usedButtonIn,
modeIn,
ret =
LocalPlayerInventory.getOpenContainer()
ret = LocalPlayerInventory.getOpenContainer()
.slotClick(item.getSlotNumber(), usedButtonIn, modeIn, getLocalPlayer()));
return ret;
}
Expand Down
Loading

0 comments on commit 96e357e

Please sign in to comment.