Skip to content

Commit

Permalink
Merge remote-tracking branch 'head/fabric_1.19.x' into fabric_1.19.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
  • Loading branch information
wendavid552 committed Dec 20, 2023
2 parents c80859d + 57da52a commit 16e2814
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.0-SNAPSHOT'
id 'fabric-loom' version '1.1-SNAPSHOT'
}

sourceCompatibility = JavaVersion.VERSION_17
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ mod_file_name = itemscroller-fabric
mod_version = craftaddon-1.0.0

# Required malilib version
malilib_version = 0.14.0
malilib_version = 0.15.3

# Minecraft, Fabric and mappings versions
minecraft_version_out = 1.19.3
minecraft_version = 1.19.3
mappings_version = 1.19.3+build.2
minecraft_version_out = 1.19.4
minecraft_version = 1.19.4
mappings_version = 1.19.4+build.1

fabric_loader_version = 0.14.11
mod_menu_version = 5.0.1
fabric_loader_version = 0.14.17
mod_menu_version = 6.1.0-rc.4
1 change: 1 addition & 0 deletions src/main/java/fi/dy/masa/itemscroller/ItemScroller.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public class ItemScroller implements ModInitializer
public void onInitialize()
{
InitializationHandler.getInstance().registerInitializationHandler(new InitHandler());
fi.dy.masa.itemscroller.compat.carpet.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.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.ShulkerBoxBlock;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;

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 (FabricLoader.getInstance().isModLoaded("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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ private void renderStackAt(ItemStack stack, int x, int y, boolean border)

stack = stack.copy();
InventoryUtils.setStackSize(stack, 1);
this.mc.getItemRenderer().zOffset += 100;
this.mc.getItemRenderer().renderInGui(stack, x, y);
this.mc.getItemRenderer().zOffset -= 100;
MatrixStack matrixStack = new MatrixStack();
matrixStack.translate(0, 0, 100.f);
this.mc.getItemRenderer().renderInGui(matrixStack, stack, x, y);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private void renderFavoriteMarker(MatrixStack matrices, int mouseX, int mouseY,
int buttonsStartY = screenY + 16 + 2;
int x = buttonsStartX + 89 - 8;
int y = buttonsStartY + 2;
float z = this.getZOffset() + 300;
float z = 300;
IGuiIcon icon = favoriteData.isGlobal ? ItemScrollerIcons.STAR_5_PURPLE : ItemScrollerIcons.STAR_5_YELLOW;

for (int i = 0; i < (numFavorites - this.indexStartOffset); ++i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.HashSet;
import java.util.Arrays;
import javax.annotation.Nonnull;

import fi.dy.masa.itemscroller.compat.carpet.StackingShulkerBoxes;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -59,8 +61,9 @@ public void initializeRecipe() {
if (this.recipe[i].getItem().hasRecipeRemainder()) {
this.recipeRemainders.add(recipe[i].getItem().getRecipeRemainder());
}
if (this.recipe[i].getMaxCount() < maxCraftAmount) {
maxCraftAmount = this.recipe[i].getMaxCount();
int maxCount = StackingShulkerBoxes.getMaxCount(this.recipe[i]);
if (maxCount < maxCraftAmount) {
maxCraftAmount = maxCount;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.ArrayDeque;
import java.util.Queue;
import net.minecraft.client.MinecraftClient;
import net.minecraft.network.Packet;
import net.minecraft.network.packet.Packet;

public class ClickPacketBuffer
{
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 @@
],

"depends": {
"minecraft": "1.19.3",
"malilib": "0.14.x"
"minecraft": "1.19.4",
"malilib": "0.15.x"
}
}

0 comments on commit 16e2814

Please sign in to comment.