ender arrow & homing arrow

This commit is contained in:
Jenny 2025-02-06 11:04:13 +01:00
parent 3cfed03bcd
commit 1e2a603cdb
Signed by: Jenny
GPG Key ID: 2072A14E40940632
15 changed files with 273 additions and 32 deletions

View File

@ -5,7 +5,7 @@ minecraft_version=1.20.1
# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.20.1,1.21)
minecraft_version_range=[1.20.1]
# The Forge version must agree with the Minecraft version to get a valid artifact
forge_version=47.3.0
# The Forge version range can use any version of Forge as bounds or match the loader version range
@ -38,7 +38,7 @@ mod_name=Advanced Arrows
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=All Rights Reserved
# The mod version. See https://semver.org/
mod_version=0.0.1
mod_version=0.0.2
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View File

@ -0,0 +1,53 @@
package com.jenny.advancedarrows.entities;
import com.jenny.advancedarrows.config.ConfigClient;
import com.jenny.advancedarrows.items.items;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
public class enderArrow extends baseArrow {
public enderArrow(EntityType<enderArrow> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
}
public enderArrow(Level pLevel, LivingEntity pShooter) {
super(pLevel, pShooter, entities.ARROW_ENDER.get());
}
@Override
protected void onHitEntity(@NotNull EntityHitResult pTarget) {
super.onHitEntity(pTarget);
Entity target = pTarget.getEntity();
target.addDeltaMovement(getDeltaMovement().multiply(1.5, 0.2, 1.5));
}
@NotNull
protected ItemStack getPickupItem() {
return new ItemStack(items.ARROW_ENDER.get());
}
@Override
protected void onHit(@NotNull HitResult pResult) {
super.onHit(pResult);
if (getOwner() != null) {
Vec3 pos = pResult.getLocation();
level().getPlayerByUUID(getOwner().getUUID()).teleportTo(pos.x, pos.y, pos.z);
}
}
@Override
public void spawnParticles() {
for (int i = 1; i <= ConfigClient.calcPCount(5); i++) {
Vec3 pos = createParticlePos(1f);
level().addParticle(ParticleTypes.ELECTRIC_SPARK, pos.x, pos.y, pos.z, 0, 0, 0);
}
}
}

View File

@ -1,7 +1,6 @@
package com.jenny.advancedarrows.entities;
import com.jenny.advancedarrows.entities.client.*;
import com.jenny.advancedarrows.entities.client.baseArrowRenderer;
import net.minecraft.client.renderer.entity.EntityRenderers;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
@ -13,9 +12,9 @@ import net.minecraftforge.registries.RegistryObject;
import static com.jenny.advancedarrows.advancedArrows.MODID;
public class entities {
private static int tr = 16;
private static float w = 0.5f;
private static float h = 0.5f;
private static final int tr = 16;
private static final float w = 0.5f;
private static final float h = 0.5f;
public static final DeferredRegister<EntityType<?>> ENTITY_TYPES =
DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, MODID);
@ -44,6 +43,14 @@ public class entities {
ENTITY_TYPES.register("arrow_breaching", () -> EntityType.Builder.<breachingArrow>of(breachingArrow::new, MobCategory.MISC)
.sized(w, h).fireImmune().clientTrackingRange(tr).build("arrow_breaching"));
public static final RegistryObject<EntityType<homingArrow>> ARROW_HOMING =
ENTITY_TYPES.register("arrow_homing", () -> EntityType.Builder.<homingArrow>of(homingArrow::new, MobCategory.MISC)
.sized(w, h).fireImmune().clientTrackingRange(tr).build("arrow_homing"));
public static final RegistryObject<EntityType<enderArrow>> ARROW_ENDER =
ENTITY_TYPES.register("arrow_ender", () -> EntityType.Builder.<enderArrow>of(enderArrow::new, MobCategory.MISC)
.sized(w, h).fireImmune().clientTrackingRange(tr).build("arrow_ender"));
public static void register(IEventBus eventBus) {
ENTITY_TYPES.register(eventBus);
}
@ -55,5 +62,7 @@ public class entities {
EntityRenderers.register(ARROW_SHARPENED.get(), baseArrowRenderer::new);
EntityRenderers.register(ARROW_SWITCH.get(), baseArrowRenderer::new);
EntityRenderers.register(ARROW_BREACHING.get(), baseArrowRenderer::new);
EntityRenderers.register(ARROW_HOMING.get(), baseArrowRenderer::new);
EntityRenderers.register(ARROW_ENDER.get(), baseArrowRenderer::new);
}
}

