Skip to content

Commit

Permalink
updated to 1.21!
Browse files Browse the repository at this point in the history
  • Loading branch information
Auroali committed Jun 13, 2024
1 parent 54a139c commit c7bad33
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 50 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.5
yarn_mappings=1.20.5+build.1
minecraft_version=1.21
yarn_mappings=1.21+build.1
loader_version=0.15.11

# Mod Properties
mod_version=1.3.0
mod_version=1.4.0
maven_group=com.auroali.armourbundles
archives_base_name=armourbundles

# Dependencies
fabric_version=0.97.8+1.20.5
fabric_version=0.100.1+1.21
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.5 2024-06-03T19:05:20.8373791 Armour Bundles/Model Definitions
// 1.21 2024-06-13T14:22:24.738260322 Armour Bundles/Model Definitions
39530e3e6a62cfc8f57c9125df332d10c76ee1ee assets/armourbundles/models/item/armour_bundle_filled.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.5 2024-06-03T19:05:20.839345172 Armour Bundles/Language (en_us)
// 1.21 2024-06-13T14:22:24.73956727 Armour Bundles/Language (en_us)
b695aa25a0f50d7be46c7e5ba21766584179b8fe assets/armourbundles/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// 1.20.5 2024-06-03T19:05:20.838835695 Armour Bundles/Recipes
f11a03a58f40b23178f533beef5fe764ca1c12e4 data/armourbundles/advancements/recipes/combat/armour_bundle.json
e4279ec21c63935a74f5262f0fc626124c1bdfcb data/armourbundles/recipes/armour_bundle.json
// 1.21 2024-06-13T14:22:24.73920794 Armour Bundles/Recipes
f11a03a58f40b23178f533beef5fe764ca1c12e4 data/armourbundles/advancement/recipes/combat/armour_bundle.json
e4279ec21c63935a74f5262f0fc626124c1bdfcb data/armourbundles/recipe/armour_bundle.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.5 2024-06-03T19:05:20.838380805 Armour Bundles/Tags for minecraft:item
c013dba0137b2f23f55282fc0893a0d5e9fc3859 data/armourbundles/tags/items/armor_bundle_insertable.json
// 1.21 2024-06-13T14:22:24.738957302 Armour Bundles/Tags for minecraft:item
c013dba0137b2f23f55282fc0893a0d5e9fc3859 data/armourbundles/tags/item/armor_bundle_insertable.json
10 changes: 5 additions & 5 deletions src/main/java/com/auroali/armourbundles/ArmourBundles.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.component.DataComponentType;
import net.minecraft.component.ComponentType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.ItemStack;
Expand All @@ -25,19 +25,19 @@ public class ArmourBundles implements ModInitializer {
// todo: fix bundle doing the item changed anim, readd bundle contents view
public static final String MODID = "armourbundles";

public static final DataComponentType<ArmourBundleInventory> ARMOUR_BUNDLE_INVENTORY = DataComponentType
public static final ComponentType<ArmourBundleInventory> ARMOUR_BUNDLE_INVENTORY = ComponentType
.<ArmourBundleInventory>builder()
.codec(ItemStack.CODEC.listOf().xmap(ArmourBundleInventory::new, ArmourBundleInventory::stacks))
.packetCodec(ItemStack.PACKET_CODEC.collect(PacketCodecs.toList()).xmap(ArmourBundleInventory::new, ArmourBundleInventory::stacks))
.cache()
.build();
public static final DataComponentType<Integer> CURRENT_PROFILE = DataComponentType
public static final ComponentType<Integer> CURRENT_PROFILE = ComponentType
.<Integer>builder()
.codec(Codec.INT)
.packetCodec(PacketCodecs.VAR_INT)
.build();

public static final DataComponentType<Profiles> PROFILES = DataComponentType
public static final ComponentType<Profiles> PROFILES = ComponentType
.<Profiles>builder()
.codec(ArmourProfile.CODEC.listOf().xmap(Profiles::new, Profiles::profiles))
.cache()
Expand Down Expand Up @@ -82,6 +82,6 @@ public void onInitialize() {
}

public static Identifier id(String id) {
return new Identifier(MODID, id);
return Identifier.of(MODID, id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ArmourBundlesClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
ModelPredicateProviderRegistry.register(ArmourBundles.ARMOUR_BUNDLE, new Identifier("filled"), (stack, world, entity, seed) -> ArmourBundles.ARMOUR_BUNDLE.getFillPercent(stack));
ModelPredicateProviderRegistry.register(ArmourBundles.ARMOUR_BUNDLE, Identifier.of("filled"), (stack, world, entity, seed) -> ArmourBundles.ARMOUR_BUNDLE.getFillPercent(stack));

PROFILE_1 = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.armourprofiles.select.1",
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/auroali/armourbundles/ArmourProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static ArmourProfile fromNbt(NbtCompound compound) {
public static ArmourProfile generateFrom(PlayerEntity entity) {
ArmourProfile profile = new ArmourProfile();
for(EquipmentSlot slot : EquipmentSlot.values()) {
if(slot.getType() != EquipmentSlot.Type.ARMOR)
if(slot.getType() != EquipmentSlot.Type.HUMANOID_ARMOR)
continue;

ItemStack stack = entity.getEquippedStack(slot);
Expand Down
35 changes: 11 additions & 24 deletions src/main/java/com/auroali/armourbundles/items/ArmourBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
import com.auroali.armourbundles.ArmourBundles;
import com.auroali.armourbundles.ArmourProfile;
import com.auroali.armourbundles.items.tooltipdata.ArmourBundleTooltipData;
import net.minecraft.client.item.TooltipData;
import net.minecraft.client.item.TooltipType;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.EnchantmentEffectComponentTypes;
import net.minecraft.component.type.BundleContentsComponent;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.StackReference;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsage;
import net.minecraft.item.*;
import net.minecraft.item.tooltip.TooltipData;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.screen.slot.Slot;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
Expand All @@ -36,7 +34,7 @@ public class ArmourBundle extends Item {
public static final int MAX_SIZE = 12;
public static final int PROFILES = 3;
public static final int COOLDOWN_TICKS = 80;
public ArmourBundle(Settings settings) {
public ArmourBundle(net.minecraft.item.Item.Settings settings) {
super(settings);
}

Expand All @@ -61,7 +59,7 @@ public boolean onStackClicked(ItemStack stack, Slot slot, ClickType clickType, P
}
// if there isn't, we try to remove an item and place it into the slot
if(!slot.hasStack()) {
removeLastItem(stack).ifPresent(slot::setStack);
removeFirstItem(stack).ifPresent(slot::setStack);
playRemoveOneSound(player);
}
return false;
Expand All @@ -79,7 +77,7 @@ public boolean onClicked(ItemStack stack, ItemStack otherStack, Slot slot, Click
}

if(otherStack.isEmpty()) {
removeLastItem(stack).ifPresent(cursorStackReference::set);
removeFirstItem(stack).ifPresent(cursorStackReference::set);
playRemoveOneSound(player);
return true;
}
Expand All @@ -92,17 +90,6 @@ public boolean tryInsert(ItemStack bundle, ItemStack stack) {
bundle.set(ArmourBundles.ARMOUR_BUNDLE_INVENTORY, ArmourBundleInventory.create(inventory, stack.copy()));
return true;
}
// NbtCompound itemNbt = bundle.getOrCreateNbt();
// NbtList inventory;
// if(!itemNbt.contains("Inv"))
// inventory = new NbtList();
// else inventory = itemNbt.getList("Inv", NbtElement.COMPOUND_TYPE);
//
// if(!canItemBeInserted(inventory, stack))
// return false;
//
// inventory.add(stack.writeNbt(new NbtCompound()));
// itemNbt.put("Inv", inventory);
return false;
}

Expand All @@ -121,12 +108,12 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
return TypedActionResult.success(stack, world.isClient);
}

public Optional<ItemStack> removeLastItem(ItemStack bundle) {
public Optional<ItemStack> removeFirstItem(ItemStack bundle) {
ArmourBundleInventory inventory = bundle.get(ArmourBundles.ARMOUR_BUNDLE_INVENTORY);
if(inventory == null || inventory.stacks().isEmpty())
return Optional.empty();

ItemStack stack = inventory.stacks().getLast();
ItemStack stack = inventory.stacks().getFirst();
bundle.set(ArmourBundles.ARMOUR_BUNDLE_INVENTORY, inventory.remove(stack));
return Optional.of(stack);
}
Expand All @@ -150,7 +137,7 @@ public Optional<ArmourProfile> getProfile(int profileIdx, ItemStack bundle) {
// and the player's inventory, which seemed better suited for this
public void tryEquip(ItemStack bundle, PlayerEntity player, ArmourProfile profile) {
for(EquipmentSlot slot : EquipmentSlot.values()) {
if(slot.getType() != EquipmentSlot.Type.ARMOR)
if(slot.getType() != EquipmentSlot.Type.HUMANOID_ARMOR)
continue;

ItemStack current = player.getEquippedStack(slot);
Expand Down Expand Up @@ -192,7 +179,7 @@ public void tryEquip(ItemStack bundle, PlayerEntity player, ArmourProfile profil
}

public boolean canItemBeInserted(ArmourBundleInventory inv, ItemStack stack) {
return inv.stacks().size() < MAX_SIZE && (stack.getItem() instanceof ArmorItem || stack.isIn(ArmourBundles.VALID_ARMOUR_BUNDLE_ITEMS)) && !EnchantmentHelper.hasBindingCurse(stack);
return inv.stacks().size() < MAX_SIZE && (stack.getItem() instanceof ArmorItem || stack.isIn(ArmourBundles.VALID_ARMOUR_BUNDLE_ITEMS)) && !EnchantmentHelper.hasAnyEnchantmentsWith(stack, EnchantmentEffectComponentTypes.PREVENT_ARMOR_CHANGE);
}

public Iterable<ItemStack> getItemsInBundle(ItemStack bundle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,29 @@
import java.util.List;

public record ArmourBundleInventory(List<ItemStack> stacks) {
public static ArmourBundleInventory DEFAULT = new ArmourBundleInventory(Collections.emptyList());
public static ArmourBundleInventory create() {
return new ArmourBundleInventory(Collections.emptyList());
return DEFAULT;
}

public static ArmourBundleInventory create(List<ItemStack> stacks) {
if(stacks.isEmpty())
return DEFAULT;
return new ArmourBundleInventory(List.copyOf(stacks));
}

public static ArmourBundleInventory create(ArmourBundleInventory inventory, ItemStack stack) {
List<ItemStack> stacks = new ArrayList<>(inventory.stacks().size() + 1);
stacks.addAll(inventory.stacks);
stacks.add(stack);
stacks.addAll(inventory.stacks);
return create(stacks);
}

public ArmourBundleInventory remove(ItemStack stack) {
ArrayList<ItemStack> list = new ArrayList<>(stacks);
list.remove(stack);
if(list.isEmpty())
return DEFAULT;
return create(list);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@Environment(EnvType.CLIENT)
public class ArmourBundleTooltipComponent implements TooltipComponent {
private static final Identifier BACKGROUND_TEXTURE = new Identifier("container/bundle/background");
private static final Identifier BACKGROUND_TEXTURE = Identifier.of("container/bundle/background");
private static final int field_32381 = 4;
private static final int field_32382 = 1;
private static final int WIDTH_PER_COLUMN = 18;
Expand Down Expand Up @@ -85,8 +85,8 @@ private int getRows() {

@Environment(EnvType.CLIENT)
static enum SlotSprite {
BLOCKED_SLOT(new Identifier("container/bundle/blocked_slot"), 18, 20),
SLOT(new Identifier("container/bundle/slot"), 18, 20);
BLOCKED_SLOT(Identifier.of("container/bundle/blocked_slot"), 18, 20),
SLOT(Identifier.of("container/bundle/slot"), 18, 20);

public final Identifier texture;
public final int width;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.auroali.armourbundles.items.tooltipdata;

import com.auroali.armourbundles.items.ArmourBundleInventory;
import net.minecraft.client.item.TooltipData;
import net.minecraft.item.tooltip.TooltipData;

public record ArmourBundleTooltipData(ArmourBundleInventory inventory) implements TooltipData {
}
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
],
"depends": {
"fabricloader": ">=0.15.11",
"minecraft": "~1.20.5",
"java": ">=17",
"minecraft": "~1.21",
"java": ">=21",
"fabric-api": "*"
}
}

0 comments on commit c7bad33

Please sign in to comment.