diff --git a/src/main/java/net/rafael/usefulcactus/client/CactusItemTooltips.java b/src/main/java/net/rafael/usefulcactus/client/CactusItemTooltips.java index 195760c..f75abe3 100644 --- a/src/main/java/net/rafael/usefulcactus/client/CactusItemTooltips.java +++ b/src/main/java/net/rafael/usefulcactus/client/CactusItemTooltips.java @@ -1,21 +1,22 @@ package net.rafael.usefulcactus.client; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.item.ItemStack; -import net.minecraft.registry.tag.BiomeTags; +import net.minecraft.client.MinecraftClient; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.text.Text; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.BiomeKeys; import java.util.List; -@Environment(EnvType.CLIENT) public class CactusItemTooltips { - public static void addCactusSwordTooltip(ItemStack stack, World world, List tooltip) { - if (world != null && world.getBiome(world.getPlayerByUuid(world.getPlayers().get(0).getUuid()).getBlockPos()) - .isIn(BiomeTags.VILLAGE_DESERT_HAS_STRUCTURE)) { + public static void addCactusSwordTooltip(List tooltip) { + if (getBiomeAtPlayerPosition() != null && getBiomeAtPlayerPosition().matchesKey(BiomeKeys.DESERT)) + { + World world = getWorld(); tooltip.add(Text.translatable("item.rafaels-useful-cactus.cactus_sword.tooltip.desert")); - + long timeOfDay = world.getTimeOfDay() % 24000; if (timeOfDay >= 6000 && timeOfDay <= 6500) { tooltip.add(Text.translatable("item.rafaels-useful-cactus.cactus_sword.tooltip.noon")); @@ -26,18 +27,29 @@ public static void addCactusSwordTooltip(ItemStack stack, World world, List tooltip) { - if (world != null && world.getBiome(world.getPlayerByUuid(world.getPlayers().get(0).getUuid()).getBlockPos()) - .isIn(BiomeTags.VILLAGE_DESERT_HAS_STRUCTURE)) { - tooltip.add(Text.translatable("item.rafaels-useful-cactus.cactus_pickaxe.tooltip.desert")); + public static void addCactusPickaxeTooltip(List tooltip) { + if (getBiomeAtPlayerPosition() != null && getBiomeAtPlayerPosition().matchesKey(BiomeKeys.DESERT)) { + World world = getWorld(); tooltip.add(Text.translatable("item.rafaels-useful-cactus.cactus_pickaxe.tooltip.durability")); - + long timeOfDay = world.getTimeOfDay() % 24000; if (timeOfDay >= 6000 && timeOfDay <= 6500) { tooltip.add(Text.translatable("item.rafaels-useful-cactus.cactus_pickaxe.tooltip.noon")); - } else if (timeOfDay >= 0 && timeOfDay < 13000) { - tooltip.add(Text.translatable("item.rafaels-useful-cactus.cactus_pickaxe.tooltip.daytime")); } } } + + // For client-side using MinecraftClient instance + private static RegistryEntry getBiomeAtPlayerPosition() { + MinecraftClient client = MinecraftClient.getInstance(); + BlockPos playerPos = client.player != null ? client.player.getBlockPos() : null; + return getWorld().getBiome(playerPos); + } + + private static World getWorld() { + MinecraftClient client = MinecraftClient.getInstance(); + return client.world; + } + + } \ No newline at end of file diff --git a/src/main/java/net/rafael/usefulcactus/item/ModItems.java b/src/main/java/net/rafael/usefulcactus/item/ModItems.java index f255637..10ac7cb 100644 --- a/src/main/java/net/rafael/usefulcactus/item/ModItems.java +++ b/src/main/java/net/rafael/usefulcactus/item/ModItems.java @@ -22,27 +22,38 @@ public class ModItems { // Basic Items public static final Item CACTUS_SKIN = registerItem("cactus_skin", new Item(new Item.Settings() - .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_skin"))))); + .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_skin"))))); // Cactus Tool Items + + // Damange 0 -> 3 + // | Attack Speed | Value | +// |--------------|-------| +// | 0 | 4 | +// | -1 | 3 | +// | -2 | 2 | +// | -3 | 1 | +// | -4 | 0 | + + // Cactus Sword: 6 attack damage, 1.6 attack speed public static final Item CACTUS_SWORD = registerItem("cactus_sword", - new CactusSwordItem(ModToolMaterial.CACTUS_SKIN,3f, 2f,new Item.Settings() + new CactusSwordItem(ModToolMaterial.CACTUS_SKIN,3f, -2.6f,new Item.Settings() .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_sword"))))); // Cactus Pickaxe: 4 attack damage, 1.2 attack speed public static final Item CACTUS_PICKAXE = registerItem("cactus_pickaxe", new CactusPickaxeItem( - ModToolMaterial.CACTUS_SKIN,1, -2.8f, new Item.Settings() - .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_pickaxe"))))); + ModToolMaterial.CACTUS_SKIN,0.5f, -2.8f, new Item.Settings() + .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_pickaxe"))))); // Cactus Axe: 9 attack damage, 0.9 attack speed public static final Item CACTUS_AXE = registerItem("cactus_axe", new AxeItem( ModToolMaterial.CACTUS_SKIN,6, -3.1f, new Item.Settings() .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_axe"))))); - // Cactus Shovel: 4.5 attack damage, 1.0 attack speed + // Cactus Shovel: 4 attack damage, 1.0 attack speed public static final Item CACTUS_SHOVEL = registerItem("cactus_shovel", new ShovelItem( - ModToolMaterial.CACTUS_SKIN,1.5f, -3.0f, new Item.Settings() + ModToolMaterial.CACTUS_SKIN,1f, -3.0f, new Item.Settings() .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_shovel"))))); // Cactus Hoe: 1 attack damage, 1.0 attack speed @@ -50,31 +61,31 @@ public class ModItems { ModToolMaterial.CACTUS_SKIN,-2, -3.0f, new Item.Settings() .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_hoe"))))); - // Cactus Hammer: 12 attack damage, 0.9 attack speed + // Cactus Hammer: 7 attack damage, 0.6 attack speed public static final Item CACTUS_HAMMER = registerItem("cactus_hammer", new CactusHammerItem( - ModToolMaterial.CACTUS_SKIN,9, -3.1f, new Item.Settings() + ModToolMaterial.CACTUS_SKIN,4, -3.4f, new Item.Settings() .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_hammer"))))); - + // Cactus Armor Items public static final Item CACTUS_HELMET = registerItem("cactus_helmet", new ModArmorItem(ModArmorMaterials.CACTUS_SKIN_ARMOR_MATERIAL, EquipmentType.HELMET, new Item.Settings() - .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_helmet"))))); + .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_helmet"))))); public static final Item CACTUS_CHESTPLATE = registerItem("cactus_chestplate", new ArmorItem(ModArmorMaterials.CACTUS_SKIN_ARMOR_MATERIAL, EquipmentType.CHESTPLATE, new Item.Settings() - .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_chestplate"))))); + .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_chestplate"))))); public static final Item CACTUS_LEGGINGS = registerItem("cactus_leggings", new ArmorItem(ModArmorMaterials.CACTUS_SKIN_ARMOR_MATERIAL, EquipmentType.LEGGINGS, new Item.Settings() - .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_leggings"))))); + .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_leggings"))))); public static final Item CACTUS_BOOTS = registerItem("cactus_boots", new ArmorItem(ModArmorMaterials.CACTUS_SKIN_ARMOR_MATERIAL, EquipmentType.BOOTS, new Item.Settings() - .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_boots"))))); + .registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RafaelsUsefulCactus.MOD_ID, "cactus_boots"))))); /** * Registers an item with the game's item registry. @@ -92,9 +103,7 @@ private static Item registerItem(String name, Item item) { public static void registerModItems() { RafaelsUsefulCactus.LOGGER.info("Registering Mod Items for " + RafaelsUsefulCactus.MOD_ID); - ItemGroupEvents.modifyEntriesEvent(ItemGroups.INGREDIENTS).register(entries -> { - entries.add(CACTUS_SKIN); - }); + ItemGroupEvents.modifyEntriesEvent(ItemGroups.INGREDIENTS).register(entries -> entries.add(CACTUS_SKIN)); ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> { entries.add(CACTUS_SWORD); @@ -112,4 +121,4 @@ public static void registerModItems() { entries.add(CACTUS_HAMMER); }); } -} +} \ No newline at end of file diff --git a/src/main/java/net/rafael/usefulcactus/item/custom/CactusPickaxeItem.java b/src/main/java/net/rafael/usefulcactus/item/custom/CactusPickaxeItem.java index 736e1f4..5480e0b 100644 --- a/src/main/java/net/rafael/usefulcactus/item/custom/CactusPickaxeItem.java +++ b/src/main/java/net/rafael/usefulcactus/item/custom/CactusPickaxeItem.java @@ -1,7 +1,5 @@ package net.rafael.usefulcactus.item.custom; -import java.util.List; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.block.BlockState; @@ -12,37 +10,39 @@ import net.minecraft.item.PickaxeItem; import net.minecraft.item.ToolMaterial; import net.minecraft.item.tooltip.TooltipType; -import net.minecraft.registry.tag.BiomeTags; import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeKeys; import net.rafael.usefulcactus.client.CactusItemTooltips; +import java.util.List; + public class CactusPickaxeItem extends PickaxeItem { - public CactusPickaxeItem(ToolMaterial material,float attackDamage, float attackSpeed, Item.Settings settings) { + public CactusPickaxeItem(ToolMaterial material, float attackDamage, float attackSpeed, Item.Settings settings) { super(material, attackDamage, attackSpeed, settings); } -@Override -public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) { - if (miner instanceof PlayerEntity player) { - if (world.getBiome(player.getBlockPos()).isIn(BiomeTags.VILLAGE_DESERT_HAS_STRUCTURE)) { - // 20% chance to not consume durability - if (world.random.nextFloat() < 0.20f) { - return false; + @Override + public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) { + if (miner instanceof PlayerEntity player) { + if (world.getBiome(player.getBlockPos()).matchesKey(BiomeKeys.DESERT)) { + // 20% chance to not consume durability + if (world.random.nextFloat() < 0.20f) { + return false; + } } } + return super.postMine(stack, world, state, pos, miner); } - return super.postMine(stack, world, state, pos, miner); -} - @Override + @Override @Environment(EnvType.CLIENT) public void appendTooltip(ItemStack stack, Item.TooltipContext context, List tooltip, TooltipType type) { if (type == TooltipType.ADVANCED) { - CactusItemTooltips.addCactusPickaxeTooltip(stack, null, tooltip); + CactusItemTooltips.addCactusPickaxeTooltip(tooltip); } super.appendTooltip(stack, context, tooltip, type); } -} +} \ No newline at end of file diff --git a/src/main/java/net/rafael/usefulcactus/item/custom/CactusSwordItem.java b/src/main/java/net/rafael/usefulcactus/item/custom/CactusSwordItem.java index 9633b83..bbb261a 100644 --- a/src/main/java/net/rafael/usefulcactus/item/custom/CactusSwordItem.java +++ b/src/main/java/net/rafael/usefulcactus/item/custom/CactusSwordItem.java @@ -21,7 +21,7 @@ public CactusSwordItem(ToolMaterial toolMaterial,float attackDamage, float attac @Environment(EnvType.CLIENT) public void appendTooltip(ItemStack stack, Item.TooltipContext context, List tooltip, TooltipType type) { if (type == TooltipType.ADVANCED) { - CactusItemTooltips.addCactusSwordTooltip(stack, null, tooltip); + CactusItemTooltips.addCactusSwordTooltip(tooltip); } super.appendTooltip(stack, context, tooltip, type); } diff --git a/src/main/java/net/rafael/usefulcactus/mixin/CactusPickaxeMixin.java b/src/main/java/net/rafael/usefulcactus/mixin/CactusPickaxeMixin.java deleted file mode 100644 index 40f58fe..0000000 --- a/src/main/java/net/rafael/usefulcactus/mixin/CactusPickaxeMixin.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.rafael.usefulcactus.mixin; - -import net.minecraft.block.BlockState; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.PickaxeItem; -import net.minecraft.registry.tag.BiomeTags; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.world.World; -import net.rafael.usefulcactus.item.ModItems; -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.CallbackInfoReturnable; - -@Mixin(Item.class) -public class CactusPickaxeMixin { - - @Inject(method = "getMiningSpeed", at = @At("HEAD"), cancellable = true) - private void onGetMiningSpeed(ItemStack stack, BlockState state, CallbackInfoReturnable cir) { - if (!(stack.getItem() instanceof PickaxeItem) || stack.getItem() != ModItems.CACTUS_PICKAXE) { - return; - } - - PlayerEntity player = ((PlayerEntity)(Object)this); - World world = player.getWorld(); - - if (world.getBiome(player.getBlockPos()).isIn(BiomeTags.VILLAGE_DESERT_HAS_STRUCTURE)) { - float originalSpeed = cir.getReturnValue(); - cir.setReturnValue(originalSpeed * 1.25f); // 25% faster in deserts - } - } - -} \ No newline at end of file diff --git a/src/main/java/net/rafael/usefulcactus/mixin/CactusSwordMixin.java b/src/main/java/net/rafael/usefulcactus/mixin/CactusSwordMixin.java index 7646deb..c78e4db 100644 --- a/src/main/java/net/rafael/usefulcactus/mixin/CactusSwordMixin.java +++ b/src/main/java/net/rafael/usefulcactus/mixin/CactusSwordMixin.java @@ -5,20 +5,21 @@ import net.minecraft.entity.mob.HuskEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.SwordItem; -import net.minecraft.registry.tag.BiomeTags; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeKeys; import net.rafael.usefulcactus.effect.ModEffects; import net.rafael.usefulcactus.item.ModItems; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(SwordItem.class) public class CactusSwordMixin { - + @Inject(method = "postHit", at = @At("HEAD")) private void onPostHit(ItemStack stack, LivingEntity target, LivingEntity attacker, CallbackInfoReturnable cir) { if (!(stack.getItem() instanceof SwordItem) || stack.getItem() != ModItems.CACTUS_SWORD) { @@ -27,8 +28,8 @@ private void onPostHit(ItemStack stack, LivingEntity target, LivingEntity attack World world = target.getWorld(); BlockPos pos = target.getBlockPos(); - - if (world.getBiome(pos).isIn(BiomeTags.VILLAGE_DESERT_HAS_STRUCTURE)) { + + if (world.getBiome(pos).matchesKey(BiomeKeys.DESERT)) { applyTimeDamageBonus(world, target); applyDesertThornEffect(world, target); applyExtraDamageToHusks(target); @@ -37,28 +38,31 @@ private void onPostHit(ItemStack stack, LivingEntity target, LivingEntity attack } } + @Unique private void applyTimeDamageBonus(World world, LivingEntity target) { long timeOfDay = world.getTimeOfDay() % 24000; float bonus = 0; - + if (timeOfDay >= 0 && timeOfDay < 13000) { bonus = 1.0f; if (timeOfDay >= 6000 && timeOfDay <= 6500) { bonus = 2.0f; } } - + if (bonus > 0) { target.damage((ServerWorld)world,target.getDamageSources().magic(), bonus); } } + @Unique private void applyDesertThornEffect(World world, LivingEntity target) { if (world.getRandom().nextFloat() < 0.2f) { target.addStatusEffect(new StatusEffectInstance(ModEffects.DESERT_THORN, 200, 0, false, true, true)); } } + @Unique private void applyExtraDamageToHusks(LivingEntity target) { World world = target.getWorld(); if (target instanceof HuskEntity) { @@ -66,15 +70,17 @@ private void applyExtraDamageToHusks(LivingEntity target) { } } + @Unique private void applyBonusDamageOnSand(World world, BlockPos pos, LivingEntity target) { if (world.getBlockState(pos.down()).isIn(net.minecraft.registry.tag.BlockTags.SAND)) { target.damage((ServerWorld) world,target.getDamageSources().magic(), 1.5f); } } + @Unique private void reduceDurabilityLoss(World world, ItemStack stack) { if (world.getRandom().nextFloat() < 0.5f && stack.getDamage() > 0) { stack.setDamage(stack.getDamage() - 1); } } -} +} \ No newline at end of file diff --git a/src/main/resources/rafaels-useful-cactus.mixins.json b/src/main/resources/rafaels-useful-cactus.mixins.json index 497c809..308b2b4 100644 --- a/src/main/resources/rafaels-useful-cactus.mixins.json +++ b/src/main/resources/rafaels-useful-cactus.mixins.json @@ -4,8 +4,7 @@ "compatibilityLevel": "JAVA_21", "mixins": [ "CactusBlockMixin", - "CactusSwordMixin", - "CactusPickaxeMixin" + "CactusSwordMixin" ], "injectors": { "defaultRequire": 1