View File

@ -0,0 +1,95 @@
package com.jenny.advancedarrows.entities;
import com.jenny.advancedarrows.config.ConfigClient;
import com.jenny.advancedarrows.items.items;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class homingArrow extends baseArrow {
LivingEntity target;
public homingArrow(EntityType<homingArrow> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
}
public homingArrow(Level pLevel, LivingEntity pShooter) {
super(pLevel, pShooter, entities.ARROW_HOMING.get());
setBaseDamage(1);
}
@NotNull
protected ItemStack getPickupItem() {
return new ItemStack(items.ARROW_HOMING.get());
}
@Override
public void tick() {
if (!level().isClientSide) {
if (target == null || getTargetDist() > 64) {
findTarget();
} else {
if (!inGround) {
Vec3 targetvec = targetVector().normalize().scale(getDeltaMovement().length());
setDeltaMovement(getDeltaMovement().multiply(0.7, 0.7, 0.7).add(targetvec.multiply(0.3, 0.3, 0.3)));
}
}
}
super.tick();
}
public double getTargetDist() {
return targetVector().length();
}
private Vec3 targetVector() {
double y = target.getBoundingBox().getYsize() / 2;
return position().vectorTo(target.position().add(0, y, 0));
}
public void findTarget() {
double minAngle = Double.MAX_VALUE;
for (LivingEntity entity : getEntities()) {
Vec3 vecTarget = position().vectorTo(entity.position());
double newAngle = Math.acos(vecTarget.dot(getDeltaMovement()) / (getDeltaMovement().length() * vecTarget.length()));
if (newAngle < minAngle) {
target = entity;
minAngle = newAngle;
}
}
}
protected List<LivingEntity> getEntities() {
if (getOwner() == null) {
setOwner(this);
}
List<LivingEntity> ret_list = new ArrayList<>();
Vec3 corner1 = this.position().subtract(32, 32, 32);
Vec3 corner2 = this.position().add(32, 32, 32);
AABB boundingBox = new AABB(corner1, corner2);
for (LivingEntity entity : level().getEntitiesOfClass(LivingEntity.class, boundingBox)) {
if (entity.getUUID() != getOwner().getUUID()) {
ret_list.add(entity);
}
}
return ret_list;
}
@Override
public void spawnParticles() {
for (int i = 1; i <= ConfigClient.calcPCount(5); i++) {
Vec3 pos = createParticlePos(0.5f);
level().addParticle(ParticleTypes.GLOW_SQUID_INK, pos.x, pos.y, pos.z, 0, 0, 0);
}
}
}

View File

