From 1e2a603cdb2453b0956d09831d71f110805ae7d4 Mon Sep 17 00:00:00 2001 From: Jenny Date: Thu, 6 Feb 2025 11:04:13 +0100 Subject: [PATCH] ender arrow & homing arrow --- gradle.properties | 4 +- .../advancedarrows/entities/enderArrow.java | 53 ++++++++++ .../advancedarrows/entities/entities.java | 19 +++- .../advancedarrows/entities/homingArrow.java | 95 ++++++++++++++++++ .../entities/sharpenedArrow.java | 24 +---- .../advancedarrows/items/ArrowEnder.java | 20 ++++ .../advancedarrows/items/ArrowHoming.java | 20 ++++ .../com/jenny/advancedarrows/items/items.java | 4 +- .../assets/advancedarrows/lang/en_us.json | 18 ++++ .../textures/item/arrow_breaching.png | Bin 489 -> 647 bytes .../textures/item/arrow_breaching.png.mcmeta | 34 +++++++ .../textures/item/arrow_ender.png | Bin 0 -> 638 bytes .../textures/item/arrow_ricochet.png | Bin 424 -> 270 bytes .../textures/item/arrow_ricochet.png.mcmeta | 10 ++ .../data/minecraft/tags/items/arrows.json | 4 +- 15 files changed, 273 insertions(+), 32 deletions(-) create mode 100644 src/main/java/com/jenny/advancedarrows/entities/enderArrow.java create mode 100644 src/main/java/com/jenny/advancedarrows/entities/homingArrow.java create mode 100644 src/main/java/com/jenny/advancedarrows/items/ArrowEnder.java create mode 100644 src/main/java/com/jenny/advancedarrows/items/ArrowHoming.java create mode 100644 src/main/resources/assets/advancedarrows/textures/item/arrow_breaching.png.mcmeta create mode 100644 src/main/resources/assets/advancedarrows/textures/item/arrow_ender.png create mode 100644 src/main/resources/assets/advancedarrows/textures/item/arrow_ricochet.png.mcmeta diff --git a/gradle.properties b/gradle.properties index 0e591d8..5ae9de5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/java/com/jenny/advancedarrows/entities/enderArrow.java b/src/main/java/com/jenny/advancedarrows/entities/enderArrow.java new file mode 100644 index 0000000..288be72 --- /dev/null +++ b/src/main/java/com/jenny/advancedarrows/entities/enderArrow.java @@ -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 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); + } + } +} diff --git a/src/main/java/com/jenny/advancedarrows/entities/entities.java b/src/main/java/com/jenny/advancedarrows/entities/entities.java index 27063e1..1dcba68 100644 --- a/src/main/java/com/jenny/advancedarrows/entities/entities.java +++ b/src/main/java/com/jenny/advancedarrows/entities/entities.java @@ -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> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, MODID); @@ -44,6 +43,14 @@ public class entities { ENTITY_TYPES.register("arrow_breaching", () -> EntityType.Builder.of(breachingArrow::new, MobCategory.MISC) .sized(w, h).fireImmune().clientTrackingRange(tr).build("arrow_breaching")); + public static final RegistryObject> ARROW_HOMING = + ENTITY_TYPES.register("arrow_homing", () -> EntityType.Builder.of(homingArrow::new, MobCategory.MISC) + .sized(w, h).fireImmune().clientTrackingRange(tr).build("arrow_homing")); + + public static final RegistryObject> ARROW_ENDER = + ENTITY_TYPES.register("arrow_ender", () -> EntityType.Builder.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); } } diff --git a/src/main/java/com/jenny/advancedarrows/entities/homingArrow.java b/src/main/java/com/jenny/advancedarrows/entities/homingArrow.java new file mode 100644 index 0000000..57a267e --- /dev/null +++ b/src/main/java/com/jenny/advancedarrows/entities/homingArrow.java @@ -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 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 getEntities() { + if (getOwner() == null) { + setOwner(this); + } + + List 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); + } + } +} diff --git a/src/main/java/com/jenny/advancedarrows/entities/sharpenedArrow.java b/src/main/java/com/jenny/advancedarrows/entities/sharpenedArrow.java index 9dba837..e8085e4 100644 --- a/src/main/java/com/jenny/advancedarrows/entities/sharpenedArrow.java +++ b/src/main/java/com/jenny/advancedarrows/entities/sharpenedArrow.java @@ -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 diff --git a/src/main/java/com/jenny/advancedarrows/items/ArrowEnder.java b/src/main/java/com/jenny/advancedarrows/items/ArrowEnder.java new file mode 100644 index 0000000..f9526fe --- /dev/null +++ b/src/main/java/com/jenny/advancedarrows/items/ArrowEnder.java @@ -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); + } +} diff --git a/src/main/java/com/jenny/advancedarrows/items/ArrowHoming.java b/src/main/java/com/jenny/advancedarrows/items/ArrowHoming.java new file mode 100644 index 0000000..4cab07e --- /dev/null +++ b/src/main/java/com/jenny/advancedarrows/items/ArrowHoming.java @@ -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); + } +} diff --git a/src/main/java/com/jenny/advancedarrows/items/items.java b/src/main/java/com/jenny/advancedarrows/items/items.java index 33462da..7b52d80 100644 --- a/src/main/java/com/jenny/advancedarrows/items/items.java +++ b/src/main/java/com/jenny/advancedarrows/items/items.java @@ -11,13 +11,15 @@ import static com.jenny.advancedarrows.advancedArrows.MODID; public class items { public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID); - public static final RegistryObject ARROW_INCENDIARY = ITEMS.register("arrow_incendiary", () -> new ArrowIncendiary(new Item.Properties())); public static final RegistryObject ARROW_RICOCHET = ITEMS.register("arrow_ricochet", () -> new ArrowRicochet(new Item.Properties())); public static final RegistryObject ARROW_KINETIC = ITEMS.register("arrow_kinetic", () -> new ArrowKinetic(new Item.Properties())); public static final RegistryObject ARROW_SHARPENED = ITEMS.register("arrow_sharpened", () -> new ArrowSharpened(new Item.Properties())); public static final RegistryObject ARROW_SWITCH = ITEMS.register("arrow_switch", () -> new ArrowSwitch(new Item.Properties())); public static final RegistryObject ARROW_BREACHING = ITEMS.register("arrow_breaching", () -> new ArrowBreaching(new Item.Properties())); + public static final RegistryObject ARROW_HOMING = ITEMS.register("arrow_homing", () -> new ArrowHoming(new Item.Properties())); + public static final RegistryObject ARROW_ENDER = ITEMS.register("arrow_ender", () -> new ArrowEnder(new Item.Properties())); + public static void register(IEventBus bus) { ITEMS.register(bus); diff --git a/src/main/resources/assets/advancedarrows/lang/en_us.json b/src/main/resources/assets/advancedarrows/lang/en_us.json index e69de29..9c8602a 100644 --- a/src/main/resources/assets/advancedarrows/lang/en_us.json +++ b/src/main/resources/assets/advancedarrows/lang/en_us.json @@ -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" +} \ No newline at end of file diff --git a/src/main/resources/assets/advancedarrows/textures/item/arrow_breaching.png b/src/main/resources/assets/advancedarrows/textures/item/arrow_breaching.png index c03fcbb88c6a0bd19900013fa1cad2c347438d19..bd310f6c5087d987c6888e19a1ad74eb388bcda2 100644 GIT binary patch literal 647 zcmV;20(kw2P)Px%K}keGRCt{2*)eXyFcb#hpQu~axe`OAih*ujx<`uAvoLnx6kGtt9-|v0XP`r* zNUgYrJG4e6VEfrljP1OCf6oT;J`o#8F6;GL2q8pW*8%`;YznKY0sw3_8~c^(x)!U& zTp3|Kh{pfa!FK z`^OjS#Zi`}XxmnlW$E_0WfSLO4lP|w0OB|gh6#BGj7g|s7fgUZP#BZZxfe9x-RG0vUaUL8K;|>^;P{lr&06^h|2`824Fab2<90U{X4j7Y= z#XgvLWj>qvFWO6!F@!x}4@e2_K|Bt`(`5Lt2kZeU!90j(`o`FVJzx(=8Qg=!1}D=d zDi356XAeG`W}@8*dyrJ|U>+noIGHx-deCiR?SXXQvuP&Ul}#QPMKXDy6^T8tOz$2f zJ~){+>Ggeq+Jc#73ExzfCuZgt> z@_m5s7fxp*cT8M7h{S<-60ZX?WDmOMgzQ0&Z}ACWV&efj5N%99jnMPx$qe(SL^^zJ%1HRE+eszX zT4$|wf-%Nb`JA{YA2AGLjEm#ARkp-sRe=O+tpgYg23z0HX0xr&65cfKV7Elb zZv?f@LxK$NJ^*-pc?DoHnE*ebv(5=MaaIFD855PS0h#>#?Gu2j`}acUg{}z|281fs zL@?8F&rQcY*YCDnzuW%3xc|RjltZ2qstgDxHL-83&N=xszKL2H5PTDR_ZzF#$^mRP8vvf4h5#(rUzP7*L#eF+A&%qL z&Tce4`A(+;z|HLg0Lyi9vVcXXwE@U@Ba5QQ0W1~^07jz`07;Ulx%Yi)Z(uJ`6gjb> fnZIkG;Y54`({DWSKQ%y=00000NkvXXu0mjfF9**L diff --git a/src/main/resources/assets/advancedarrows/textures/item/arrow_breaching.png.mcmeta b/src/main/resources/assets/advancedarrows/textures/item/arrow_breaching.png.mcmeta new file mode 100644 index 0000000..f64f9eb --- /dev/null +++ b/src/main/resources/assets/advancedarrows/textures/item/arrow_breaching.png.mcmeta @@ -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 + ] + } +} \ No newline at end of file diff --git a/src/main/resources/assets/advancedarrows/textures/item/arrow_ender.png b/src/main/resources/assets/advancedarrows/textures/item/arrow_ender.png new file mode 100644 index 0000000000000000000000000000000000000000..ddebf537e901a7a5d41b513bedb61b571de17a3a GIT binary patch literal 638 zcmV-^0)hRBP)Px%I7vi7RA_kuF(^b#}_y zze3~e?kE`w&0;#nvnfZEI9%j<#Gn$wIn;YTnmZfXCU+0>gCmc3ckq4h``#l7%$V_i zlZaYC5cBzE&mVuU@BLHb#mUPVA7A*bjUoW9-Q_EI5N;$k2Ilk2o-EupTL4^ra2J3B z=g=FP)`*DZ#dBVN zY+!CyM(+8E94GQkEU*6D`WohDh2b|x+)pm(XlWe)O;6F=Z6H@E@&tZ3hrrPa59%L6 zpEL5Sfhojd54d*s#Ai~Obl`mC28O1UIC%4x%+d`2w6sog;qRrTb+VN$fRXw@3=GI< zdg|yit&1yL+2UDlh5em+;5(6TVu0;(&U^X(7mJVX)BoII;J6t1RZ*M$oqFKvLxcvl z%QwiVM9WOI zLP50wXtw*O))A{y=rkyAVB!^;L~Uf0Pe6GC6RFUoYa^q40?HdWw@9a18yV#jP~O0q z;*F{{GRh~Qyn(Tzwk%6jrPJw%`HkW|F`i~^WRy=pc>|$8DZ^@G7={>M$=(*@X1jLo z;>JPw1e7-rdU6yB1yP}DwJPRIrIHxeYPHD!7*jq0Px#$Vo&&R7i={lrajzKoCX0Vkg!@3PDoD&c=QrtY^tta)C+dG3+dJhA9V>T;p3v z1hL6ZAR*JgeZ&5l0p_k%k>{MmBqAiq7~_v{GXyNl5&+ONO}aV8$hs=1s(M#24vkAjoI1;Qf2{sOzqs_KVDgsMtarHG`*Me+-}vUY<2-j`3I UHU;2#3jhEB07*qoM6N<$g7gn`Hvj+t literal 424 zcmV;Z0ayNsP)Px$Vo5|nRA_wIk7p={KTQmeMHM9$&b8DN>5`s%Fqg`|iUqVyM5%><8 z;zqf`chLMa91oY;Q|5Wz^PJCT5kw!qe}0M&SS%Kc#bTK#Ns@>@M=j_pUMmwS&M#g4 zMXHeEjWp2|ZIlU>SR+jQB~oh>UBzi>;=iK4U$3R1E;PSVhueN&nx+CEiXs4lAOK)K zpU?WN_x4)U?%TS7A^B-+1~(uR_dKt5KFhL=*KVc{aIo>JJEqqh{)X@S0w6ej2jKet z34l0`f&R0v!uSRTe+OjpkIx?f99_H&{fHXIH!#>dKHQxNSSP<&e$HV1P7FQ!65D_( z`LUR81G`RMGQ9?LNnSFY26RhavcC