Skip to content

Commit

Permalink
[v2.5.2+1.20] support minecraft 1.20.3/1.20.4 (#67)
Browse files Browse the repository at this point in the history
* bump fabric deps

* updated supported minecraft version

* bump up mod version

* remove override decorators
  • Loading branch information
Aton-Kish committed Dec 11, 2023
1 parent baaa46b commit 72ced10
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 197 deletions.
9 changes: 3 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ dependencies {
modImplementation "com.misterpemodder:shulkerboxtooltip-fabric:${project.shulker_box_tooltip_version}"
}

loom {
accessWidenerPath = file("src/main/resources/${project.mod_id}.accesswidener")
}

processResources {
inputs.property "version", project.version

Expand Down Expand Up @@ -154,7 +150,8 @@ curseforge {

addGameVersion "Fabric"
addGameVersion "Java 17"
addGameVersion "1.20.2"
addGameVersion "1.20.3"
addGameVersion "1.20.4"

relations {
requiredDependency "fabric-api"
Expand All @@ -178,7 +175,7 @@ modrinth {
versionType = "release"
changelog = "[v${project.version}](https://github.com/Aton-Kish/reinforced-shulker-boxes/releases/tag/v" + java.net.URLEncoder.encode(project.version, "UTF-8") + ")"

gameVersions = ["1.20.2"]
gameVersions = ["1.20.3", "1.20.4"]
loaders = ["fabric"]

dependencies {
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.2
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.1
loader_version=0.15.1

# Mod Properties
mod_version=2.5.1+1.20
mod_version=2.5.2+1.20
mod_id=reinfshulker
maven_group=atonkish.reinfshulker
archives_base_name=reinforced-shulker-boxes

# Dependencies
fabric_version=0.91.2+1.20.2
fabric_version=0.91.1+1.20.4
reinforced_core_version=3.1.3+1.20
reinforced_chests_version=2.4.3+1.20
quick_shulker_version=1.4.0-1.20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import atonkish.reinfshulker.block.ReinforcedShulkerBoxBlock;
Expand All @@ -21,8 +21,9 @@
@Mixin(ShulkerBoxBlock.class)
public class ShulkerBoxBlockMixin {
@Inject(method = "onBreak", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/BlockEntity;setStackNbt(Lnet/minecraft/item/ItemStack;)V"), locals = LocalCapture.CAPTURE_FAILHARD)
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfo info,
BlockEntity blockEntity, ShulkerBoxBlockEntity shulkerBoxBlockEntity, ItemStack itemStack) {
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player,
CallbackInfoReturnable<BlockState> cir, BlockEntity blockEntity,
ShulkerBoxBlockEntity shulkerBoxBlockEntity, ItemStack itemStack) {
if (blockEntity instanceof ReinforcedShulkerBoxBlockEntity) {
ReinforcedShulkerBoxBlockEntity entity = (ReinforcedShulkerBoxBlockEntity) blockEntity;
((ItemStackAccessor) (Object) itemStack)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
package atonkish.reinfshulker.recipe;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.NotImplementedException;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Sets;

import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.codecs.RecordCodecBuilder;

import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.RawShapedRecipe;
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.recipe.ShapedRecipe;
import net.minecraft.recipe.book.CraftingRecipeCategory;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.dynamic.Codecs;

public class ReinforcedShulkerBoxCraftingRecipe extends ShapedRecipe {
public ReinforcedShulkerBoxCraftingRecipe(String group, CraftingRecipeCategory category, int width, int height,
DefaultedList<Ingredient> ingredients, ItemStack result, boolean showNotification) {
super(group, category, width, height, ingredients, result, showNotification);
}
final RawShapedRecipe raw;

public ReinforcedShulkerBoxCraftingRecipe(String group, CraftingRecipeCategory category, int width, int height,
DefaultedList<Ingredient> ingredients, ItemStack result) {
this(group, category, width, height, ingredients, result, true);
public ReinforcedShulkerBoxCraftingRecipe(String group, CraftingRecipeCategory category, RawShapedRecipe raw,
ItemStack result, boolean showNotification) {
super(group, category, raw, result, showNotification);
this.raw = raw;
}

public ReinforcedShulkerBoxCraftingRecipe(String group, CraftingRecipeCategory category, RawShapedRecipe raw,
ItemStack result) {
this(group, category, raw, result, true);
}

@Override
public RecipeSerializer<?> getSerializer() {
return ModRecipeSerializer.REINFORCED_SHULKER_BOX;
}

private RawShapedRecipe getRaw() {
return this.raw;
}

@Override
public ItemStack craft(RecipeInputInventory recipeInputInventory, DynamicRegistryManager dynamicRegistryManager) {
ItemStack itemStack = this.getResult(dynamicRegistryManager).copy();
Expand All @@ -52,185 +49,46 @@ public ItemStack craft(RecipeInputInventory recipeInputInventory, DynamicRegistr
return itemStack;
}

@VisibleForTesting
static String[] removePadding(List<String> pattern) {
int i = Integer.MAX_VALUE;
int j = 0;
int k = 0;
int l = 0;

for (int m = 0; m < pattern.size(); ++m) {
String string = pattern.get(m);
i = Math.min(i, ReinforcedShulkerBoxCraftingRecipe.findFirstSymbol(string));
int n = ReinforcedShulkerBoxCraftingRecipe.findLastSymbol(string);
j = Math.max(j, n);
if (n < 0) {
if (k == m) {
++k;
}

++l;
continue;
}

l = 0;
}

if (pattern.size() == l) {
return new String[0];
}

String[] strings = new String[pattern.size() - l - k];

for (int o = 0; o < strings.length; ++o) {
strings[o] = pattern.get(o + k).substring(i, j + 1);
}

return strings;
}

private static int findFirstSymbol(String line) {
int i;
for (i = 0; i < line.length() && line.charAt(i) == ' '; ++i) {
}

return i;
}

private static int findLastSymbol(String pattern) {
int i;
for (i = pattern.length() - 1; i >= 0 && pattern.charAt(i) == ' '; --i) {
}

return i;
}

public static class Serializer implements RecipeSerializer<ReinforcedShulkerBoxCraftingRecipe> {
static final Codec<List<String>> PATTERN_CODEC;
static final Codec<String> KEY_ENTRY_CODEC;
private static final Codec<ReinforcedShulkerBoxCraftingRecipe> CODEC;
public static final Codec<ReinforcedShulkerBoxCraftingRecipe> CODEC = RecordCodecBuilder.create((instance) -> {
return instance
.group(Codecs.createStrictOptionalFieldCodec(Codec.STRING, "group", "").forGetter((recipe) -> {
return recipe.getGroup();
}), CraftingRecipeCategory.CODEC.fieldOf("category").orElse(CraftingRecipeCategory.MISC)
.forGetter((recipe) -> {
return recipe.getCategory();
}), RawShapedRecipe.CODEC.forGetter((recipe) -> {
return recipe.getRaw();
}), ItemStack.RECIPE_RESULT_CODEC.fieldOf("result").forGetter((recipe) -> {
return recipe.getResult(null);
}), Codecs.createStrictOptionalFieldCodec(Codec.BOOL, "show_notification", true)
.forGetter((recipe) -> {
return recipe.showNotification();
}))
.apply(instance, ReinforcedShulkerBoxCraftingRecipe::new);
});

public Codec<ReinforcedShulkerBoxCraftingRecipe> codec() {
return CODEC;
}

public ReinforcedShulkerBoxCraftingRecipe read(PacketByteBuf packetByteBuf) {
int i = packetByteBuf.readVarInt();
int j = packetByteBuf.readVarInt();
String string = packetByteBuf.readString();
CraftingRecipeCategory craftingRecipeCategory = (CraftingRecipeCategory) packetByteBuf
.readEnumConstant(CraftingRecipeCategory.class);
DefaultedList<Ingredient> defaultedList = DefaultedList.ofSize(i * j, Ingredient.EMPTY);

for (int k = 0; k < defaultedList.size(); ++k) {
defaultedList.set(k, Ingredient.fromPacket(packetByteBuf));
}

RawShapedRecipe rawShapedRecipe = RawShapedRecipe.readFromBuf(packetByteBuf);
ItemStack itemStack = packetByteBuf.readItemStack();
boolean bl = packetByteBuf.readBoolean();
return new ReinforcedShulkerBoxCraftingRecipe(string, craftingRecipeCategory, i, j, defaultedList,
itemStack, bl);
return new ReinforcedShulkerBoxCraftingRecipe(string, craftingRecipeCategory, rawShapedRecipe, itemStack,
bl);
}

public void write(PacketByteBuf packetByteBuf, ReinforcedShulkerBoxCraftingRecipe recipe) {
packetByteBuf.writeVarInt(recipe.getWidth());
packetByteBuf.writeVarInt(recipe.getHeight());
packetByteBuf.writeString(recipe.getGroup());
packetByteBuf.writeEnumConstant(recipe.getCategory());
Iterator<Ingredient> ingredientsIterator = recipe.getIngredients().iterator();

while (ingredientsIterator.hasNext()) {
Ingredient ingredient = ingredientsIterator.next();
ingredient.write(packetByteBuf);
}

recipe.getRaw().writeToBuf(packetByteBuf);
packetByteBuf.writeItemStack(recipe.getResult(null));
packetByteBuf.writeBoolean(recipe.showNotification());
}

static {
PATTERN_CODEC = Codec.STRING.listOf().flatXmap((rows) -> {
if (rows.size() > 3) {
return DataResult.error(() -> {
return "Invalid pattern: too many rows, 3 is maximum";
});
} else if (rows.isEmpty()) {
return DataResult.error(() -> {
return "Invalid pattern: empty pattern not allowed";
});
} else {
int i = ((String) rows.get(0)).length();
Iterator<String> rowsIterator = rows.iterator();

String string;
do {
if (!rowsIterator.hasNext()) {
return DataResult.success(rows);
}

string = rowsIterator.next();
if (string.length() > 3) {
return DataResult.error(() -> {
return "Invalid pattern: too many columns, 3 is maximum";
});
}
} while (i == string.length());

return DataResult.error(() -> {
return "Invalid pattern: each row must be the same width";
});
}
}, DataResult::success);
KEY_ENTRY_CODEC = Codec.STRING.flatXmap((keyEntry) -> {
if (keyEntry.length() != 1) {
return DataResult.error(() -> {
return "Invalid key entry: '" + keyEntry + "' is an invalid symbol (must be 1 character only).";
});
} else {
return " ".equals(keyEntry) ? DataResult.error(() -> {
return "Invalid key entry: ' ' is a reserved symbol.";
}) : DataResult.success(keyEntry);
}
}, DataResult::success);
CODEC = ShapedRecipe.Serializer.RawShapedRecipe.CODEC.flatXmap((recipe) -> {
String[] strings = ReinforcedShulkerBoxCraftingRecipe.removePadding(recipe.pattern());
int i = strings[0].length();
int j = strings.length;
DefaultedList<Ingredient> defaultedList = DefaultedList.ofSize(i * j, Ingredient.EMPTY);
Set<String> set = Sets.newHashSet(recipe.key().keySet());

for (int k = 0; k < strings.length; ++k) {
String string = strings[k];

for (int l = 0; l < string.length(); ++l) {
String string2 = string.substring(l, l + 1);
Ingredient ingredient = string2.equals(" ") ? Ingredient.EMPTY
: (Ingredient) recipe.key().get(string2);
if (ingredient == null) {
return DataResult.error(() -> {
return "Pattern references symbol '" + string2 + "' but it's not defined in the key";
});
}

set.remove(string2);
defaultedList.set(l + i * k, ingredient);
}
}

if (!set.isEmpty()) {
return DataResult.error(() -> {
return "Key defines symbols that aren't used in pattern: " + set;
});
} else {
ReinforcedShulkerBoxCraftingRecipe craftingRecipe = new ReinforcedShulkerBoxCraftingRecipe(
recipe.group(), recipe.category(), i, j, defaultedList,
recipe.result(), recipe.showNotification());
return DataResult.success(craftingRecipe);
}
}, (recipe) -> {
throw new NotImplementedException(
"Serializing ReinforcedShulkerBoxCraftingRecipe is not implemented yet.");
});
}
}
}
3 changes: 1 addition & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@
"environment": "client"
}
],
"accessWidener": "reinfshulker.accesswidener",

"depends": {
"fabricloader": ">=0.15.0",
"fabric-api": "*",
"minecraft": "~1.20.2",
"minecraft": "~1.20.3",
"java": ">=17"
},
"suggests": {
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/reinfshulker.accesswidener

This file was deleted.

0 comments on commit 72ced10

Please sign in to comment.