Skip to content

Commit

Permalink
feat(1.20.1-forged): add trace arrow
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlimiter committed Apr 7, 2024
1 parent e945f02 commit 53d2203
Show file tree
Hide file tree
Showing 18 changed files with 134 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -31,11 +32,10 @@
public class EndestPearlEntity extends ThrowableItemProjectile {
private LivingEntity shooter;

public EndestPearlEntity(EntityType<? extends ThrowableItemProjectile> p_37442_, Level p_37443_) {
super(p_37442_, p_37443_);
public EndestPearlEntity(EntityType<? extends ThrowableItemProjectile> 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);
Expand All @@ -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<ClientGamePacketListener> getAddEntityPacket() {
public @NotNull Packet<ClientGamePacketListener> getAddEntityPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}

Expand All @@ -66,7 +66,6 @@ public void setShooter(LivingEntity shooter) {
this.shooter = shooter;
}


@Override
public void handleEntityEvent(byte pId) {
if (pId == 3) {
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@
*/

public class TraceArrowEntity extends AbstractArrow {
private static final EntityDataAccessor<Integer> ID_EFFECT_COLOR;
private static final EntityDataAccessor<Integer> ID_EFFECT_COLOR = SynchedEntityData.defineId(TraceArrowEntity.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<Integer> SPECTRAL_TIME = SynchedEntityData.defineId(TraceArrowEntity.class, EntityDataSerializers.INT);;
private static final EntityDataAccessor<Integer> JUMP_COUNT = SynchedEntityData.defineId(TraceArrowEntity.class, EntityDataSerializers.INT);
private Potion potion;
private final Set<MobEffectInstance> effects;
private boolean fixedColor;
private LivingEntity homingTarget;
private Vec3 seekOrigin;
private int homingTime;
private static final EntityDataAccessor<Integer> SPECTRAL_TIME;
private static final EntityDataAccessor<Integer> JUMP_COUNT;
private static final List<String> projectileAntiImmuneEntities;
private static final List<String> 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<? extends AbstractArrow> entityType, Level world) {
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
}
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,19 @@
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;
import net.minecraft.world.item.PickaxeItem;
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;

Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 53d2203

Please sign in to comment.