From f24d17af1bb6c1a49fb42c9eb8cb8e4a77ee0f33 Mon Sep 17 00:00:00 2001 From: seymourimadeit Date: Wed, 3 Jul 2024 14:33:19 -0700 Subject: [PATCH] fix #25 --- changelog-1.21.txt | 3 ++- gradle.properties | 2 +- .../StopHoldingItemAfterAdmiring.java | 7 ++----- .../common/items/BucklerItem.java | 18 ++++++++---------- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/changelog-1.21.txt b/changelog-1.21.txt index 2d328bc..67ec658 100644 --- a/changelog-1.21.txt +++ b/changelog-1.21.txt @@ -1 +1,2 @@ -- Update to latest forge changes \ No newline at end of file +- Port to newest neoforge changes +- Fix crash with bucklers in servers \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index a995919..c3648af 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ minecraft_version=1.21 # as they do not follow standard versioning conventions. minecraft_version_range=[1.21, 1.22) # The Neo version must agree with the Minecraft version to get a valid artifact -neo_version=21.0.31-beta +neo_version=21.0.52-beta # The Neo version range can use any version of Neo as bounds or match the loader version range neo_version_range=[20.5.14,) # The loader version range can only use the major version of Neo/FML as bounds diff --git a/src/main/java/tallestred/piglinproliferation/common/entities/ai/behaviors/StopHoldingItemAfterAdmiring.java b/src/main/java/tallestred/piglinproliferation/common/entities/ai/behaviors/StopHoldingItemAfterAdmiring.java index e9bf099..96231d5 100644 --- a/src/main/java/tallestred/piglinproliferation/common/entities/ai/behaviors/StopHoldingItemAfterAdmiring.java +++ b/src/main/java/tallestred/piglinproliferation/common/entities/ai/behaviors/StopHoldingItemAfterAdmiring.java @@ -1,24 +1,21 @@ package tallestred.piglinproliferation.common.entities.ai.behaviors; -import net.minecraft.core.Holder; import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.ai.behavior.BehaviorControl; import net.minecraft.world.entity.ai.behavior.declarative.BehaviorBuilder; import net.minecraft.world.entity.ai.memory.MemoryModuleType; import net.minecraft.world.entity.monster.piglin.Piglin; import net.minecraft.world.entity.monster.piglin.StopHoldingItemIfNoLongerAdmiring; import net.minecraft.world.level.storage.loot.LootTable; -import net.neoforged.neoforge.common.ToolActions; +import net.neoforged.neoforge.common.ItemAbilities; import tallestred.piglinproliferation.common.entities.ai.AbstractPiglinAi; -import tallestred.piglinproliferation.common.entities.ai.PiglinAlchemistAi; public class StopHoldingItemAfterAdmiring extends StopHoldingItemIfNoLongerAdmiring { public static

BehaviorControl

