Skip to content

Commit

Permalink
Merge pull request #16 from milkev/1.21
Browse files Browse the repository at this point in the history
update to 1.21
  • Loading branch information
milkev authored Aug 3, 2024
2 parents 7cf3041 + 660843c commit 6ce06a7
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 45 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.5-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
}

Expand Down
22 changes: 11 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/develop/
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.15.7
# check these on https://fabricmc.net/use
minecraft_version=1.21
yarn_mappings=1.21+build.9
loader_version=0.15.11

#Fabric api
fabric_version=0.96.11+1.20.4
# Fabric API
fabric_version=0.100.8+1.21

# Mod Properties
mod_version = 1.3.0
mod_version = 1.3.1
maven_group = space.bbkr
archives_base_name = shulkercharm

# Dependencies
trinkets_version=3.8.1
pal_version=1.9.0
cardinal_components_version=5.4.0
cloth_config_version=12.0.111
trinkets_version=3.10.0
pal_version=1.10.0
cardinal_components_version=6.1.1
cloth_config_version=15.0.128
18 changes: 15 additions & 3 deletions src/main/java/space/bbkr/shulkercharm/ShulkerCharm.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package space.bbkr.shulkercharm;

import com.mojang.serialization.Codec;
import io.github.ladysnake.pal.AbilitySource;
import io.github.ladysnake.pal.Pal;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.component.ComponentType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroups;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
Expand All @@ -16,15 +19,24 @@
public class ShulkerCharm implements ModInitializer {
public static final String MODID = "shulkercharm";

public static final Identifier CHARM_FLIGHT_ID = new Identifier(MODID, "shulker_charm_flight");
public static final Identifier CHARM_FLIGHT_ID = Identifier.of(MODID, "shulker_charm_flight");

public static final AbilitySource CHARM_FLIGHT = Pal.getAbilitySource(CHARM_FLIGHT_ID);

public static final Item SHULKER_CHARM = Registry.register(Registries.ITEM, new Identifier(MODID, "shulker_charm"),
new ShulkerCharmItem(new Item.Settings().maxCount(1).rarity(Rarity.RARE)));
public static final Item SHULKER_CHARM = Registry.register(
Registries.ITEM,
Identifier.of(MODID, "shulker_charm"),
new ShulkerCharmItem(new Item.Settings().maxCount(1).rarity(Rarity.RARE).component(ShulkerCharm.SHULKER_CHARM_CHARGE, 0)));

public static ShulkerCharmConfig config;

//as of 1.20.5, NBT is no longer a thing? instead we get complicated component things
public static final ComponentType<Integer> SHULKER_CHARM_CHARGE = Registry.register(
Registries.DATA_COMPONENT_TYPE,
Identifier.of(MODID, "shulker_charm_charge"),
ComponentType.<Integer>builder().codec(Codec.INT).build()
);

@Override
public void onInitialize() {
AutoConfig.register(ShulkerCharmConfig.class, JanksonConfigSerializer::new);
Expand Down
24 changes: 11 additions & 13 deletions src/main/java/space/bbkr/shulkercharm/ShulkerCharmItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
import dev.emi.trinkets.api.SlotReference;
import dev.emi.trinkets.api.TrinketItem;
import io.github.ladysnake.pal.VanillaAbilities;
import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.annotation.Nullable;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableTextContent;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.List;

Expand Down Expand Up @@ -89,10 +87,9 @@ public int getMaxDurability() {
}

@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
if (context.isAdvanced()) {
int power = getPower(stack);
tooltip.add(Text.translatable("tooltip.shulkercharm.power", power, getMaxDurability()));
public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
if (type.isAdvanced()) {
tooltip.add(Text.translatable("tooltip.shulkercharm.power", getPower(stack), getMaxDurability()));
}
}

Expand All @@ -103,9 +100,7 @@ public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> too
*/
public int getPower(ItemStack stack) {
if (ShulkerCharm.config.rangeModifier == -1) return getMaxDurability();
NbtCompound tag = stack.getOrCreateNbt();
if (!tag.contains("Power", NbtType.INT)) tag.putInt("Power", 0);
return tag.getInt("Power");
return stack.getComponents().getOrDefault(ShulkerCharm.SHULKER_CHARM_CHARGE, 0);
}

/**
Expand All @@ -114,8 +109,11 @@ public int getPower(ItemStack stack) {
* @param power The amount of power it should have.
*/
public void setPower(ItemStack stack, int power) {
NbtCompound tag = stack.getOrCreateNbt();
tag.putInt("Power", Math.max(0, Math.min(power, getMaxDurability())));
if(power >= getMaxDurability()) {
stack.set(ShulkerCharm.SHULKER_CHARM_CHARGE, getMaxDurability());
} else {
stack.set(ShulkerCharm.SHULKER_CHARM_CHARGE, power);
}
}

/**
Expand Down
12 changes: 0 additions & 12 deletions src/main/resources/data/trinkets/slots/chest/necklace.json

This file was deleted.

10 changes: 5 additions & 5 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"mixins.shulkercharm.json"
],
"depends": {
"fabricloader": ">=0.14.21",
"fabricloader": ">=0.15.11",
"fabric": "*",
"minecraft": ">=1.20.2",
"trinkets": ">=3.8.0",
"cloth-config2": ">=12.0.111",
"playerabilitylib": ">=1.9.0"
"minecraft": "1.21.x",
"trinkets": ">=3.10.0",
"cloth-config2": ">=15.0.128",
"playerabilitylib": ">=1.10.0"
}
}

0 comments on commit 6ce06a7

Please sign in to comment.