Skip to content

Commit

Permalink
update to 1.21 (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyHPi authored Aug 7, 2024
1 parent 3251579 commit 274594d
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 73 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ eclipse/
build.number
run/
.DS_Store
launch.json
launch.json
out/
.idea/
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
}

sourceCompatibility = JavaVersion.VERSION_17
Expand All @@ -9,6 +9,7 @@ repositories {
maven { url 'https://masa.dy.fi/maven' }
maven { url 'https://maven.terraformersmc.com/releases/' }
// maven { url 'https://maven.quiltmc.org/repository/release/' }
maven { url 'https://jitpack.io' }
}

dependencies {
Expand All @@ -17,7 +18,9 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}"
implementation "com.google.code.findbugs:jsr305:3.0.2"

modImplementation "fi.dy.masa.malilib:malilib-fabric-${project.minecraft_version_out}:${project.malilib_version}"
// modImplementation "fi.dy.masa.malilib:malilib-fabric-${project.minecraft_version_out}:${project.malilib_version}"
modImplementation "com.github.sakura-ryoko:malilib:${project.malilib_sr}"


// Fabric API. This is technically optional, but you probably want it anyway.
//modCompile "net.fabricmc.fabric-api:fabric-api:" + project.fabric_version
Expand Down
11 changes: 6 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ mod_version = craftfix-1.2.8

# Required malilib version
malilib_version = 0.18.0
malilib_sr=1.21-sakura.4

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