create(AbstractPiglinAi

aiInstance, ResourceKey lootTableLocation) { return BehaviorBuilder.create((p_259197_) -> { return p_259197_.group(p_259197_.absent(MemoryModuleType.ADMIRING_ITEM)).apply(p_259197_, (p_259512_) -> { return (p_259681_, piglin, p_259451_) -> { - if (!piglin.getOffhandItem().isEmpty() && !piglin.getOffhandItem().canPerformAction(ToolActions.SHIELD_BLOCK)) { + if (!piglin.getOffhandItem().isEmpty() && !piglin.getOffhandItem().canPerformAction(ItemAbilities.SHIELD_BLOCK)) { aiInstance.stopHoldingOffHandItem(piglin, true, lootTableLocation); // else if (BehaviorHelper.canStopHoldingItemIfNoLongerAdmiring(!piglin.getOffhandItem().isEmpty() && !piglin.getOffhandItem().canPerformAction(net.minecraftforge.common.ToolActions.SHIELD_BLOCK), piglin)) // ModCompat.stopHoldingOffHandItem(piglin, true); diff --git a/src/main/java/tallestred/piglinproliferation/common/items/BucklerItem.java b/src/main/java/tallestred/piglinproliferation/common/items/BucklerItem.java index 8eb5f1f..cc2ee6c 100644 --- a/src/main/java/tallestred/piglinproliferation/common/items/BucklerItem.java +++ b/src/main/java/tallestred/piglinproliferation/common/items/BucklerItem.java @@ -31,8 +31,8 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions; +import net.neoforged.neoforge.common.ItemAbilities; import net.neoforged.neoforge.common.Tags; -import net.neoforged.neoforge.common.ToolActions; import tallestred.piglinproliferation.capablities.PPDataAttachments; import tallestred.piglinproliferation.client.PPSounds; import tallestred.piglinproliferation.client.particles.ParticleHelper; @@ -46,7 +46,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.UUID; import java.util.function.Consumer; import static tallestred.piglinproliferation.util.CodeUtilities.doubleToString; @@ -89,19 +88,18 @@ public static boolean isReady(ItemStack stack) { return stack.getOrDefault(PPComponents.BUCKLER_IS_READY, false); } - public static int startingChargeTicks(ItemStack stack) { + public static int startingChargeTicks(ItemStack stack, Level level) { int min = PPConfig.COMMON.minBucklerChargeTime.get(); int max = PPConfig.COMMON.maxBucklerChargeTime.get(); - assert Minecraft.getInstance().level != null; - return min + (((max - min) * stack.getEnchantmentLevel(PPEnchantments.getEnchant(PPEnchantments.TURNING, Minecraft.getInstance().level.registryAccess())) / 5)); + return min + (((max - min) * stack.getEnchantmentLevel(PPEnchantments.getEnchant(PPEnchantments.TURNING, level.registryAccess())) / 5)); } public static int getChargeTicks(ItemStack stack) { return stack.getOrDefault(PPComponents.BUCKLER_CHARGE_TICKS, 0); } - public static void setChargeTicks(ItemStack stack) { - setChargeTicks(stack, startingChargeTicks(stack)); + public static void setChargeTicks(ItemStack stack, Level level) { + setChargeTicks(stack, startingChargeTicks(stack, level)); } public static void setChargeTicks(ItemStack stack, int chargeTicks) { @@ -138,7 +136,7 @@ public static void bucklerBash(LivingEntity entity) { } if (!entity.isSilent()) entity.level().playSound(null, entity.getX(), entity.getY(), entity.getZ(), PPSounds.SHIELD_BASH.get(), entity.getSoundSource(), 0.5F, 0.8F + entity.getRandom().nextFloat() * 0.4F); - if (entityHit instanceof Player && entityHit.getUseItem().canPerformAction(ToolActions.SHIELD_BLOCK)) + if (entityHit instanceof Player && entityHit.getUseItem().canPerformAction(ItemAbilities.SHIELD_BLOCK)) ((Player) entityHit).disableShield(); } else { boolean isInMainHand = entity.getMainHandItem().getItem() instanceof BucklerItem; @@ -184,7 +182,7 @@ public BlockEntityWithoutLevelRenderer getCustomRenderer() { public ItemStack finishUsingItem(ItemStack stack, Level worldIn, LivingEntity entity) { ItemStack itemstack = super.finishUsingItem(stack, worldIn, entity); BucklerItem.setReady(stack, true); - BucklerItem.setChargeTicks(stack); + BucklerItem.setChargeTicks(stack, worldIn); CHARGE_SPEED_BOOST.get().resetTransientModifier(entity); CHARGE_JUMP_PREVENTION.get().resetTransientModifier(entity); INCREASED_KNOCKBACK_RESISTANCE.get().resetTransientModifier(entity); @@ -229,7 +227,7 @@ public List getDescription(ItemStack stack) { boolean isBang = stack.getEnchantmentLevel(PPEnchantments.getEnchant(PPEnchantments.BANG, minecraft.player.registryAccess())) > 0; ArrayList list = new ArrayList<>(); list.add(Component.translatable("item.piglinproliferation.buckler.desc.on_use").withStyle(ChatFormatting.GRAY)); - list.add(Component.literal(" ").append(Component.translatable("item.piglinproliferation.buckler.desc.charge_ability", doubleToString(ticksToSeconds(startingChargeTicks(stack)))).withStyle(ChatFormatting.DARK_GREEN))); + list.add(Component.literal(" ").append(Component.translatable("item.piglinproliferation.buckler.desc.charge_ability", doubleToString(ticksToSeconds(startingChargeTicks(stack, minecraft.player.level())))).withStyle(ChatFormatting.DARK_GREEN))); if (!isDetailed) list.add(Component.literal(" ").append(Component.translatable("item.piglinproliferation.buckler.desc.details", minecraft.options.keyShift.getTranslatedKeyMessage()).withStyle(ChatFormatting.GREEN))); else {