Skip to content

Commit

Permalink
sync with sakura-ryoko/itemscroller
Browse files Browse the repository at this point in the history
  • Loading branch information
TexBlock committed Aug 29, 2024
1 parent 77e75f4 commit 1fce49d
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
## Change
- update MaFgLib version
- sync with `sakura-ryoko/itemscroller` 1.21-sakura.8
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ publisher {
setChangelog(file("CHANGELOG.md").getText("UTF-8"))
setVersion("${project.version}")
setDisplayName("${project.version}")
setGameVersions(libs.versions.minecraft.range.get())
setGameVersions("1.21", "1.21.1")
setLoaders(loom.platform.get().id())
setCurseEnvironment("client")
setArtifact(remapJar)
Expand Down
15 changes: 6 additions & 9 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
[versions]

minecraft-range="1.21"

# Base properties
minecraft_version="1.21"
yarn_mappings="1.21+build.2"
minecraft_version="1.21.1"
yarn_mappings="1.21.1+build.3"
mappings_patch="1.21+build.4"
neoforge="21.0.167"
neoforge="21.1.31"

# Mod properties
version="0.1.7"
version="0.1.8"
maven-group="org.thinkingstudio.rocknroller"
archives-name="RocknRoller"

Expand All @@ -18,15 +15,15 @@ id-modrinth="hYq29QmW"
id-curseforge="916852"

# Mod dependencies
mafglib="0.1.21-mc1.21"
mafglib="0.1.22-mc1.21.1"
badpackets="neo-0.8.1"

# Libraries
jsr305="3.0.2"

# Gradle plugin
architectury-loom = "1.6-SNAPSHOT"
modpublisher = "2.1.+"
modpublisher = "2.+"

[libraries]
minecraft = { group = "com.mojang", name = "minecraft", version.ref = "minecraft_version" }
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/fi/dy/masa/itemscroller/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static class Generic
public static final ConfigInteger MASS_CRAFT_INTERVAL = new ConfigInteger("massCraftInterval", 2, 1, 60, "itemscroller.config.generic.comment.massCraftInterval").translatedName("itemscroller.config.generic.name.massCraftInterval");
public static final ConfigInteger MASS_CRAFT_ITERATIONS = new ConfigInteger("massCraftIterations", 36, 1, 256, "itemscroller.config.generic.comment.massCraftIterations").translatedName("itemscroller.config.generic.name.massCraftIterations");
public static final ConfigBoolean MASS_CRAFT_SWAPS = new ConfigBoolean("massCraftSwapsOnly", false, "itemscroller.config.generic.comment.massCraftSwapsOnly").translatedName("itemscroller.config.generic.name.massCraftSwapsOnly");
public static final ConfigBoolean MASS_CRAFT_RECIPE_BOOK = new ConfigBoolean("massCraftUseRecipeBook", false, "itemscroller.config.generic.comment.massCraftUseRecipeBook").translatedName("itemscroller.config.generic.name.massCraftUseRecipeBook");
public static final ConfigInteger PACKET_RATE_LIMIT = new ConfigInteger("packetRateLimit", 4, 1, 1024, "itemscroller.config.generic.comment.packetRateLimit").translatedName("itemscroller.config.generic.name.packetRateLimit");
public static final ConfigBoolean SCROLL_CRAFT_STORE_RECIPES_TO_FILE = new ConfigBoolean("craftingRecipesSaveToFile", true, "itemscroller.config.generic.comment.craftingRecipesSaveToFile").translatedName("itemscroller.config.generic.name.craftingRecipesSaveToFile");
public static final ConfigBoolean SCROLL_CRAFT_RECIPE_FILE_GLOBAL = new ConfigBoolean("craftingRecipesSaveFileIsGlobal", false, "itemscroller.config.generic.comment.craftingRecipesSaveFileIsGlobal").translatedName("itemscroller.config.generic.name.craftingRecipesSaveFileIsGlobal");
Expand All @@ -57,6 +58,7 @@ public static class Generic
MASS_CRAFT_INTERVAL,
MASS_CRAFT_ITERATIONS,
MASS_CRAFT_SWAPS,
MASS_CRAFT_RECIPE_BOOK,
MOD_MAIN_TOGGLE,
PACKET_RATE_LIMIT,
RATE_LIMIT_CLICK_PACKETS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import net.minecraft.screen.slot.Slot;
import fi.dy.masa.malilib.config.options.ConfigHotkey;
import fi.dy.masa.malilib.gui.GuiBase;
Expand All @@ -30,6 +32,8 @@ public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler

protected int massCraftTicker;

private boolean recipeBookClicks = false;

public static KeybindCallbacks getInstance()
{
return INSTANCE;
Expand Down Expand Up @@ -190,6 +194,9 @@ private static void debugPrintInv(RecipeInputInventory inv)
@Override
public void onClientTick(MinecraftClient mc)
{
if (InventoryUtils.dontUpdateRecipeBook > 0) {
--InventoryUtils.dontUpdateRecipeBook;
}
if (this.functionalityEnabled() == false || mc.player == null)
{
return;
Expand Down Expand Up @@ -223,9 +230,54 @@ public void onClientTick(MinecraftClient mc)
}

RecipePattern recipe = RecipeStorage.getInstance().getSelectedRecipe();

int limit = Configs.Generic.MASS_CRAFT_ITERATIONS.getIntegerValue();

if (Configs.Generic.MASS_CRAFT_SWAPS.getBooleanValue())
if (Configs.Generic.MASS_CRAFT_RECIPE_BOOK.getBooleanValue() && recipe.lookupVanillaRecipe(mc.world) != null)
{
InventoryUtils.dontUpdateRecipeBook = 2;
for (int i = 0; i < limit; ++i)
{
// todo
// InventoryUtils.tryClearCursor(gui);
// InventoryUtils.setInhibitCraftingOutputUpdate(true);
InventoryUtils.throwAllCraftingResultsToGround(recipe, gui);

RecipeInputInventory craftingInv = ((IMixinCraftingResultSlot) outputSlot).itemscroller_getCraftingInventory();
if (!recipe.getVanillaRecipe().matches(craftingInv.createRecipeInput(), mc.world))
{
CraftingHandler.SlotRange range = CraftingHandler.getCraftingGridSlots(gui, outputSlot);
final int invSlots = gui.getScreenHandler().slots.size();
final int rangeSlots = range.getSlotCount();

for (int j = 0, slotNum = range.getFirst(); j < rangeSlots && slotNum < invSlots; j++, slotNum++)
{
InventoryUtils.shiftClickSlot(gui, slotNum);

Slot slotTmp = gui.getScreenHandler().getSlot(slotNum);
ItemStack stack = slotTmp.getStack();
if (!stack.isEmpty())
{
InventoryUtils.dropStack(gui, slotNum);
}
}
}

mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, recipe.getVanillaRecipeEntry(), true);
// InventoryUtils.setInhibitCraftingOutputUpdate(false);
// InventoryUtils.updateCraftingOutputSlot(outputSlot);

craftingInv = ((IMixinCraftingResultSlot) outputSlot).itemscroller_getCraftingInventory();
if (recipe.getVanillaRecipe().matches(craftingInv.createRecipeInput(), mc.world))
{
break;
}

InventoryUtils.shiftClickSlot(gui, outputSlot.id);
recipeBookClicks = true;
}
}
else if (Configs.Generic.MASS_CRAFT_SWAPS.getBooleanValue())
{
for (int i = 0; i < limit; ++i)
{
Expand Down Expand Up @@ -301,4 +353,9 @@ public void onClientTick(MinecraftClient mc)
});
}
}

