From eaef0d9922c2e169c2bd1cbd16d6f14c33d3dc51 Mon Sep 17 00:00:00 2001 From: chronosacaria Date: Mon, 19 Aug 2024 00:46:30 -0400 Subject: [PATCH] Resolved Crash, Seemingly fixed #41, Version Bump - Resolved Crash related to trying to cast `ClientWorld` to `ServerWorld` - Resolving this appears to have resolved the issue present in Issue #41 --- gradle.properties | 2 +- .../artifacts/SatchelOfElementsItem.java | 36 +++++++++++-------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/gradle.properties b/gradle.properties index 690a451..2f75aac 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ minecraft_version=1.20.1 yarn_mappings=1.20.1+build.9 loader_version=0.14.21 # Mod Properties -mod_version=4.0.3 +mod_version=4.0.4 maven_group=chronosacaria archives_base_name=mcdar # Dependencies diff --git a/src/main/java/chronosacaria/mcdar/artifacts/SatchelOfElementsItem.java b/src/main/java/chronosacaria/mcdar/artifacts/SatchelOfElementsItem.java index ed3c91f..e4c8b3a 100644 --- a/src/main/java/chronosacaria/mcdar/artifacts/SatchelOfElementsItem.java +++ b/src/main/java/chronosacaria/mcdar/artifacts/SatchelOfElementsItem.java @@ -6,12 +6,12 @@ import chronosacaria.mcdar.api.McdarEnchantmentHelper; import chronosacaria.mcdar.enums.StatusInflictingArtifactID; import net.minecraft.client.item.TooltipContext; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUsageContext; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; import net.minecraft.world.World; import java.util.List; @@ -25,22 +25,30 @@ public SatchelOfElementsItem() { ); } - public TypedActionResult use (World world, PlayerEntity user, Hand hand){ - ItemStack itemStack = user.getStackInHand(hand); + @Override + public ActionResult useOnBlock (ItemUsageContext context) { + if (context.getPlayer() != null && context.getPlayer().getWorld().getServer() != null) { + ServerPlayerEntity user = context.getPlayer().getWorld().getServer().getPlayerManager().getPlayer(context.getPlayer().getUuid()); + if (user != null) { + Hand hand = user.getActiveHand(); + ItemStack itemStack = user.getStackInHand(hand); - if (user.totalExperience >= 15 || user.isCreative()) { - AOEHelper.satchelOfElementsEffects(user); + if (user.totalExperience >= 15 || user.isCreative()) { + AOEHelper.satchelOfElementsEffects(user); - if (!user.isCreative()) { - user.addExperience(-15); - itemStack.damage(1, user, (entity) -> entity.sendToolBreakStatus(hand)); + if (!user.isCreative()) { + user.addExperience(-15); + itemStack.damage(1, user, (entity) -> entity.sendToolBreakStatus(hand)); + } + McdarEnchantmentHelper.mcdar$cooldownHelper( + user, + this + ); + return ActionResult.CONSUME; + } } - McdarEnchantmentHelper.mcdar$cooldownHelper( - user, - this - ); } - return new TypedActionResult<>(ActionResult.SUCCESS, itemStack); + return ActionResult.PASS; } @Override