@ -2,17 +2,12 @@ package com.jenny.advancedarrows.entities;
import com.jenny.advancedarrows.config.ConfigClient;
import com.jenny.advancedarrows.items.items;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
public class sharpenedArrow extends baseArrow{
@ -22,24 +17,7 @@ public class sharpenedArrow extends baseArrow{
public sharpenedArrow(Level pLevel, LivingEntity pShooter) {
super(pLevel, pShooter, entities.ARROW_SHARPENED.get());
}
@Override
protected void onHitEntity(@NotNull EntityHitResult pTarget) {
super.onHitEntity(pTarget);
System.out.println("a");
Entity entity1 = this.getOwner();
Entity target = pTarget.getEntity();
DamageSource damagesource;
if (entity1 == null) {
damagesource = this.damageSources().arrow(this, this);
} else {
damagesource = this.damageSources().arrow(this, entity1);
if (entity1 instanceof LivingEntity) {
((LivingEntity)entity1).setLastHurtMob(target);
}
}
target.hurt(damagesource, 5);
setBaseDamage(3);
}
@NotNull

View File

@ -0,0 +1,20 @@
package com.jenny.advancedarrows.items;
import com.jenny.advancedarrows.entities.enderArrow;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
public class ArrowEnder extends ArrowAbstract {
public ArrowEnder(Properties properties) {
super(properties);
}
@Override
@NotNull
public AbstractArrow createArrow(@NotNull Level pLevel, @NotNull ItemStack pStack, @NotNull LivingEntity pShooter) {
return new enderArrow(pLevel, pShooter);
}
}

View File

@ -0,0 +1,20 @@
package com.jenny.advancedarrows.items;
import com.jenny.advancedarrows.entities.homingArrow;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
public class ArrowHoming extends ArrowAbstract {
public ArrowHoming(Properties properties) {
super(properties);
}
@Override
@NotNull
public AbstractArrow createArrow(@NotNull Level pLevel, @NotNull ItemStack pStack, @NotNull LivingEntity pShooter) {
return new homingArrow(pLevel, pShooter);
}
}

View File

@ -11,13 +11,15 @@ import static com.jenny.advancedarrows.advancedArrows.MODID;
public class items {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
public static final RegistryObject<Item> ARROW_INCENDIARY = ITEMS.register("arrow_incendiary", () -> new ArrowIncendiary(new Item.Properties()));
public static final RegistryObject<Item> ARROW_RICOCHET = ITEMS.register("arrow_ricochet", () -> new ArrowRicochet(new Item.Properties()));
public static final RegistryObject<Item> ARROW_KINETIC = ITEMS.register("arrow_kinetic", () -> new ArrowKinetic(new Item.Properties()));
public static final RegistryObject<Item> ARROW_SHARPENED = ITEMS.register("arrow_sharpened", () -> new ArrowSharpened(new Item.Properties()));
public static final RegistryObject<Item> ARROW_SWITCH = ITEMS.register("arrow_switch", () -> new ArrowSwitch(new Item.Properties()));
public static final RegistryObject<Item> ARROW_BREACHING = ITEMS.register("arrow_breaching", () -> new ArrowBreaching(new Item.Properties()));
public static final RegistryObject<Item> ARROW_HOMING = ITEMS.register("arrow_homing", () -> new ArrowHoming(new Item.Properties()));
public static final RegistryObject<Item> ARROW_ENDER = ITEMS.register("arrow_ender", () -> new ArrowEnder(new Item.Properties()));
public static void register(IEventBus bus) {
ITEMS.register(bus);

View File

@ -0,0 +1,18 @@
{
"item.advancedarrows.arrow_breaching": "Breaching Arrow",
"tooltip.advancedarrows.arrow_breaching": "hurts entities hiding behind a hit block",
"item.advancedarrows.arrow_ender": "Ender Arrow",
"tooltip.advancedarrows.arrow_ender": "teleports the shooter to it's positon upon hit",
"item.advancedarrows.arrow_homing": "Homing Arrow",
"tooltip.advancedarrows.arrow_homing": "flies towards the closest entity",
"item.advancedarrows.arrow_incendiary": "Incendiary Arrow",
"tooltip.advancedarrows.arrow_incendiary": "sets hit entity on fire",
"item.advancedarrows.arrow_kinetic": "Kinetic Arrow",
"tooltip.advancedarrows.arrow_kinetic": "pushes hit entity away",
"item.advancedarrows.arrow_ricochet": "Ricocheting Arrow",
"tooltip.advancedarrows.arrow_ricochet": "ricochets off blocks",
"item.advancedarrows.arrow_sharpened": "Sharpened Arrow",
"tooltip.advancedarrows.arrow_sharpened": "does more damage",
"item.advancedarrows.arrow_switch": "Switching Arrow",
"tooltip.advancedarrows.arrow_switch": "switches shooter's & target's position on hit"
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 489 B

After

Width:  |  Height:  |  Size: 647 B

View File

@ -0,0 +1,34 @@
{
"animation": {
"frametime": 3,
"interpolate": false,
"frames": [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
4,
3,
2,
1,
0,
0,
0,
0
]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 638 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 424 B

After

Width:  |  Height:  |  Size: 270 B

View File

@ -0,0 +1,10 @@
{
"animation": {
"frametime": 15,
"interpolate": false,
"frames": [
0,
1
]
}
}

View File

@ -5,6 +5,8 @@
"advancedarrows:arrow_kinetic",
"advancedarrows:arrow_sharpened",
"advancedarrows:arrow_switch",
"advancedarrows:arrow_breaching"
"advancedarrows:arrow_breaching",
"advancedarrows:arrow_homing",
"advancedarrows:arrow_ender"
]
}