public void onPacket(ScreenHandlerSlotUpdateS2CPacket packet)
{
var mc = MinecraftClient.getInstance();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package fi.dy.masa.itemscroller.mixin;

import fi.dy.masa.itemscroller.config.Configs;
import fi.dy.masa.itemscroller.config.Hotkeys;
import fi.dy.masa.itemscroller.event.KeybindCallbacks;
import fi.dy.masa.itemscroller.util.InventoryUtils;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.packet.s2c.play.CraftFailedResponseS2CPacket;
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import net.minecraft.network.packet.s2c.play.InventoryS2CPacket;
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import net.minecraft.network.packet.s2c.play.StatisticsS2CPacket;
Expand All @@ -22,6 +27,26 @@ private void onPong(StatisticsS2CPacket packet, CallbackInfo ci)
}
}

@Inject(method = "onScreenHandlerSlotUpdate", at = @At("RETURN"))
private void onScreenHandlerSlotUpdate(ScreenHandlerSlotUpdateS2CPacket packet, CallbackInfo ci)
{
KeybindCallbacks.getInstance().onPacket(packet);
}

@Inject(
method = "onCraftFailedResponse",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/util/thread/ThreadExecutor;)V",
shift = At.Shift.AFTER
),
cancellable = true
)
private void onCraftFailedResponse(CraftFailedResponseS2CPacket packet, CallbackInfo ci)
{
// todo
}

