Skip to content

Commit

Permalink
port to 1.21.2-pre.1 --> working on fixing mass Crafting
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Oct 9, 2024
1 parent 9b39aa5 commit a0e7d93
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 35 deletions.
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ author = masa
mod_file_name = itemscroller-fabric

# Current mod version
mod_version = 0.24.999-snap
mod_version = 0.24.59-alpha.1

# Required malilib version
malilib_version = 0.20.999-snap
malilib_id = 67cc3ca61a
malilib_version = 0.21.59-alpha.1
malilib_id = 14f11c739d

# Minecraft, Fabric Loader and API and mappings versions
minecraft_version_out = 24w40a
minecraft_version = 24w40a
mappings_version = 24w40a+build.9
minecraft_version_out = 1.21.2-pre1
minecraft_version = 1.21.2-pre1
mappings_version = 1.21.2-pre1+build.1

fabric_loader_version = 0.16.5
mod_menu_version = 12.0.0-alpha.1
# fabric_api_version = 0.105.2+1.21.2
# fabric_api_version = 0.105.3+1.21.2
18 changes: 18 additions & 0 deletions src/main/java/fi/dy/masa/itemscroller/data/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import net.minecraft.recipe.RecipeManager;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.RegistryKey;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;

import fi.dy.masa.malilib.network.ClientPlayHandler;
import fi.dy.masa.malilib.network.IPluginClientPlayHandler;
Expand Down Expand Up @@ -134,6 +136,22 @@ public String getServuxVersion()

public boolean hasServuxServer() { return this.servuxServer; }

public boolean hasIntegratedServer()
{
return mc.isIntegratedServerRunning();
}

public @Nullable ServerWorld getServerWorld()
{
if (this.hasIntegratedServer() &&
mc.getServer() != null && mc.world != null)
{
return mc.getServer().getWorld(mc.world.getRegistryKey());
}

return null;
}

/**
* Store's the world registry manager for Dynamic Lookup for various data
* Set this at WorldLoadPost
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fi.dy.masa.itemscroller.mixin;

import net.minecraft.client.gui.screen.recipebook.GhostRecipe;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
import net.minecraft.recipe.NetworkRecipeId;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -8,7 +9,6 @@
@Mixin(RecipeBookWidget.class)
public interface IMixinRecipeBookWidget
{
// FIXME
@Accessor("field_54830")
NetworkRecipeId itemscroller_getGhostSlots();
@Accessor("ghostRecipe")
GhostRecipe itemscroller_getGhostSlots();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fi.dy.masa.itemscroller.mixin;

import fi.dy.masa.itemscroller.util.InventoryUtils;

import net.minecraft.class_10352;
import net.minecraft.client.gui.screen.recipebook.AbstractCraftingRecipeBookWidget;
import net.minecraft.client.gui.screen.recipebook.GhostRecipe;
import net.minecraft.client.gui.screen.recipebook.RecipeResultCollection;
Expand All @@ -24,19 +26,19 @@ private void itemscroller_populateRecipes(RecipeResultCollection recipeResultCol
}
}


// FIXME -- Annoying code to deal with
// Seems to be (intended) bug from Mojang
@Inject(
method = "method_64868",
method = "showGhostRecipe",
at = @At("HEAD"),
cancellable = true
)
private void itemscroller_nShowGhostRecipe(GhostRecipe ghostRecipe, RecipeDisplay recipeDisplay, SlotDisplay.Context context, CallbackInfo ci)
private void itemscroller_onShowGhostRecipe(GhostRecipe ghostRecipe, RecipeDisplay recipeDisplay, class_10352 context, CallbackInfo ci)
{
/*
if (((IMixinRecipeBookWidget) this).itemscroller_getGhostSlots() == recipe) {
if (((IMixinRecipeBookWidget) this).itemscroller_getGhostSlots() == ghostRecipe)
{
ci.cancel();
}
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ private void onScreenHandlerSlotUpdate(ScreenHandlerSlotUpdateS2CPacket packet,
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ public abstract class MixinCraftingScreenHandler
private void onSlotChangedCraftingGrid(net.minecraft.inventory.Inventory inventory, CallbackInfo ci)
{
// FIXME
/*
if (MinecraftClient.getInstance().isOnThread())
{
InventoryUtils.onSlotChangedCraftingGrid(this.player,
((IMixinAbstractCraftingScreenHandler) this).itemscroller_getCraftingInventory(),
((IMixinAbstractCraftingScreenHandler) this).itemscroller_getCraftingResultInventory());
}
*/
}