fabric_loader_version = 0.15.1
mod_menu_version = 9.0.0-pre.1
fabric_loader_version = 0.15.11
mod_menu_version = 11.0.1
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 2 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 @@ -13,6 +14,6 @@ public class ItemScroller implements ModInitializer
public void onInitialize()
{
InitializationHandler.getInstance().registerInitializationHandler(new InitHandler());
fi.dy.masa.itemscroller.compat.carpet.StackingShulkerBoxes.init();
StackingShulkerBoxes.init();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.ShulkerBoxBlock;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.ContainerComponent;
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 {
Expand All @@ -17,14 +18,6 @@ public static void init(){
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 {
Expand All @@ -39,8 +32,7 @@ public static void init(){
}
}
}
private static IntSupplier shulkerBoxStackSizeGetter = null;
private static Function<ItemStack, Boolean> shulkerBoxHasItems = null;
private static IntSupplier shulkerBoxStackSizeGetter = () -> 1; // avoid init fail cause NullPointerException

/**
* @param stack {@link ItemStack}
Expand All @@ -51,10 +43,10 @@ public static void init(){
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)
if (shulkerBoxStackSize > 1
&& stack.getItem() instanceof BlockItem
&& ((BlockItem)stack.getItem()).getBlock() instanceof ShulkerBoxBlock
&& stack.getOrDefault(DataComponentTypes.CONTAINER, ContainerComponent.DEFAULT).stream().findAny().isEmpty()
) {
return shulkerBoxStackSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import fi.dy.masa.itemscroller.util.AccessorUtils;
import fi.dy.masa.itemscroller.util.InputUtils;
import fi.dy.masa.itemscroller.util.InventoryUtils;
import org.joml.Matrix4fStack;

public class RenderEventHandler
{
Expand Down Expand Up @@ -51,10 +52,10 @@ public void renderRecipeView(DrawContext drawContext)

this.calculateRecipePositions(gui);

MatrixStack matrixStack = RenderSystem.getModelViewStack();
matrixStack.push();
matrixStack.translate(this.recipeListX, this.recipeListY, 0);
matrixStack.scale((float) this.scale, (float) this.scale, 1);
Matrix4fStack matrix4fStack = RenderSystem.getModelViewStack();
matrix4fStack.pushMatrix();
matrix4fStack.translate(this.recipeListX, this.recipeListY, 0);
matrix4fStack.scale((float) this.scale, (float) this.scale, 1);

String str = StringUtils.translate("itemscroller.gui.label.recipe_page", (first / countPerPage) + 1, recipes.getTotalRecipeCount() / countPerPage);

Expand All @@ -80,7 +81,7 @@ public void renderRecipeView(DrawContext drawContext)
this.renderRecipeItems(recipe, recipes.getRecipeCountPerPage(), gui, drawContext);
}

matrixStack.pop();
matrix4fStack.popMatrix();
RenderSystem.applyModelViewMatrix();
RenderSystem.enableBlend(); // Fixes the crafting book icon rendering
}
Expand All @@ -106,9 +107,9 @@ public void onDrawScreenPost(MinecraftClient mc, DrawContext drawContext)
final int recipeId = this.getHoveredRecipeId(mouseX, mouseY, recipes, gui);

float offset = 300f;
MatrixStack matrixStack = RenderSystem.getModelViewStack();
matrixStack.push();
matrixStack.translate(0, 0, offset);
Matrix4fStack matrix4fStack = RenderSystem.getModelViewStack();
matrix4fStack.pushMatrix();
matrix4fStack.translate(0, 0, offset);

if (recipeId >= 0)
{
Expand All @@ -126,7 +127,7 @@ else if (Configs.Generic.CRAFTING_RENDER_RECIPE_ITEMS.getBooleanValue())
}
}

matrixStack.pop();
matrix4fStack.popMatrix();
RenderSystem.applyModelViewMatrix();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import fi.dy.masa.itemscroller.recipes.RecipeStorage;
import fi.dy.masa.itemscroller.villager.VillagerDataStorage;
import fi.dy.masa.malilib.interfaces.IWorldLoadListener;
import net.minecraft.registry.DynamicRegistryManager;

public class WorldLoadListener implements IWorldLoadListener
{
Expand All @@ -16,7 +17,7 @@ public void onWorldLoadPre(@Nullable ClientWorld worldBefore, @Nullable ClientWo
// Quitting to main menu, save the settings before the integrated server gets shut down
if (worldBefore != null && worldAfter == null)
{
this.writeData();
this.writeData(worldBefore.getRegistryManager());
VillagerDataStorage.getInstance().writeToDisk();
}
}
Expand All @@ -27,24 +28,24 @@ public void onWorldLoadPost(@Nullable ClientWorld worldBefore, @Nullable ClientW
// Logging in to a world, load the data
if (worldBefore == null && worldAfter != null)
{
this.readStoredData();
this.readStoredData(worldAfter.getRegistryManager());
VillagerDataStorage.getInstance().readFromDisk();
}
}

private void writeData()
private void writeData(DynamicRegistryManager registryManager)
{
if (Configs.Generic.SCROLL_CRAFT_STORE_RECIPES_TO_FILE.getBooleanValue())
{
RecipeStorage.getInstance().writeToDisk();
RecipeStorage.getInstance().writeToDisk(registryManager);
}
}

private void readStoredData()
private void readStoredData(DynamicRegistryManager registryManager)
{
if (Configs.Generic.SCROLL_CRAFT_STORE_RECIPES_TO_FILE.getBooleanValue())
{
RecipeStorage.getInstance().readFromDisk();
RecipeStorage.getInstance().readFromDisk(registryManager);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum ItemScrollerIcons implements IGuiIcon
STAR_5_YELLOW (112, 18, 5, 5),
STAR_5_PURPLE (117, 18, 5, 5);

public static final Identifier TEXTURE = new Identifier(Reference.MOD_ID, "textures/gui/gui_widgets.png");
public static final Identifier TEXTURE = Identifier.splitOn("itemscroller:textures/gui/gui_widgets.png", ':');

private final int u;
private final int v;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fi.dy.masa.itemscroller.mixin;

import net.minecraft.recipe.CraftingRecipe;
import net.minecraft.recipe.RecipeEntry;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -31,7 +33,8 @@ private static void onUpdateResult(
World world,
PlayerEntity player,
RecipeInputInventory craftingInventory,
CraftingResultInventory resultInv,
CraftingResultInventory resultInventory,
RecipeEntry<CraftingRecipe> recipe,
CallbackInfo ci)
{
//InventoryUtils.onSlotChangedCraftingGrid(player, craftingInv, resultInv);
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/fi/dy/masa/itemscroller/recipes/RecipePattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.nbt.NbtList;
import net.minecraft.recipe.CraftingRecipe;
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
import fi.dy.masa.itemscroller.recipes.CraftingHandler.SlotRange;
Expand Down Expand Up @@ -117,7 +118,7 @@ public void copyRecipeFrom(RecipePattern other)
this.initializeRecipe();
}

public void readFromNBT(@Nonnull NbtCompound nbt)
public void readFromNBT(@Nonnull NbtCompound nbt, DynamicRegistryManager registryManager)
{
if (nbt.contains("Result", Constants.NBT.TAG_COMPOUND) && nbt.contains("Ingredients", Constants.NBT.TAG_LIST))
{
Expand All @@ -137,22 +138,23 @@ public void readFromNBT(@Nonnull NbtCompound nbt)

if (slot >= 0 && slot < this.recipe.length)
{
this.recipe[slot] = ItemStack.fromNbt(tag);
this.recipe[slot] = ItemStack.fromNbtOrEmpty(registryManager, tag);
}
}

this.result = ItemStack.fromNbt(nbt.getCompound("Result"));
this.result = ItemStack.fromNbtOrEmpty(registryManager, nbt.getCompound("Result"));
this.initializeRecipe();
}
}

@Nonnull
public NbtCompound writeToNBT(@Nonnull NbtCompound nbt)
public NbtCompound writeToNBT(DynamicRegistryManager registryManager)
{
NbtCompound nbt = new NbtCompound();

if (this.isValid())
{
NbtCompound tag = new NbtCompound();
this.result.writeNbt(tag);
NbtCompound tag = (NbtCompound) this.result.encode(registryManager);

nbt.putInt("Length", this.recipe.length);
nbt.put("Result", tag);
Expand All @@ -161,11 +163,12 @@ public NbtCompound writeToNBT(@Nonnull NbtCompound nbt)

for (int i = 0; i < this.recipe.length; i++)
{
if (InventoryUtils.isStackEmpty(this.recipe[i]) == false)
if (this.recipe[i].isEmpty() == false && InventoryUtils.isStackEmpty(this.recipe[i]) == false)
{
tag = new NbtCompound();
tag.copyFrom((NbtCompound) this.recipe[i].encode(registryManager));

tag.putInt("Slot", i);
this.recipe[i].writeNbt(tag);
tagIngredients.add(tag);
}
}
Expand Down
Loading

0 comments on commit 274594d

Please sign in to comment.