Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
seymourimadeit committed Jul 3, 2024
1 parent 7b02d3f commit f24d17a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
3 changes: 2 additions & 1 deletion changelog-1.21.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Update to latest forge changes
- Port to newest neoforge changes
- Fix crash with bucklers in servers
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<E extends Piglin> extends StopHoldingItemIfNoLongerAdmiring {
public static<P extends Piglin> BehaviorControl<P> create(AbstractPiglinAi<P> aiInstance, ResourceKey<LootTable> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -229,7 +227,7 @@ public List<Component> getDescription(ItemStack stack) {
boolean isBang = stack.getEnchantmentLevel(PPEnchantments.getEnchant(PPEnchantments.BANG, minecraft.player.registryAccess())) > 0;
ArrayList<Component> 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 {
Expand Down

0 comments on commit f24d17a

Please sign in to comment.