Skip to content

Commit

Permalink
sync with craft-fix fork
Browse files Browse the repository at this point in the history
  • Loading branch information
TexBlock committed Jul 16, 2024
1 parent 3e1100a commit c71e281
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 392 deletions.
15 changes: 0 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,6 @@ java {
withSourcesJar()
}

jar {
// add some additional metadata to the jar manifest
manifest {
attributes([
"Specification-Title" : project.mod_id,
"Specification-Vendor" : project.mod_author,
"Specification-Version" : "1",
"Implementation-Title" : project.name,
"Implementation-Version" : version,
"Implementation-Vendor" : project.mod_author,
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}

// configure the maven publication
publishing {
publications {
Expand Down
5 changes: 2 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ loom.platform=neoforge
yarn_mappings=1.20.4+build.3

# Mod Properties
mod_version=0.1.2
mod_version=0.1.3
maven_group=org.thinkingstudio.rocknroller
archives_base_name=RocknRoller
mod_id=rocknroller
mod_author=ThinkingStudio

modrinth_id=hYq29QmW
curseforge_id=916852

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/fi/dy/masa/itemscroller/ItemScroller.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fi.dy.masa.itemscroller;

import fi.dy.masa.itemscroller.compat.carpet.StackingShulkerBoxes;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import fi.dy.masa.malilib.event.InitializationHandler;
Expand All @@ -10,5 +11,6 @@ public class ItemScroller {
public static void onInitialize()
{
InitializationHandler.getInstance().registerInitializationHandler(new InitHandler());
StackingShulkerBoxes.init();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package fi.dy.masa.itemscroller.compat.carpet;

import net.minecraft.block.ShulkerBoxBlock;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.neoforged.fml.ModList;

import java.lang.invoke.*;
import java.util.function.Function;
import java.util.function.IntSupplier;

public class StackingShulkerBoxes {
public static boolean enabled = false;

public static void init(){
if (ModList.get().isLoaded("carpet")){
try {
enabled = true;
MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodHandle shulkerBoxHasItemsTarget = lookup.findStatic(Class.forName("carpet.helpers.InventoryHelper"), "shulkerBoxHasItems", MethodType.methodType(boolean.class, ItemStack.class));
shulkerBoxHasItems = (ItemStack stack) -> {
try {
return (Boolean) shulkerBoxHasItemsTarget.invokeWithArguments(stack);
} catch (Throwable e) {
throw new RuntimeException(e);
}
};
MethodHandle shulkerBoxStackSizeHandle = lookup.findStaticVarHandle(Class.forName("carpet.CarpetSettings"), "shulkerBoxStackSize", int.class).toMethodHandle(VarHandle.AccessMode.GET);
shulkerBoxStackSizeGetter = ()-> {
try {
return (int) shulkerBoxStackSizeHandle.invokeExact();
} catch (Throwable e) {
throw new RuntimeException(e);
}
};

} catch (Throwable e) {
e.printStackTrace();
}
}
}
private static IntSupplier shulkerBoxStackSizeGetter = null;
private static Function<ItemStack, Boolean> shulkerBoxHasItems = null;

/**
* @param stack {@link ItemStack}
* @return Stack size considering empty boxes stacking rule from carpet mod
* @author <a href="https://github.com/gnembon">gnembon</a>, <a href="https://github.com/vlad2305m">vlad2305m</a>
* @see <a href="https://https://github.com/gnembon/fabric-carpet/blob/master/src/main/java/carpet/mixins/Slot_stackableSBoxesMixin.java">Original implementation</a>
*/
public static int getMaxCount(ItemStack stack){
if (!enabled) return stack.getMaxCount();
int shulkerBoxStackSize = shulkerBoxStackSizeGetter.getAsInt();
if (shulkerBoxStackSize > 1 &&
stack.getItem() instanceof BlockItem &&
((BlockItem)stack.getItem()).getBlock() instanceof ShulkerBoxBlock &&
!shulkerBoxHasItems.apply(stack)
) {
return shulkerBoxStackSize;
}
return stack.getMaxCount();
}
}
24 changes: 7 additions & 17 deletions src/main/java/fi/dy/masa/itemscroller/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,32 @@ public class Configs implements IConfigHandler

public static class Generic
{
public static final ConfigBoolean CARPET_CTRL_Q_CRAFTING = new ConfigBoolean("carpetCtrlQCraftingEnabledOnServer", false, "Set to true if the server is running the Carpet mod,\nand has the ctrlQCrafting option enabled.\nThis just changes which method Item Scroller uses\nfor the Drop key + Shift + Right click crafting.");
public static final ConfigBoolean CLIENT_CRAFTING_FIX = new ConfigBoolean("clientCraftingFixOn1.12", true, "Enable updating the crafting recipe output directly on the client side.\nThis fixes the quick/mass crafting and right-click-to-craft-a-stack\nfeatures othrwise being broken in 1.12.");
public static final ConfigBoolean MASS_CRAFT_HOLD = new ConfigBoolean("massCraftHold", false, "Mass craft continuously");
public static final ConfigBoolean CRAFTING_RENDER_RECIPE_ITEMS = new ConfigBoolean("craftingRenderRecipeItems", true, "If enabled, then the recipe items are also rendered\nin the crafting recipe view.");
public static final ConfigBoolean MOD_MAIN_TOGGLE = new ConfigBoolean("modMainToggle", true, "Can disable all the functionality of the entire mod");
public static final ConfigBoolean MASS_CRAFT_INHIBIT_MID_UPDATES = new ConfigBoolean("massCraftInhibitMidUpdates", true, "Prevent recipe output slot updates in the middle of moving items\nto the crafting grid. This should reduce CPU usage\nbecause of not constantly querying the recipe after every grid change.");
public static final ConfigInteger MASS_CRAFT_INTERVAL = new ConfigInteger("massCraftInterval", 2, 1, 60, "The interval in game ticks the massCraft operation is repeated at");
public static final ConfigInteger MASS_CRAFT_ITERATIONS = new ConfigInteger("massCraftIterations", 36, 1, 256, "How many massCraft iterations/attempts to do per execution.\nWith unstackable items or a full inventory and \"small recipe\"\nthis will need to be larger, as a shift + click craft to the inventory\nmight only craft 1 or 2 items per operation.");
public static final ConfigBoolean MASS_CRAFT_SWAPS = new ConfigBoolean("massCraftSwapsOnly", false, "Uses a newer method of filling the crafting grid,\nusing only swap slot packets.\n\nNote: Due to only using slot swap packets,\nno partial crafts are possible! And also no\nstack splitting will happen, at all.");
public static final ConfigInteger PACKET_RATE_LIMIT = new ConfigInteger("packetRateLimit", 4, 1, 1024, "The limit of sent emulated slot click packets per game tick,\nif 'rateLimitClickPackets' is enabled");
public static final ConfigBoolean DROP_RECIPE_REMAINDER = new ConfigBoolean("dropRecipeRemainder", true, "If enabled, recipe remainders are dropped.");
public static final ConfigBoolean DROP_NON_RECIPE_ITEMS = new ConfigBoolean("dropNonRecipeItems", false, "If enabled, non recipe items in crafting grid are dropped.");
public static final ConfigInteger MASS_CRAFT_INTERVAL = new ConfigInteger("massCraftInterval", 1, 1, 60, "The interval in game ticks the massCraft operation is repeated at");
public static final ConfigBoolean SCROLL_CRAFT_STORE_RECIPES_TO_FILE = new ConfigBoolean("craftingRecipesSaveToFile", true, "If enabled, then the crafting features recipes are saved to a file\ninside minecraft/itemscroller/recipes_worldorservername.nbt.\nThis makes the recipes persistent across game restarts.");
public static final ConfigBoolean SCROLL_CRAFT_RECIPE_FILE_GLOBAL = new ConfigBoolean("craftingRecipesSaveFileIsGlobal", false, "If true, then the recipe file is global, instead\n of being saved per-world or server");
public static final ConfigBoolean RATE_LIMIT_CLICK_PACKETS = new ConfigBoolean("rateLimitClickPackets", false, "This is meant for compatibility with Spigot servers and similar,\nwhich apply rate limits to packets from the client.\nThis queues up the emulated slot click packets and sends\nthem rate limited over time. The limit per game tick can be set in 'packetRateLimit´.");
public static final ConfigBoolean REVERSE_SCROLL_DIRECTION_SINGLE = new ConfigBoolean("reverseScrollDirectionSingle", false, "Reverse the scrolling direction for single item mode.");
public static final ConfigBoolean REVERSE_SCROLL_DIRECTION_STACKS = new ConfigBoolean("reverseScrollDirectionStacks", false, "Reverse the scrolling direction for full stacks mode.");
public static final ConfigBoolean USE_RECIPE_CACHING = new ConfigBoolean("useRecipeCaching", true, "Enables caching the last used recipe in the crafting\nrecipe output item fetching code. This can help a lot\nwith lowering CPU usage when mass crafting stuff.");
public static final ConfigBoolean SLOT_POSITION_AWARE_SCROLL_DIRECTION = new ConfigBoolean("useSlotPositionAwareScrollDirection", false, "When enabled, the item movement direction depends\non the slots' y-position on screen. Might be derpy with more\ncomplex inventories, use with caution!");
public static final ConfigBoolean VILLAGER_TRADE_USE_GLOBAL_FAVORITES = new ConfigBoolean("villagerTradeUseGlobalFavorites", true, "Whether or not global (per-item-type) villager trade\nfavorites should be used.");
public static final ConfigBoolean VILLAGER_TRADE_LIST_REMEMBER_SCROLL = new ConfigBoolean("villagerTradeListRememberScrollPosition", true, "Remember and restore the last scroll position in the\ntrade list when re-opening the GUI");

public static final ImmutableList<IConfigValue> OPTIONS = ImmutableList.of(
CARPET_CTRL_Q_CRAFTING,
CLIENT_CRAFTING_FIX,
MASS_CRAFT_HOLD,
CRAFTING_RENDER_RECIPE_ITEMS,
MASS_CRAFT_INHIBIT_MID_UPDATES,
MASS_CRAFT_INTERVAL,
MASS_CRAFT_ITERATIONS,
MASS_CRAFT_SWAPS,
MOD_MAIN_TOGGLE,
PACKET_RATE_LIMIT,
RATE_LIMIT_CLICK_PACKETS,
DROP_RECIPE_REMAINDER,
DROP_NON_RECIPE_ITEMS,
SCROLL_CRAFT_STORE_RECIPES_TO_FILE,
SCROLL_CRAFT_RECIPE_FILE_GLOBAL,
REVERSE_SCROLL_DIRECTION_SINGLE,
REVERSE_SCROLL_DIRECTION_STACKS,
SLOT_POSITION_AWARE_SCROLL_DIRECTION,
USE_RECIPE_CACHING,
VILLAGER_TRADE_USE_GLOBAL_FAVORITES,
VILLAGER_TRADE_LIST_REMEMBER_SCROLL
);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/fi/dy/masa/itemscroller/config/Hotkeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Hotkeys
public static final ConfigHotkey CRAFT_EVERYTHING = new ConfigHotkey("craftEverything", "LEFT_CONTROL,C", GUI_NO_ORDER, "Craft everything possible once with the currently selected recipe");
public static final ConfigHotkey DROP_ALL_MATCHING = new ConfigHotkey("dropAllMatching", "LEFT_CONTROL,LEFT_SHIFT,Q", GUI_NO_ORDER, "Drop all stacks identical to the hovered stack");
public static final ConfigHotkey MASS_CRAFT = new ConfigHotkey("massCraft", "LEFT_CONTROL,LEFT_ALT,C", GUI_NO_ORDER, "Mass craft and throw out the results with the\ncurrently selected recipe as long as this\nkeybind is held down");
public static final ConfigHotkey MASS_CRAFT_TOGGLE = new ConfigHotkey("massCraftToggle", "", "Toggle mass craft");
public static final ConfigHotkey MOVE_CRAFT_RESULTS = new ConfigHotkey("moveCraftResults", "LEFT_CONTROL,M", GUI_NO_ORDER, "Move all of the currently selected recipe's\noutput items from the player inventory\nto the other inventory");
public static final ConfigHotkey RECIPE_VIEW = new ConfigHotkey("recipeView", "A", GUI_RELAXED, "Show the Item Scroller recipe GUI");
public static final ConfigHotkey SLOT_DEBUG = new ConfigHotkey("slotDebug", "LEFT_CONTROL,LEFT_ALT,LEFT_SHIFT,I", GUI_NO_ORDER, "Print debug info for the hovered slot or GUI");
Expand Down Expand Up @@ -57,6 +58,7 @@ public class Hotkeys
CRAFT_EVERYTHING,
DROP_ALL_MATCHING,
MASS_CRAFT,
MASS_CRAFT_TOGGLE,
MOVE_CRAFT_RESULTS,
RECIPE_VIEW,
SLOT_DEBUG,
Expand Down
18 changes: 1 addition & 17 deletions src/main/java/fi/dy/masa/itemscroller/event/InputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import fi.dy.masa.itemscroller.config.Hotkeys;
import fi.dy.masa.itemscroller.recipes.RecipeStorage;
import fi.dy.masa.itemscroller.util.AccessorUtils;
import fi.dy.masa.itemscroller.util.ClickPacketBuffer;
import fi.dy.masa.itemscroller.util.InputUtils;
import fi.dy.masa.itemscroller.util.InventoryUtils;
import fi.dy.masa.itemscroller.util.MoveAction;
Expand Down Expand Up @@ -115,17 +114,9 @@ private boolean handleInput(int keyCode, boolean keyState, double dWheel)
{
return false;
}

if (Configs.Generic.RATE_LIMIT_CLICK_PACKETS.getBooleanValue() &&
this.callbacks.functionalityEnabled())
{
ClickPacketBuffer.setShouldBufferClickPackets(true);
}


boolean cancel = this.handleInputImpl(keyCode, keyState, dWheel, mc);

ClickPacketBuffer.setShouldBufferClickPackets(false);

return cancel;
}

Expand Down Expand Up @@ -256,11 +247,6 @@ private boolean handleDragging(HandledScreen<?> gui, MinecraftClient mc, int mou
boolean cancel = false;
MoveAction action = InventoryUtils.getActiveMoveAction();

if (Configs.Generic.RATE_LIMIT_CLICK_PACKETS.getBooleanValue())
{
ClickPacketBuffer.setShouldBufferClickPackets(true);
}

if (InputUtils.isActionKeyActive(action))
{
cancel = InventoryUtils.dragMoveItems(gui, action, mouseX, mouseY, false);
Expand All @@ -270,8 +256,6 @@ else if (action != MoveAction.NONE)
InventoryUtils.stopDragging();
}

ClickPacketBuffer.setShouldBufferClickPackets(false);

return cancel;
}
}
Loading

0 comments on commit c71e281

Please sign in to comment.