@Inject(
method = "onInventory",
at = @At(
Expand All @@ -48,7 +73,7 @@ private void onInventory(InventoryS2CPacket packet, CallbackInfo ci)
),
cancellable = true
)
private void onScreenHandlerSlotUpdate(ScreenHandlerSlotUpdateS2CPacket packet, CallbackInfo ci)
private void onScreenHandlerSlotUpdateInvokeMainThread(ScreenHandlerSlotUpdateS2CPacket packet, CallbackInfo ci)
{
if (InventoryUtils.bufferInvUpdates)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,51 @@
package fi.dy.masa.itemscroller.mixin;

import fi.dy.masa.itemscroller.util.InventoryUtils;
import net.minecraft.client.gui.screen.recipebook.RecipeBookGhostSlots;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.screen.slot.Slot;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;

@Mixin(RecipeBookWidget.class)
public class MixinRecipeBookWidget
{
@Shadow @Final protected RecipeBookGhostSlots ghostSlots;

@Inject(method = "slotClicked", at = @At("HEAD"), cancellable = true)
private void onSlotClicked(Slot slot, CallbackInfo ci)
{
if (InventoryUtils.dontUpdateRecipeBook > 0)
{
ci.cancel();
}
}

@Inject(method = "update", at = @At("HEAD"), cancellable = true)
private void onUpdate(CallbackInfo ci)
{
if (InventoryUtils.dontUpdateRecipeBook > 0)
{
ci.cancel();
}
}

// Seems to be (intended) bug from Mojang
@Inject(
method = "showGhostRecipe",
at = @At("HEAD"),
cancellable = true
)
private void onShowGhostRecipe(RecipeEntry<?> recipe, List<Slot> slots, CallbackInfo ci) {
if (this.ghostSlots.getRecipe() == recipe) {
ci.cancel();
}
}
}
12 changes: 7 additions & 5 deletions src/main/java/fi/dy/masa/itemscroller/recipes/RecipePattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public void ensureRecipeSizeAndClearRecipe(int size)
this.clearRecipe();
}

private void lookupVanillaRecipe(World world) {
@Nullable
public <T extends RecipeInput> Recipe<T> lookupVanillaRecipe(World world) {
//Assume all recipes here are of type CraftingRecipe
this.vanillaRecipe = null;
var mc = MinecraftClient.getInstance();
int recipeSize;
Expand All @@ -69,17 +71,18 @@ else if (recipe.length == 9)
}
else
{
return;
return null;
}

for (RecipeEntry<CraftingRecipe> match : mc.world.getRecipeManager().getAllMatches(RecipeType.CRAFTING, CraftingRecipeInput.create(recipeSize, recipeSize, Arrays.asList(recipe)), world))
{
if (InventoryUtils.areStacksEqual(result, match.value().getResult(world.getRegistryManager())))
{
this.vanillaRecipe = match;
return;
return (Recipe<T>) match.value();
}
}
return null;
}

public void storeCraftingRecipe(Slot slot, HandledScreen<? extends ScreenHandler> gui, boolean clearIfEmpty)
Expand Down Expand Up @@ -152,7 +155,6 @@ public void readFromNBT(@Nonnull NbtCompound nbt, @Nonnull DynamicRegistryManage
}

this.result = ItemStack.fromNbtOrEmpty(registryManager, nbt.getCompound("Result"));
this.lookupVanillaRecipe(MinecraftClient.getInstance().world);
}
}

Expand Down Expand Up @@ -225,7 +227,7 @@ public RecipeEntry<?> getVanillaRecipeEntry()
@Nullable
public <T extends RecipeInput> Recipe<T> getVanillaRecipe()
{
if (vanillaRecipe == null)
if (recipe == null)
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class InventoryUtils
{
private static final Set<Integer> DRAGGED_SLOTS = new HashSet<>();
private static final int SERVER_SYNC_MAGIC = 45510;
public static int dontUpdateRecipeBook;

private static WeakReference<Slot> sourceSlotCandidate = null;
private static WeakReference<Slot> sourceSlot = null;
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ file = "META-INF/accesstransformer.cfg"
[[dependencies.rocknroller]]
modId = "neoforge"
type = "required"
versionRange = "[20.5,)"
versionRange = "[21,)"
ordering = "NONE"
side = "BOTH"

[[dependencies.rocknroller]]
modId = "minecraft"
type = "required"
versionRange = "[1.20.5,)"
versionRange = "[1.21,)"
ordering = "NONE"
side = "BOTH"

Expand Down

0 comments on commit 1fce49d

Please sign in to comment.