// FIXME
Expand All @@ -43,11 +41,9 @@ private static void onUpdateResult(
ScreenHandler handler, ServerWorld serverWorld, PlayerEntity player, RecipeInputInventory craftingInventory, CraftingResultInventory resultInventory, RecipeEntry<CraftingRecipe> recipe, CallbackInfo ci)
{
// FIXME
/*
if (MinecraftClient.getInstance().isOnThread())
{
InventoryUtils.onSlotChangedCraftingGrid(player, craftingInventory, resultInventory);
}
*/
}
}
30 changes: 18 additions & 12 deletions src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.screen.slot.TradeOutputSlot;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.village.TradeOffer;
Expand All @@ -53,6 +54,7 @@
import fi.dy.masa.itemscroller.ItemScroller;
import fi.dy.masa.itemscroller.config.Configs;
import fi.dy.masa.itemscroller.config.Hotkeys;
import fi.dy.masa.itemscroller.data.DataManager;
import fi.dy.masa.itemscroller.mixin.IMixinCraftingResultSlot;
import fi.dy.masa.itemscroller.recipes.CraftingHandler;
import fi.dy.masa.itemscroller.recipes.CraftingHandler.SlotRange;
Expand Down Expand Up @@ -94,7 +96,6 @@ public static void setInhibitCraftingOutputUpdate(boolean inhibitUpdate)
}

// FIXME
/*
public static void onSlotChangedCraftingGrid(PlayerEntity player,
RecipeInputInventory craftMatrix,
CraftingResultInventory inventoryCraftResult)
Expand Down Expand Up @@ -122,15 +123,14 @@ public static void updateCraftingOutputSlot(Slot outputSlot)
updateCraftingOutputSlot(player, craftingInv, resultInv, true);
}
}
*/

// FIXME
/*
public static void updateCraftingOutputSlot(PlayerEntity player,
RecipeInputInventory craftMatrix,
CraftingResultInventory inventoryCraftResult,
boolean setEmptyStack)
{
ServerWorld serverWorld = DataManager.getInstance().getServerWorld();
World world = player.getEntityWorld();

if ((world instanceof ClientWorld) && player instanceof ClientPlayerEntity)
Expand All @@ -140,11 +140,19 @@ public static void updateCraftingOutputSlot(PlayerEntity player,
RecipeEntry<?> recipeEntry = null;
CraftingRecipeInput recipeInput = craftMatrix.createRecipeInput();

if (recipe == null || recipe.matches(recipeInput, world) == false)
if ((recipe == null || recipe.matches(recipeInput, world) == false) &&
(serverWorld != null))
{
Optional<RecipeEntry<CraftingRecipe>> opt = serverWorld.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, recipeInput, serverWorld);
recipe = opt.map(RecipeEntry::value).orElse(null);
recipeEntry = opt.orElse(null);
}
else if ((recipe == null || recipe.matches(recipeInput, world) == false) &&
(DataManager.getInstance().getPreparedRecipes() != null))
{
Optional<RecipeEntry<CraftingRecipe>> optional = world.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, recipeInput, world);
recipe = optional.map(RecipeEntry::value).orElse(null);
recipeEntry = optional.orElse(null);
Optional<RecipeEntry<CraftingRecipe>> opt = DataManager.getInstance().getPreparedRecipes().find(RecipeType.CRAFTING, recipeInput, world).findFirst();
recipe = opt.map(RecipeEntry::value).orElse(null);
recipeEntry = opt.orElse(null);
}

// TODO -- See if this works (GameRules)
Expand All @@ -153,8 +161,9 @@ public static void updateCraftingOutputSlot(PlayerEntity player,
GameRules rules = new GameRules(((ClientPlayerEntity) player).networkHandler.getEnabledFeatures());

if ((recipe.isIgnoredInRecipeBook() ||
rules.getBoolean(GameRules.DO_LIMITED_CRAFTING) == false ||
((ClientPlayerEntity) player).getRecipeBook().contains(recipeEntry)))
rules.getBoolean(GameRules.DO_LIMITED_CRAFTING) == false))
// FIXME
//|| ((ClientPlayerEntity) player).getRecipeBook().contains(recipeEntry)))
{
inventoryCraftResult.setLastRecipe(recipeEntry);
stack = recipe.craft(recipeInput, world.getRegistryManager());
Expand All @@ -170,7 +179,6 @@ public static void updateCraftingOutputSlot(PlayerEntity player,
lastRecipe = recipe;
}
}
*/

public static String getStackString(ItemStack stack)
{
Expand Down Expand Up @@ -1687,7 +1695,6 @@ public static void throwAllNonRecipeItemsToGround(RecipePattern recipe,
}

// FIXME
/*
public static void setCraftingGridContentsUsingSwaps(HandledScreen<? extends ScreenHandler> gui,
PlayerInventory inv,
RecipePattern recipe,
Expand Down Expand Up @@ -1760,7 +1767,6 @@ public static void setCraftingGridContentsUsingSwaps(HandledScreen<? extends Scr
}
}
}
*/

private static int putSingleItemIntoSlots(HandledScreen<? extends ScreenHandler> gui,
IntArrayList targetSlots,
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
],
"accessWidener": "itemscroller.accesswidener",
"depends": {
"minecraft": ">1.21.1",
"malilib": "0.20.999-snap"
"minecraft": "1.21.2-beta.1",
"malilib": "0.21.59-alpha.1"
}
}

0 comments on commit a0e7d93

Please sign in to comment.