From 53d2203a40236704dd771fac0cfc5e57ad868d14 Mon Sep 17 00:00:00 2001 From: cnlimiter Date: Mon, 8 Apr 2024 00:41:06 +0800 Subject: [PATCH] feat(1.20.1-forged): add trace arrow --- .../api/common/item/BaseItemStackHandler.java | 2 +- .../common/entity/EndestPearlEntity.java | 13 ++-- .../common/entity/arrow/TraceArrowEntity.java | 14 ++--- ...InfinityItem.java => InfinityAxeItem.java} | 9 +-- ...InfinityItem.java => InfinityBowItem.java} | 61 +++++++++++++------ ...InfinityItem.java => InfinityHoeItem.java} | 5 +- ...nityItem.java => InfinityPickaxeItem.java} | 9 +-- ...inityItem.java => InfinityShovelItem.java} | 8 +-- ...finityItem.java => InfinitySwordItem.java} | 4 +- ...finityItem.java => InfinityTotemItem.java} | 4 +- ...rdSkullsItem.java => SkullsSwordItem.java} | 4 +- .../avaritia/init/handler/CapHandler.java | 31 ++++++++++ .../init/handler/InfinityHandler.java | 11 ++-- .../init/handler/ItemOverrideHandler.java | 14 ++--- .../mods/avaritia/init/registry/ModCaps.java | 17 ++++++ .../avaritia/init/registry/ModEntities.java | 2 +- .../mods/avaritia/init/registry/ModItems.java | 16 +++-- .../resources/META-INF/accesstransformer.cfg | 2 +- 18 files changed, 134 insertions(+), 92 deletions(-) rename src/main/java/committee/nova/mods/avaritia/common/item/tools/{AxeInfinityItem.java => InfinityAxeItem.java} (89%) rename src/main/java/committee/nova/mods/avaritia/common/item/tools/{BowInfinityItem.java => InfinityBowItem.java} (75%) rename src/main/java/committee/nova/mods/avaritia/common/item/tools/{HoeInfinityItem.java => InfinityHoeItem.java} (98%) rename src/main/java/committee/nova/mods/avaritia/common/item/tools/{PickaxeInfinityItem.java => InfinityPickaxeItem.java} (91%) rename src/main/java/committee/nova/mods/avaritia/common/item/tools/{ShovelInfinityItem.java => InfinityShovelItem.java} (91%) rename src/main/java/committee/nova/mods/avaritia/common/item/tools/{SwordInfinityItem.java => InfinitySwordItem.java} (98%) rename src/main/java/committee/nova/mods/avaritia/common/item/tools/{TotemInfinityItem.java => InfinityTotemItem.java} (82%) rename src/main/java/committee/nova/mods/avaritia/common/item/tools/{SwordSkullsItem.java => SkullsSwordItem.java} (95%) create mode 100644 src/main/java/committee/nova/mods/avaritia/init/handler/CapHandler.java create mode 100644 src/main/java/committee/nova/mods/avaritia/init/registry/ModCaps.java diff --git a/src/main/java/committee/nova/mods/avaritia/api/common/item/BaseItemStackHandler.java b/src/main/java/committee/nova/mods/avaritia/api/common/item/BaseItemStackHandler.java index 3124ea1b..277ebf1a 100644 --- a/src/main/java/committee/nova/mods/avaritia/api/common/item/BaseItemStackHandler.java +++ b/src/main/java/committee/nova/mods/avaritia/api/common/item/BaseItemStackHandler.java @@ -28,7 +28,7 @@ public class BaseItemStackHandler extends ItemStackHandler { private int[] outputSlots; public BaseItemStackHandler(int size) { - this(size, (Runnable) null); + this(size, null); } public BaseItemStackHandler(int size, Runnable onContentsChanged) { diff --git a/src/main/java/committee/nova/mods/avaritia/common/entity/EndestPearlEntity.java b/src/main/java/committee/nova/mods/avaritia/common/entity/EndestPearlEntity.java index a9786b39..c24660db 100644 --- a/src/main/java/committee/nova/mods/avaritia/common/entity/EndestPearlEntity.java +++ b/src/main/java/committee/nova/mods/avaritia/common/entity/EndestPearlEntity.java @@ -1,5 +1,6 @@ package committee.nova.mods.avaritia.common.entity; +import committee.nova.mods.avaritia.init.registry.ModDamageTypes; import committee.nova.mods.avaritia.init.registry.ModEntities; import committee.nova.mods.avaritia.init.registry.ModItems; import net.minecraft.core.BlockPos; @@ -31,11 +32,10 @@ public class EndestPearlEntity extends ThrowableItemProjectile { private LivingEntity shooter; - public EndestPearlEntity(EntityType p_37442_, Level p_37443_) { - super(p_37442_, p_37443_); + public EndestPearlEntity(EntityType entityType, Level level) { + super(entityType, level); } - public EndestPearlEntity(Level level, double x, double y, double z) { this(ModEntities.ENDER_PEARL.get(), level); setPos(x, y, z); @@ -47,13 +47,13 @@ public EndestPearlEntity(Level level, LivingEntity shooter) { } @Override - protected Item getDefaultItem() { + protected @NotNull Item getDefaultItem() { return ModItems.endest_pearl.get(); } @Override - public Packet getAddEntityPacket() { + public @NotNull Packet getAddEntityPacket() { return NetworkHooks.getEntitySpawningPacket(this); } @@ -66,7 +66,6 @@ public void setShooter(LivingEntity shooter) { this.shooter = shooter; } - @Override public void handleEntityEvent(byte pId) { if (pId == 3) { @@ -92,7 +91,6 @@ protected void onHitEntity(EntityHitResult pos) { GapingVoidEntity ent; if (shooter != null) { ent = new GapingVoidEntity(level(), shooter); - } else ent = new GapingVoidEntity(level()); Direction dir = entity.getDirection(); @@ -133,7 +131,6 @@ protected void onHitBlock(@NotNull BlockHitResult result) { ent.moveTo(pos.getX() + offset.x * 0.25, pos.getY() + offset.y * 0.25, pos.getZ() + offset.z * 0.25, getYRot(), 0.0F); level().addFreshEntity(ent); - remove(RemovalReason.KILLED); } } diff --git a/src/main/java/committee/nova/mods/avaritia/common/entity/arrow/TraceArrowEntity.java b/src/main/java/committee/nova/mods/avaritia/common/entity/arrow/TraceArrowEntity.java index a21d4cac..663c5df5 100644 --- a/src/main/java/committee/nova/mods/avaritia/common/entity/arrow/TraceArrowEntity.java +++ b/src/main/java/committee/nova/mods/avaritia/common/entity/arrow/TraceArrowEntity.java @@ -62,16 +62,16 @@ */ public class TraceArrowEntity extends AbstractArrow { - private static final EntityDataAccessor ID_EFFECT_COLOR; + private static final EntityDataAccessor ID_EFFECT_COLOR = SynchedEntityData.defineId(TraceArrowEntity.class, EntityDataSerializers.INT); + private static final EntityDataAccessor SPECTRAL_TIME = SynchedEntityData.defineId(TraceArrowEntity.class, EntityDataSerializers.INT);; + private static final EntityDataAccessor JUMP_COUNT = SynchedEntityData.defineId(TraceArrowEntity.class, EntityDataSerializers.INT); private Potion potion; private final Set effects; private boolean fixedColor; private LivingEntity homingTarget; private Vec3 seekOrigin; private int homingTime; - private static final EntityDataAccessor SPECTRAL_TIME; - private static final EntityDataAccessor JUMP_COUNT; - private static final List projectileAntiImmuneEntities; + private static final List projectileAntiImmuneEntities = Lists.newArrayList("minecraft:enderman", "minecraft:wither", "minecraft:ender_dragon", "draconicevolution:guardian_wither"); private final Entity owner = this.getOwner() == null ? this : this.getOwner(); public TraceArrowEntity(EntityType entityType, Level world) { @@ -682,10 +682,4 @@ private void destroyArrow() { } } - static { - ID_EFFECT_COLOR = SynchedEntityData.defineId(TraceArrowEntity.class, EntityDataSerializers.INT); - SPECTRAL_TIME = SynchedEntityData.defineId(TraceArrowEntity.class, EntityDataSerializers.INT); - JUMP_COUNT = SynchedEntityData.defineId(TraceArrowEntity.class, EntityDataSerializers.INT); - projectileAntiImmuneEntities = Lists.newArrayList("minecraft:enderman", "minecraft:wither", "minecraft:ender_dragon", "draconicevolution:guardian_wither"); - } } diff --git a/src/main/java/committee/nova/mods/avaritia/common/item/tools/AxeInfinityItem.java b/src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityAxeItem.java similarity index 89% rename from src/main/java/committee/nova/mods/avaritia/common/item/tools/AxeInfinityItem.java rename to src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityAxeItem.java index 3fd71d40..fcd287c5 100644 --- a/src/main/java/committee/nova/mods/avaritia/common/item/tools/AxeInfinityItem.java +++ b/src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityAxeItem.java @@ -1,14 +1,11 @@ package committee.nova.mods.avaritia.common.item.tools; import committee.nova.mods.avaritia.common.entity.ImmortalItemEntity; -import committee.nova.mods.avaritia.init.config.ModConfig; -import committee.nova.mods.avaritia.init.handler.InfinityHandler; import committee.nova.mods.avaritia.init.registry.ModEntities; import committee.nova.mods.avaritia.init.registry.ModItems; import committee.nova.mods.avaritia.util.ToolUtil; import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; @@ -19,17 +16,15 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.HashSet; - /** * Description: * Author: cnlimiter * Date: 2022/5/15 17:11 * Version: 1.0 */ -public class AxeInfinityItem extends AxeItem { +public class InfinityAxeItem extends AxeItem { - public AxeInfinityItem() { + public InfinityAxeItem() { super(Tier.INFINITY_PICKAXE, 10, -3.0f, (new Properties()) .stacksTo(1) .fireResistant()); diff --git a/src/main/java/committee/nova/mods/avaritia/common/item/tools/BowInfinityItem.java b/src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityBowItem.java similarity index 75% rename from src/main/java/committee/nova/mods/avaritia/common/item/tools/BowInfinityItem.java rename to src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityBowItem.java index bd8f5adb..de5782a8 100644 --- a/src/main/java/committee/nova/mods/avaritia/common/item/tools/BowInfinityItem.java +++ b/src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityBowItem.java @@ -5,7 +5,6 @@ import committee.nova.mods.avaritia.common.entity.arrow.TraceArrowEntity; import committee.nova.mods.avaritia.init.registry.ModEntities; import committee.nova.mods.avaritia.init.registry.ModItems; -import committee.nova.mods.avaritia.util.math.RayTracer; import net.minecraft.nbt.CompoundTag; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; @@ -16,17 +15,18 @@ import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.HumanoidArm; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.AbstractArrow; import net.minecraft.world.entity.projectile.Arrow; +import net.minecraft.world.entity.projectile.SpectralArrow; import net.minecraft.world.item.*; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.Level; -import net.minecraft.world.phys.BlockHitResult; import net.minecraftforge.event.ForgeEventFactory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -37,8 +37,8 @@ * Date: 2022/4/2 20:07 * Version: 1.0 */ -public class BowInfinityItem extends BowItem { - public BowInfinityItem() { +public class InfinityBowItem extends BowItem { + public InfinityBowItem() { super(new Properties() .stacksTo(1) .rarity(ModItems.COSMIC_RARITY) @@ -112,46 +112,50 @@ public Entity createEntity(Level level, Entity location, ItemStack stack) { public void releaseUsing(@NotNull ItemStack stack, @NotNull Level level, @NotNull LivingEntity entity, int timeLeft) { if (!level.isClientSide) { if (entity instanceof Player player) { - AbstractArrow arrowEntity; - ItemStack ammoStack = player.getProjectile(stack); int drawTime = this.getUseDuration(stack) - timeLeft; drawTime = ForgeEventFactory.onArrowLoose(stack, level, player, drawTime, true); if (drawTime < 0) { return; } + float VELOCITY_MULTIPLIER = 1.2F; float DAMAGE_MULTIPLIER = 5000.0F; float draw = getPowerForTime(drawTime); float powerForTime = draw * VELOCITY_MULTIPLIER; - if (ammoStack.isEmpty()) { - ammoStack = new ItemStack(Items.ARROW); - } - if (stack.getOrCreateTag().getBoolean("tracer")) { + ItemStack ammoStack = player.getProjectile(stack).isEmpty() ? new ItemStack(Items.ARROW) : player.getProjectile(stack); + + AbstractArrow arrowEntity; + + if (stack.getOrCreateTag().getBoolean("tracer")) { if ((double)powerForTime >= 0.1D) { - ArrowItem arrowitem = (ArrowItem)(ammoStack.getItem() instanceof ArrowItem ? ammoStack.getItem() : Items.ARROW); - arrowEntity = this.customArrow(arrowitem.createArrow(level, ammoStack, entity)); + ArrowItem arrowitem = (ammoStack.getItem() instanceof ArrowItem arrowItem ? arrowItem : (ArrowItem) Items.ARROW); + arrowEntity = this.customTraceArrow(arrowitem.createArrow(level, ammoStack, player)); if (arrowEntity instanceof Arrow arrow2) { arrow2.setEffectsFromItem(ammoStack); } else if (arrowEntity instanceof TraceArrowEntity infinityArrow) { infinityArrow.setEffectsFromItem(ammoStack); } + arrowEntity.shootFromRotation(player, player.getXRot(), player.getYRot(), 0.0F, powerForTime * 3.0F, 0.01F); if (draw == 1.0F) { arrowEntity.setCritArrow(true); } arrowEntity.setBaseDamage(arrowEntity.getBaseDamage() * (double)DAMAGE_MULTIPLIER); - addEnchant(stack, level, entity, arrowEntity, powerForTime); + addEnchant(stack, level, player, arrowEntity, powerForTime); } } else { - arrowEntity = HeavenArrowEntity.create(level, entity); - arrowEntity.setPos(entity.getX() - 0.3, entity.getEyeY() - 0.1, entity.getZ()); - arrowEntity.setCritArrow(true); - addEnchant(stack, level, entity, arrowEntity, powerForTime); + arrowEntity = HeavenArrowEntity.create(level, player); + arrowEntity.setPos(player.getX() - 0.3, player.getEyeY() - 0.1, player.getZ()); + arrowEntity.shootFromRotation(player, player.getXRot(), player.getYRot(), 0.0F, powerForTime * 3.0F, 0.01F); + if (draw == 1.0F) { + arrowEntity.setCritArrow(true); + } + addEnchant(stack, level, player, arrowEntity, powerForTime); } level.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.ARROW_SHOOT, SoundSource.PLAYERS, 1.0F, 1.0F / (level.random.nextFloat() * 0.4F + 1.2F) + powerForTime * 0.5F); @@ -161,8 +165,7 @@ public void releaseUsing(@NotNull ItemStack stack, @NotNull Level level, @NotNul } } - private void addEnchant(@NotNull ItemStack stack, @NotNull Level level, @NotNull LivingEntity entity, AbstractArrow arrowEntity, float powerForTime) { - arrowEntity.shootFromRotation(entity, entity.getXRot(), entity.getYRot(), 0.0F, powerForTime * 3.0F, 0.01F); + private void addEnchant(@NotNull ItemStack stack, @NotNull Level level, @NotNull LivingEntity player, AbstractArrow arrowEntity, float powerForTime) { int j = EnchantmentHelper.getTagEnchantmentLevel(Enchantments.POWER_ARROWS, stack); if (j > 0) { arrowEntity.setBaseDamage(arrowEntity.getBaseDamage() + (double)j * 0.5D + 0.5D); @@ -176,8 +179,28 @@ private void addEnchant(@NotNull ItemStack stack, @NotNull Level level, @NotNull if (EnchantmentHelper.getTagEnchantmentLevel(Enchantments.FLAMING_ARROWS, stack) > 0) { arrowEntity.setSecondsOnFire(100); } + stack.hurtAndBreak(1, player, (p_289501_) -> { + p_289501_.broadcastBreakEvent(player.getUsedItemHand()); + }); arrowEntity.pickup = AbstractArrow.Pickup.CREATIVE_ONLY; level.addFreshEntity(arrowEntity); } + public @NotNull AbstractArrow customTraceArrow(AbstractArrow arrow) { + if (arrow.getType() != EntityType.ARROW && arrow.getType() != EntityType.SPECTRAL_ARROW) { + return arrow; + } else { + Entity owner = arrow.getOwner(); + if (!(owner instanceof LivingEntity)) { + return new TraceArrowEntity(ModEntities.TRACE_ARROW.get(), arrow.level()); + } else { + TraceArrowEntity newArrow = new TraceArrowEntity(arrow.level(), (LivingEntity)arrow.getOwner()); + if (arrow instanceof SpectralArrow spectralArrow) { + newArrow.setSpectral(spectralArrow.duration); + } + return newArrow; + } + } + } + } diff --git a/src/main/java/committee/nova/mods/avaritia/common/item/tools/HoeInfinityItem.java b/src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityHoeItem.java similarity index 98% rename from src/main/java/committee/nova/mods/avaritia/common/item/tools/HoeInfinityItem.java rename to src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityHoeItem.java index cd5ebfa0..599387c8 100644 --- a/src/main/java/committee/nova/mods/avaritia/common/item/tools/HoeInfinityItem.java +++ b/src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityHoeItem.java @@ -1,7 +1,6 @@ package committee.nova.mods.avaritia.common.item.tools; import committee.nova.mods.avaritia.common.entity.ImmortalItemEntity; -import committee.nova.mods.avaritia.init.handler.InfinityHandler; import committee.nova.mods.avaritia.init.handler.ItemCaptureHandler; import committee.nova.mods.avaritia.init.registry.ModEntities; import committee.nova.mods.avaritia.init.registry.ModItems; @@ -37,9 +36,9 @@ * Date: 2022/5/15 16:47 * Version: 1.0 */ -public class HoeInfinityItem extends HoeItem { +public class InfinityHoeItem extends HoeItem { - public HoeInfinityItem() { + public InfinityHoeItem() { super(Tier.INFINITY_HOE, -5, 0f, (new Properties()) .stacksTo(1) .fireResistant()); diff --git a/src/main/java/committee/nova/mods/avaritia/common/item/tools/PickaxeInfinityItem.java b/src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityPickaxeItem.java similarity index 91% rename from src/main/java/committee/nova/mods/avaritia/common/item/tools/PickaxeInfinityItem.java rename to src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityPickaxeItem.java index a99989f4..e1bed7bf 100644 --- a/src/main/java/committee/nova/mods/avaritia/common/item/tools/PickaxeInfinityItem.java +++ b/src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityPickaxeItem.java @@ -5,16 +5,12 @@ import committee.nova.mods.avaritia.init.registry.ModEntities; import committee.nova.mods.avaritia.init.registry.ModItems; import committee.nova.mods.avaritia.util.ToolUtil; -import committee.nova.mods.avaritia.util.math.RayTracer; import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.HumanoidArm; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -22,7 +18,6 @@ import net.minecraft.world.item.Rarity; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.BlockHitResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -32,9 +27,9 @@ * Date: 2022/3/31 10:25 * Version: 1.0 */ -public class PickaxeInfinityItem extends PickaxeItem { +public class InfinityPickaxeItem extends PickaxeItem { - public PickaxeInfinityItem() { + public InfinityPickaxeItem() { super(Tier.INFINITY_PICKAXE, 1, -2.8F, (new Properties()) .stacksTo(1) .fireResistant()); diff --git a/src/main/java/committee/nova/mods/avaritia/common/item/tools/ShovelInfinityItem.java b/src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityShovelItem.java similarity index 91% rename from src/main/java/committee/nova/mods/avaritia/common/item/tools/ShovelInfinityItem.java rename to src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityShovelItem.java index b80fac9c..f6c44ce3 100644 --- a/src/main/java/committee/nova/mods/avaritia/common/item/tools/ShovelInfinityItem.java +++ b/src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityShovelItem.java @@ -5,21 +5,17 @@ import committee.nova.mods.avaritia.init.registry.ModEntities; import committee.nova.mods.avaritia.init.registry.ModItems; import committee.nova.mods.avaritia.util.ToolUtil; -import committee.nova.mods.avaritia.util.math.RayTracer; import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.HumanoidArm; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Rarity; import net.minecraft.world.item.ShovelItem; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.BlockHitResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -29,9 +25,9 @@ * Date: 2022/5/15 16:33 * Version: 1.0 */ -public class ShovelInfinityItem extends ShovelItem { +public class InfinityShovelItem extends ShovelItem { - public ShovelInfinityItem() { + public InfinityShovelItem() { super(Tier.INFINITY_SHOVEL, -2, -2.8f, (new Properties()) .stacksTo(1) .fireResistant()); diff --git a/src/main/java/committee/nova/mods/avaritia/common/item/tools/SwordInfinityItem.java b/src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinitySwordItem.java similarity index 98% rename from src/main/java/committee/nova/mods/avaritia/common/item/tools/SwordInfinityItem.java rename to src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinitySwordItem.java index 77fe3266..9f7f3909 100644 --- a/src/main/java/committee/nova/mods/avaritia/common/item/tools/SwordInfinityItem.java +++ b/src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinitySwordItem.java @@ -27,8 +27,8 @@ * Date: 2022/4/2 19:41 * Version: 1.0 */ -public class SwordInfinityItem extends SwordItem { - public SwordInfinityItem() { +public class InfinitySwordItem extends SwordItem { + public InfinitySwordItem() { super(Tier.INFINITY_SWORD, 0, -2.8F, (new Properties()) .stacksTo(1) .fireResistant()); diff --git a/src/main/java/committee/nova/mods/avaritia/common/item/tools/TotemInfinityItem.java b/src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityTotemItem.java similarity index 82% rename from src/main/java/committee/nova/mods/avaritia/common/item/tools/TotemInfinityItem.java rename to src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityTotemItem.java index c777a8be..6cc33b6a 100644 --- a/src/main/java/committee/nova/mods/avaritia/common/item/tools/TotemInfinityItem.java +++ b/src/main/java/committee/nova/mods/avaritia/common/item/tools/InfinityTotemItem.java @@ -10,9 +10,9 @@ * @Description: */ -public class TotemInfinityItem extends Item { +public class InfinityTotemItem extends Item { - public TotemInfinityItem() { + public InfinityTotemItem() { super(new Properties() .stacksTo(1) .rarity(Rarity.EPIC) diff --git a/src/main/java/committee/nova/mods/avaritia/common/item/tools/SwordSkullsItem.java b/src/main/java/committee/nova/mods/avaritia/common/item/tools/SkullsSwordItem.java similarity index 95% rename from src/main/java/committee/nova/mods/avaritia/common/item/tools/SwordSkullsItem.java rename to src/main/java/committee/nova/mods/avaritia/common/item/tools/SkullsSwordItem.java index 60a5773f..db82d840 100644 --- a/src/main/java/committee/nova/mods/avaritia/common/item/tools/SwordSkullsItem.java +++ b/src/main/java/committee/nova/mods/avaritia/common/item/tools/SkullsSwordItem.java @@ -24,8 +24,8 @@ * Date: 2022/4/2 20:00 * Version: 1.0 */ -public class SwordSkullsItem extends SwordItem { - public SwordSkullsItem() { +public class SkullsSwordItem extends SwordItem { + public SkullsSwordItem() { super(Tier.SKULL_SWORD, 0, -2.4f, (new Properties()) .stacksTo(1) .fireResistant()); diff --git a/src/main/java/committee/nova/mods/avaritia/init/handler/CapHandler.java b/src/main/java/committee/nova/mods/avaritia/init/handler/CapHandler.java new file mode 100644 index 00000000..a810ce47 --- /dev/null +++ b/src/main/java/committee/nova/mods/avaritia/init/handler/CapHandler.java @@ -0,0 +1,31 @@ +package committee.nova.mods.avaritia.init.handler; + +import committee.nova.mods.avaritia.Static; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.animal.horse.AbstractHorse; +import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent; +import net.minecraftforge.event.AttachCapabilitiesEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; + +/** + * CapHandler + * + * @author cnlimiter + * @version 1.0 + * @description + * @date 2024/4/7 1:48 + */ +@Mod.EventBusSubscriber +public class CapHandler { + + @SubscribeEvent + public static void registerCaps(RegisterCapabilitiesEvent event){ + } + + @SubscribeEvent + public static void attachCaps(AttachCapabilitiesEvent event) { + if (!(event.getObject() instanceof AbstractHorse)) return; + } +} diff --git a/src/main/java/committee/nova/mods/avaritia/init/handler/InfinityHandler.java b/src/main/java/committee/nova/mods/avaritia/init/handler/InfinityHandler.java index b4e9a04d..6b19b55e 100644 --- a/src/main/java/committee/nova/mods/avaritia/init/handler/InfinityHandler.java +++ b/src/main/java/committee/nova/mods/avaritia/init/handler/InfinityHandler.java @@ -205,7 +205,7 @@ public static void expCancel(ItemExpireEvent event) { @OnlyIn(Dist.CLIENT) @SubscribeEvent public static void onTooltip(ItemTooltipEvent event) { - if (event.getItemStack().getItem() instanceof SwordInfinityItem) { + if (event.getItemStack().getItem() instanceof InfinitySwordItem) { for (int x = 0; x < event.getToolTip().size(); x++) { if (event.getToolTip().get(x).getString().contains(I18n.get("tooltip.infinity.desc")) || event.getToolTip().get(x).getString().equals(I18n.get("attribute.name.generic.attack_damage"))) { event.getToolTip().set(x, Component.literal("+").withStyle(ChatFormatting.BLUE).append(Component.literal(TextUtil.makeFabulous(I18n.get("tooltip.infinity")))).append(" ").append(Component.translatable("tooltip.infinity.desc").withStyle(ChatFormatting.BLUE))); @@ -279,9 +279,6 @@ public static void onAttacked(LivingAttackEvent event) { if (!(event.getEntity() instanceof Player player)) { return; } - if (event.getSource().getEntity() != null && event.getSource().getEntity() instanceof Player) { - return; - } if (AbilityUtil.isInfinite(player) && !event.getSource().is(ModDamageTypes.INFINITY)) { event.setCanceled(true); } @@ -325,9 +322,9 @@ public static void onLivingDrops(LivingDropsEvent event) { public static void entityItemUnDeath(ItemEvent event) { ItemEntity entityItem = event.getEntity(); Item item = entityItem.getItem().getItem(); - if (item instanceof ArmorInfinityItem || item instanceof AxeInfinityItem || item instanceof BowInfinityItem || - item instanceof HoeInfinityItem || item instanceof ShovelInfinityItem || item instanceof PickaxeInfinityItem || - item instanceof SwordInfinityItem) { + if (item instanceof ArmorInfinityItem || item instanceof InfinityAxeItem || item instanceof InfinityBowItem || + item instanceof InfinityHoeItem || item instanceof InfinityShovelItem || item instanceof InfinityPickaxeItem || + item instanceof InfinitySwordItem) { entityItem.setInvulnerable(true); } } diff --git a/src/main/java/committee/nova/mods/avaritia/init/handler/ItemOverrideHandler.java b/src/main/java/committee/nova/mods/avaritia/init/handler/ItemOverrideHandler.java index 2730f4f4..e75ec32b 100644 --- a/src/main/java/committee/nova/mods/avaritia/init/handler/ItemOverrideHandler.java +++ b/src/main/java/committee/nova/mods/avaritia/init/handler/ItemOverrideHandler.java @@ -2,9 +2,9 @@ import committee.nova.mods.avaritia.Static; import committee.nova.mods.avaritia.common.item.MatterClusterItem; -import committee.nova.mods.avaritia.common.item.tools.BowInfinityItem; -import committee.nova.mods.avaritia.common.item.tools.PickaxeInfinityItem; -import committee.nova.mods.avaritia.common.item.tools.ShovelInfinityItem; +import committee.nova.mods.avaritia.common.item.tools.InfinityBowItem; +import committee.nova.mods.avaritia.common.item.tools.InfinityPickaxeItem; +import committee.nova.mods.avaritia.common.item.tools.InfinityShovelItem; import committee.nova.mods.avaritia.init.registry.ModItems; import net.minecraft.client.renderer.item.ItemProperties; import net.minecraft.client.renderer.item.ItemPropertyFunction; @@ -28,7 +28,7 @@ public class ItemOverrideHandler { @SubscribeEvent public static void init(FMLClientSetupEvent event) { event.enqueueWork(() -> setPropertyOverride(ModItems.infinity_pickaxe.get(), Static.rl("hammer"), (itemStack, world, livingEntity, d) -> { - if (itemStack.getItem() instanceof PickaxeInfinityItem) + if (itemStack.getItem() instanceof InfinityPickaxeItem) return itemStack.getOrCreateTag().getBoolean("hammer") ? 1 : 0; return 0; })); @@ -36,7 +36,7 @@ public static void init(FMLClientSetupEvent event) { return MatterClusterItem.getClusterSize(itemStack) == MatterClusterItem.CAPACITY ? 1 : 0; })); event.enqueueWork(() -> setPropertyOverride(ModItems.infinity_bow.get(), Static.rl("tracer"), (itemStack, world, livingEntity, d) -> { - if (itemStack.getItem() instanceof BowInfinityItem) + if (itemStack.getItem() instanceof InfinityBowItem) return itemStack.getOrCreateTag().getBoolean("tracer") ? 1 : 0; return 0; })); @@ -48,13 +48,13 @@ public static void init(FMLClientSetupEvent event) { } })); event.enqueueWork(() -> setPropertyOverride(ModItems.infinity_bow.get(), Static.rl("pulling"), (itemStack, world, livingEntity, d) -> { - if (itemStack.getItem() instanceof BowInfinityItem) + if (itemStack.getItem() instanceof InfinityBowItem) return livingEntity != null && livingEntity.isUsingItem() && livingEntity.getUseItem() == itemStack && !CrossbowItem.isCharged(itemStack) ? 1.0F : 0.0F; return 0; })); event.enqueueWork(() -> setPropertyOverride(ModItems.infinity_shovel.get(), Static.rl("destroyer"), (itemStack, world, livingEntity, d) -> { - if (itemStack.getItem() instanceof ShovelInfinityItem) + if (itemStack.getItem() instanceof InfinityShovelItem) return itemStack.getOrCreateTag().getBoolean("destroyer") ? 1 : 0; return 0; })); diff --git a/src/main/java/committee/nova/mods/avaritia/init/registry/ModCaps.java b/src/main/java/committee/nova/mods/avaritia/init/registry/ModCaps.java new file mode 100644 index 00000000..449cd4f7 --- /dev/null +++ b/src/main/java/committee/nova/mods/avaritia/init/registry/ModCaps.java @@ -0,0 +1,17 @@ +package committee.nova.mods.avaritia.init.registry; + +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.CapabilityManager; +import net.minecraftforge.common.capabilities.CapabilityToken; + +/** + * ModCaps + * + * @author cnlimiter + * @version 1.0 + * @description + * @date 2024/4/7 1:48 + */ +public class ModCaps { + +} diff --git a/src/main/java/committee/nova/mods/avaritia/init/registry/ModEntities.java b/src/main/java/committee/nova/mods/avaritia/init/registry/ModEntities.java index 3b2a017d..1587f9a1 100644 --- a/src/main/java/committee/nova/mods/avaritia/init/registry/ModEntities.java +++ b/src/main/java/committee/nova/mods/avaritia/init/registry/ModEntities.java @@ -60,7 +60,7 @@ public class ModEntities { public static final RegistryObject> TRACE_ARROW = ENTITIES.register("trace_arrow", () -> EntityType.Builder.of(TraceArrowEntity::new, MobCategory.MISC) .sized(0.5F, 0.5F) - .clientTrackingRange(2) + .clientTrackingRange(4) .updateInterval(20) .fireImmune() .noSummon() diff --git a/src/main/java/committee/nova/mods/avaritia/init/registry/ModItems.java b/src/main/java/committee/nova/mods/avaritia/init/registry/ModItems.java index b49f3c9e..508a998f 100644 --- a/src/main/java/committee/nova/mods/avaritia/init/registry/ModItems.java +++ b/src/main/java/committee/nova/mods/avaritia/init/registry/ModItems.java @@ -6,12 +6,10 @@ import committee.nova.mods.avaritia.common.item.EndestPearlItem; import committee.nova.mods.avaritia.common.item.MatterClusterItem; import committee.nova.mods.avaritia.common.item.resources.ResourceItem; -import committee.nova.mods.avaritia.common.item.resources.StarFuelItem; import committee.nova.mods.avaritia.common.item.singularity.SingularityItem; import committee.nova.mods.avaritia.common.item.tools.*; import net.minecraft.ChatFormatting; import net.minecraft.world.item.ArmorItem; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.Rarity; import net.minecraftforge.registries.DeferredRegister; @@ -31,15 +29,15 @@ public class ModItems { public static Rarity COSMIC_RARITY = Rarity.create("COSMIC", ChatFormatting.RED); //tools - public static RegistryObject infinity_pickaxe = item("infinity_pickaxe", PickaxeInfinityItem::new); - public static RegistryObject infinity_shovel = item("infinity_shovel", ShovelInfinityItem::new); - public static RegistryObject infinity_axe = item("infinity_axe", AxeInfinityItem::new); - public static RegistryObject infinity_hoe = item("infinity_hoe", HoeInfinityItem::new); + public static RegistryObject infinity_pickaxe = item("infinity_pickaxe", InfinityPickaxeItem::new); + public static RegistryObject infinity_shovel = item("infinity_shovel", InfinityShovelItem::new); + public static RegistryObject infinity_axe = item("infinity_axe", InfinityAxeItem::new); + public static RegistryObject infinity_hoe = item("infinity_hoe", InfinityHoeItem::new); public static RegistryObject matter_cluster = item("matter_cluster", MatterClusterItem::new); //weapons - public static RegistryObject infinity_sword = item("infinity_sword", SwordInfinityItem::new); - public static RegistryObject skull_sword = item("skull_fire_sword", SwordSkullsItem::new); - public static RegistryObject infinity_bow = item("infinity_bow", BowInfinityItem::new); + public static RegistryObject infinity_sword = item("infinity_sword", InfinitySwordItem::new); + public static RegistryObject skull_sword = item("skull_fire_sword", SkullsSwordItem::new); + public static RegistryObject infinity_bow = item("infinity_bow", InfinityBowItem::new); //armors public static RegistryObject infinity_helmet = item("infinity_helmet", () -> new ArmorInfinityItem(ArmorItem.Type.HELMET)); public static RegistryObject infinity_chestplate = item("infinity_chestplate", () -> new ArmorInfinityItem(ArmorItem.Type.CHESTPLATE)); diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 8d24a74e..ddf1693b 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -15,7 +15,7 @@ public net.minecraft.world.entity.item.ItemEntity f_31986_ # pickupdelay public net.minecraft.world.entity.item.ItemEntity f_31985_ # age public net.minecraft.world.damagesource.DamageSources m_269079_(Lnet/minecraft/resources/ResourceKey;)Lnet/minecraft/world/damagesource/DamageSource; # source public net.minecraft.world.damagesource.DamageSources m_268998_(Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/entity/Entity;)Lnet/minecraft/world/damagesource/DamageSource; # source - +public net.minecraft.world.entity.projectile.SpectralArrow f_37409_ # duration public-f com.mojang.blaze3d.shaders.Uniform m_5985_(F)V # set public-f com.mojang.blaze3d.shaders.Uniform m_142276_(Lcom/mojang/math/Vector3f;)V # set