Skip to content

Commit

Permalink
Tooltips not showing problem fixed
Browse files Browse the repository at this point in the history
Crash while using Cactus Pickaxe Fixed
Attack Damage and Attack Speed Balanced
  • Loading branch information
rafaelmehdiyev committed Dec 24, 2024
1 parent b85ba5a commit 0c0676a
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -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<Text> 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<Text> 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"));
Expand All @@ -26,18 +27,29 @@ public static void addCactusSwordTooltip(ItemStack stack, World world, List<Text
tooltip.add(Text.translatable("item.rafaels-useful-cactus.cactus_sword.tooltip.thorn"));
}

public static void addCactusPickaxeTooltip(ItemStack stack, World world, List<Text> 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<Text> 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<Biome> 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;
}


}
27 changes: 18 additions & 9 deletions src/main/java/net/rafael/usefulcactus/item/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,45 @@ public class ModItems {
.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()
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
public static final Item CACTUS_HOE = registerItem("cactus_hoe", new HoeItem(
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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,36 +10,38 @@
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<Text> tooltip, TooltipType type) {
if (type == TooltipType.ADVANCED) {
CactusItemTooltips.addCactusPickaxeTooltip(stack, null, tooltip);
CactusItemTooltips.addCactusPickaxeTooltip(tooltip);
}
super.appendTooltip(stack, context, tooltip, type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public CactusSwordItem(ToolMaterial toolMaterial,float attackDamage, float attac
@Environment(EnvType.CLIENT)
public void appendTooltip(ItemStack stack, Item.TooltipContext context, List<Text> tooltip, TooltipType type) {
if (type == TooltipType.ADVANCED) {
CactusItemTooltips.addCactusSwordTooltip(stack, null, tooltip);
CactusItemTooltips.addCactusSwordTooltip(tooltip);
}
super.appendTooltip(stack, context, tooltip, type);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
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;
Expand All @@ -28,7 +29,7 @@ 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);
Expand All @@ -37,6 +38,7 @@ 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;
Expand All @@ -53,25 +55,29 @@ private void applyTimeDamageBonus(World world, LivingEntity target) {
}
}

@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) {
target.damage((ServerWorld)world,target.getDamageSources().magic(), 3.0f);
}
}

@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);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions src/main/resources/rafaels-useful-cactus.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"compatibilityLevel": "JAVA_21",
"mixins": [
"CactusBlockMixin",
"CactusSwordMixin",
"CactusPickaxeMixin"
"CactusSwordMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 0c0676a

Please sign in to comment.