diff --git a/gradle.properties b/gradle.properties index 894a985..2e68374 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.20.2) +minecraft_version_range=[1.20.1,1.20.2] # 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.3 +mod_version=0.0.4 # 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/advancedArrows.java b/src/main/java/com/jenny/advancedarrows/advancedArrows.java index 30de4c8..5f17681 100644 --- a/src/main/java/com/jenny/advancedarrows/advancedArrows.java +++ b/src/main/java/com/jenny/advancedarrows/advancedArrows.java @@ -1,9 +1,10 @@ package com.jenny.advancedarrows; -import com.jenny.advancedarrows.config.*; +import com.jenny.advancedarrows.config.ConfigClient; +import com.jenny.advancedarrows.config.ConfigCommon; import com.jenny.advancedarrows.entities.entities; import com.jenny.advancedarrows.items.items; - +import com.jenny.advancedarrows.particles.particles; import com.mojang.logging.LogUtils; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.MinecraftForge; @@ -30,18 +31,23 @@ public class advancedArrows { modEventBus.addListener(this::commonSetup); + entities.register(modEventBus); items.register(modEventBus); creativeTab.register(modEventBus); - entities.register(modEventBus); + particles.register(modEventBus); MinecraftForge.EVENT_BUS.register(this); - ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ConfigClient.SPEC); + ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ConfigClient.SPEC, "AdvancedArrows-client.toml"); + ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ConfigCommon.SPEC, "AdvancedArrows-common.toml"); } - private void commonSetup(final FMLCommonSetupEvent event) {} + private void commonSetup(final FMLCommonSetupEvent event) { + items.registerDispenser(); + } @SubscribeEvent - public void onServerStarting(ServerStartingEvent event) {} + public void onServerStarting(ServerStartingEvent event) { + } @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public static class ClientModEvents { diff --git a/src/main/java/com/jenny/advancedarrows/config/ConfigClient.java b/src/main/java/com/jenny/advancedarrows/config/ConfigClient.java index 4730933..18c9438 100644 --- a/src/main/java/com/jenny/advancedarrows/config/ConfigClient.java +++ b/src/main/java/com/jenny/advancedarrows/config/ConfigClient.java @@ -1,31 +1,26 @@ package com.jenny.advancedarrows.config; import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.config.ModConfigEvent; import static com.jenny.advancedarrows.advancedArrows.MODID; @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD) public class ConfigClient { private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder(); + public static final ForgeConfigSpec SPEC; - private static final ForgeConfigSpec.ConfigValue C_PARTICLE_PERCENT = - BUILDER.comment("amount of particles to spawn (0.0 = None, 1.0 = normal, values higher are valid too)") - .define("arrowParticleCount", 1.0D); + public static final ForgeConfigSpec.ConfigValue C_PARTICLE_PERCENT; - public static final ForgeConfigSpec SPEC = BUILDER.build(); + static { + C_PARTICLE_PERCENT = + BUILDER.comment("amount of particles to spawn (0.0 = None, 1.0 = normal, values higher are valid too)") + .define("arrowParticleCount", 1.0D); - public static float particlePercent; - - @SubscribeEvent - static void onLoad(final ModConfigEvent event) - { - particlePercent = C_PARTICLE_PERCENT.get().floatValue(); + SPEC = BUILDER.build(); } public static int calcPCount(int pCount) { - return Math.round(pCount * particlePercent); + return (int) Math.round(pCount * C_PARTICLE_PERCENT.get()); } } diff --git a/src/main/java/com/jenny/advancedarrows/config/ConfigCommon.java b/src/main/java/com/jenny/advancedarrows/config/ConfigCommon.java new file mode 100644 index 0000000..006d62c --- /dev/null +++ b/src/main/java/com/jenny/advancedarrows/config/ConfigCommon.java @@ -0,0 +1,22 @@ +package com.jenny.advancedarrows.config; + +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.fml.common.Mod; + +import static com.jenny.advancedarrows.advancedArrows.MODID; + +@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD) +public class ConfigCommon { + private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder(); + public static final ForgeConfigSpec SPEC; + + public static final ForgeConfigSpec.ConfigValue C_AIMBOT_PLAYER; + + static { + C_AIMBOT_PLAYER = + BUILDER.comment("allow the homing arrow to target players") + .define("homingAtPlayer", false); + + SPEC = BUILDER.build(); + } +} diff --git a/src/main/java/com/jenny/advancedarrows/creativeTab.java b/src/main/java/com/jenny/advancedarrows/creativeTab.java index b4a3a2c..c69b595 100644 --- a/src/main/java/com/jenny/advancedarrows/creativeTab.java +++ b/src/main/java/com/jenny/advancedarrows/creativeTab.java @@ -1,7 +1,6 @@ package com.jenny.advancedarrows; import com.jenny.advancedarrows.items.items; - import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; import net.minecraft.world.item.CreativeModeTab; @@ -18,9 +17,7 @@ import static com.jenny.advancedarrows.advancedArrows.MODID; public class creativeTab { public static final DeferredRegister CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID); - public static final RegistryObject CREATIVE_TAB = CREATIVE_MODE_TABS.register("advanced_arrows", () -> CreativeModeTab.builder().withTabsBefore(CreativeModeTabs.COMBAT).icon(() -> items.ARROW_INCENDIARY.get().getDefaultInstance()).displayItems((parameters, output) -> { - output.acceptAll(Arrays.stream(getItems()).toList()); - }).title(Component.literal("Advanced Arrows")).build()); + public static final RegistryObject CREATIVE_TAB = CREATIVE_MODE_TABS.register("advanced_arrows", () -> CreativeModeTab.builder().withTabsBefore(CreativeModeTabs.SPAWN_EGGS).icon(() -> items.ARROW_INCENDIARY.get().getDefaultInstance()).displayItems((parameters, output) -> output.acceptAll(Arrays.stream(getItems()).toList())).title(Component.literal("Advanced Arrows")).build()); public static void register(IEventBus bus) { CREATIVE_MODE_TABS.register(bus); diff --git a/src/main/java/com/jenny/advancedarrows/entities/baseArrow.java b/src/main/java/com/jenny/advancedarrows/entities/baseArrow.java index 0d06f27..74d7287 100644 --- a/src/main/java/com/jenny/advancedarrows/entities/baseArrow.java +++ b/src/main/java/com/jenny/advancedarrows/entities/baseArrow.java @@ -13,7 +13,6 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.projectile.AbstractArrow; -import net.minecraft.world.entity.projectile.Arrow; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.alchemy.Potion; @@ -29,7 +28,7 @@ import java.util.Set; public class baseArrow extends AbstractArrow { private static final int EXPOSED_POTION_DECAY_TIME = 600; private static final int NO_EFFECT_COLOR = -1; - private static final EntityDataAccessor ID_EFFECT_COLOR = SynchedEntityData.defineId(Arrow.class, EntityDataSerializers.INT); + private static final EntityDataAccessor ID_EFFECT_COLOR = SynchedEntityData.defineId(baseArrow.class, EntityDataSerializers.INT); private static final byte EVENT_POTION_PUFF = 0; private Potion potion = Potions.EMPTY; private final Set effects = Sets.newHashSet(); diff --git a/src/main/java/com/jenny/advancedarrows/entities/breachingArrow.java b/src/main/java/com/jenny/advancedarrows/entities/breachingArrow.java index 89e4b8b..c07d49f 100644 --- a/src/main/java/com/jenny/advancedarrows/entities/breachingArrow.java +++ b/src/main/java/com/jenny/advancedarrows/entities/breachingArrow.java @@ -2,8 +2,7 @@ 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 com.jenny.advancedarrows.particles.particles; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -19,6 +18,8 @@ import java.util.ArrayList; import java.util.List; public class breachingArrow extends baseArrow{ + static final int range = 4; + public breachingArrow(EntityType pEntityType, Level pLevel) { super(pEntityType, pLevel); } @@ -27,6 +28,14 @@ public class breachingArrow extends baseArrow{ super(pLevel, pShooter, entities.ARROW_BREACHING.get()); } + @Override + public void tick() { + super.tick(); + if (level().isClientSide && inGround && inGroundTime == 1) { + spawnBreachParticles(); + } + } + @Override protected void onHit(@NotNull HitResult pResult) { for (Entity entity : getEntities()) { @@ -37,17 +46,34 @@ public class breachingArrow extends baseArrow{ protected List getEntities() { List ret_list = new ArrayList<>(); - Vec3 corner1 = position().subtract(4, 4, 4); - Vec3 corner2 = position().add(4, 4, 4); + Vec3 corner1 = position().subtract(range, range, range); + Vec3 corner2 = position().add(range, range, range); AABB boundingBox = new AABB(corner1, corner2); for (Entity entity : level().getEntitiesOfClass(LivingEntity.class, boundingBox)) { - if (entity.getBoundingBox().intersects(position(), position().add(getDeltaMovement().normalize().scale(10)))) { + if (entity.getBoundingBox().intersects(position(), position().add(getDeltaMovement().normalize().scale(range)))) { ret_list.add(entity); } } return ret_list; } + protected void spawnBreachParticles() { + int max = ConfigClient.calcPCount(20); + Vec3 delta = getDeltaMovement().normalize().scale(range); + for (int i = 0; i < max; i++) { + Vec3 pos = position().add(delta.scale((float) i / (max - 1))); + level().addParticle(particles.PARTICLE_BREACHING_ARROW.get(), pos.x, pos.y, pos.z, 0, 0, 0); + } + } + + @Override + public void spawnParticles() { + for (int i = 1; i <= ConfigClient.calcPCount(5); i++) { + Vec3 pos = createParticlePos(1f); + level().addParticle(particles.PARTICLE_BREACHING_ARROW.get(), pos.x, pos.y, pos.z, 0, 0, 0); + } + } + @NotNull protected ItemStack getPickupItem() { return new ItemStack(items.ARROW_BREACHING.get()); diff --git a/src/main/java/com/jenny/advancedarrows/entities/enderArrow.java b/src/main/java/com/jenny/advancedarrows/entities/enderArrow.java index 288be72..e5e4d8d 100644 --- a/src/main/java/com/jenny/advancedarrows/entities/enderArrow.java +++ b/src/main/java/com/jenny/advancedarrows/entities/enderArrow.java @@ -47,7 +47,7 @@ public class enderArrow extends baseArrow { 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); + level().addParticle(ParticleTypes.GLOW, 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 1dcba68..559a2bf 100644 --- a/src/main/java/com/jenny/advancedarrows/entities/entities.java +++ b/src/main/java/com/jenny/advancedarrows/entities/entities.java @@ -12,7 +12,7 @@ import net.minecraftforge.registries.RegistryObject; import static com.jenny.advancedarrows.advancedArrows.MODID; public class entities { - private static final int tr = 16; + private static final int tr = 32; private static final float w = 0.5f; private static final float h = 0.5f; diff --git a/src/main/java/com/jenny/advancedarrows/entities/homingArrow.java b/src/main/java/com/jenny/advancedarrows/entities/homingArrow.java index 57a267e..cd2478c 100644 --- a/src/main/java/com/jenny/advancedarrows/entities/homingArrow.java +++ b/src/main/java/com/jenny/advancedarrows/entities/homingArrow.java @@ -1,6 +1,7 @@ package com.jenny.advancedarrows.entities; import com.jenny.advancedarrows.config.ConfigClient; +import com.jenny.advancedarrows.config.ConfigCommon; import com.jenny.advancedarrows.items.items; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.world.entity.EntityType; @@ -78,8 +79,10 @@ public class homingArrow extends baseArrow { AABB boundingBox = new AABB(corner1, corner2); for (LivingEntity entity : level().getEntitiesOfClass(LivingEntity.class, boundingBox)) { - if (entity.getUUID() != getOwner().getUUID()) { - ret_list.add(entity); + if (entity.getUUID() != getOwner().getUUID()) { // prevents targeting itself + if (level().getPlayerByUUID(entity.getUUID()) == null || ConfigCommon.C_AIMBOT_PLAYER.get()) { // prevent aiming at player if config says so + ret_list.add(entity); + } } } return ret_list; diff --git a/src/main/java/com/jenny/advancedarrows/entities/incendiaryArrow.java b/src/main/java/com/jenny/advancedarrows/entities/incendiaryArrow.java index 299ec01..c6cfc34 100644 --- a/src/main/java/com/jenny/advancedarrows/entities/incendiaryArrow.java +++ b/src/main/java/com/jenny/advancedarrows/entities/incendiaryArrow.java @@ -2,7 +2,6 @@ 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; @@ -20,6 +19,11 @@ public class incendiaryArrow extends baseArrow{ super(pLevel, pShooter, entities.ARROW_INCENDIARY.get()); } + public incendiaryArrow(Level pLevel, double x, double y, double z) { + super(entities.ARROW_INCENDIARY.get(), pLevel); + setPos(x, y, z); + } + @Override protected void doPostHurtEffects(@NotNull LivingEntity pTarget) { pTarget.setSecondsOnFire(5); @@ -34,9 +38,8 @@ public class incendiaryArrow extends baseArrow{ public void spawnParticles() { for (int i = 1; i <= ConfigClient.calcPCount(5); i++) { double m = (double) level().getRandom().nextIntBetweenInclusive(- 100, 100) / 100; - Vec3 DeltaMovement = getDeltaMovement(); Vec3 pos = createParticlePos(1f); - level().addParticle(ParticleTypes.FLAME, pos.x, pos.y, pos.z, DeltaMovement.x, DeltaMovement.y, DeltaMovement.z); + level().addParticle(ParticleTypes.FLAME, pos.x, pos.y, pos.z, 0, 0, 0); } } } diff --git a/src/main/java/com/jenny/advancedarrows/entities/kineticArrow.java b/src/main/java/com/jenny/advancedarrows/entities/kineticArrow.java index e300f63..3e82ec4 100644 --- a/src/main/java/com/jenny/advancedarrows/entities/kineticArrow.java +++ b/src/main/java/com/jenny/advancedarrows/entities/kineticArrow.java @@ -2,18 +2,13 @@ package com.jenny.advancedarrows.entities; import com.jenny.advancedarrows.config.ConfigClient; import com.jenny.advancedarrows.items.items; -import net.minecraft.core.BlockPos; 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.level.block.state.BlockState; -import net.minecraft.world.level.gameevent.GameEvent; -import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.EntityHitResult; -import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/jenny/advancedarrows/entities/ricochetArrow.java b/src/main/java/com/jenny/advancedarrows/entities/ricochetArrow.java index f9aba29..f835812 100644 --- a/src/main/java/com/jenny/advancedarrows/entities/ricochetArrow.java +++ b/src/main/java/com/jenny/advancedarrows/entities/ricochetArrow.java @@ -1,13 +1,11 @@ package com.jenny.advancedarrows.entities; import com.jenny.advancedarrows.items.items; - 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.Vec3; - import org.jetbrains.annotations.NotNull; public class ricochetArrow extends baseArrow{ diff --git a/src/main/java/com/jenny/advancedarrows/entities/switchArrow.java b/src/main/java/com/jenny/advancedarrows/entities/switchArrow.java index ef2e92c..e526de8 100644 --- a/src/main/java/com/jenny/advancedarrows/entities/switchArrow.java +++ b/src/main/java/com/jenny/advancedarrows/entities/switchArrow.java @@ -2,19 +2,13 @@ package com.jenny.advancedarrows.entities; import com.jenny.advancedarrows.config.ConfigClient; import com.jenny.advancedarrows.items.items; -import net.minecraft.core.BlockPos; 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.level.block.state.BlockState; -import net.minecraft.world.level.gameevent.GameEvent; -import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.EntityHitResult; -import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; @@ -27,6 +21,11 @@ public class switchArrow extends baseArrow{ super(pLevel, pShooter, entities.ARROW_SWITCH.get()); } + public switchArrow(Level pLevel, double x, double y, double z) { + super(entities.ARROW_SWITCH.get(), pLevel); + setPos(x, y, z); + } + @Override protected void onHitEntity(@NotNull EntityHitResult pTarget) { super.onHitEntity(pTarget); diff --git a/src/main/java/com/jenny/advancedarrows/eventBusEvents.java b/src/main/java/com/jenny/advancedarrows/eventBusEvents.java new file mode 100644 index 0000000..df730c4 --- /dev/null +++ b/src/main/java/com/jenny/advancedarrows/eventBusEvents.java @@ -0,0 +1,19 @@ +package com.jenny.advancedarrows; + +import com.jenny.advancedarrows.particles.ArrowParticle; +import net.minecraft.client.Minecraft; +import net.minecraftforge.client.event.RegisterParticleProvidersEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; + +import static com.jenny.advancedarrows.advancedArrows.MODID; +import static com.jenny.advancedarrows.particles.particles.PARTICLE_BREACHING_ARROW; + +@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD) +public class eventBusEvents { + @SubscribeEvent + public static void registerParticleFactories(final RegisterParticleProvidersEvent event) { + //particles.registerClient(Minecraft.getInstance().particleEngine); + Minecraft.getInstance().particleEngine.register(PARTICLE_BREACHING_ARROW.get(), ArrowParticle.Provider::new); + } +} diff --git a/src/main/java/com/jenny/advancedarrows/items/ArrowBreaching.java b/src/main/java/com/jenny/advancedarrows/items/ArrowBreaching.java index b0d5c4b..9e83c6c 100644 --- a/src/main/java/com/jenny/advancedarrows/items/ArrowBreaching.java +++ b/src/main/java/com/jenny/advancedarrows/items/ArrowBreaching.java @@ -1,7 +1,6 @@ package com.jenny.advancedarrows.items; import com.jenny.advancedarrows.entities.breachingArrow; -import com.jenny.advancedarrows.entities.switchArrow; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.projectile.AbstractArrow; import net.minecraft.world.item.ItemStack; diff --git a/src/main/java/com/jenny/advancedarrows/items/ArrowIncendiary.java b/src/main/java/com/jenny/advancedarrows/items/ArrowIncendiary.java index 23a15b3..e453d7e 100644 --- a/src/main/java/com/jenny/advancedarrows/items/ArrowIncendiary.java +++ b/src/main/java/com/jenny/advancedarrows/items/ArrowIncendiary.java @@ -1,7 +1,6 @@ package com.jenny.advancedarrows.items; import com.jenny.advancedarrows.entities.incendiaryArrow; - import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.projectile.AbstractArrow; import net.minecraft.world.item.ItemStack; diff --git a/src/main/java/com/jenny/advancedarrows/items/ArrowKinetic.java b/src/main/java/com/jenny/advancedarrows/items/ArrowKinetic.java index 06cb372..fd84403 100644 --- a/src/main/java/com/jenny/advancedarrows/items/ArrowKinetic.java +++ b/src/main/java/com/jenny/advancedarrows/items/ArrowKinetic.java @@ -1,6 +1,5 @@ package com.jenny.advancedarrows.items; -import com.jenny.advancedarrows.entities.incendiaryArrow; import com.jenny.advancedarrows.entities.kineticArrow; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.projectile.AbstractArrow; diff --git a/src/main/java/com/jenny/advancedarrows/items/ArrowRicochet.java b/src/main/java/com/jenny/advancedarrows/items/ArrowRicochet.java index e808957..6fb2bbf 100644 --- a/src/main/java/com/jenny/advancedarrows/items/ArrowRicochet.java +++ b/src/main/java/com/jenny/advancedarrows/items/ArrowRicochet.java @@ -1,6 +1,5 @@ package com.jenny.advancedarrows.items; -import com.jenny.advancedarrows.entities.incendiaryArrow; import com.jenny.advancedarrows.entities.ricochetArrow; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.projectile.AbstractArrow; diff --git a/src/main/java/com/jenny/advancedarrows/items/ArrowSharpened.java b/src/main/java/com/jenny/advancedarrows/items/ArrowSharpened.java index 985f0b1..ce98fb3 100644 --- a/src/main/java/com/jenny/advancedarrows/items/ArrowSharpened.java +++ b/src/main/java/com/jenny/advancedarrows/items/ArrowSharpened.java @@ -1,6 +1,5 @@ package com.jenny.advancedarrows.items; -import com.jenny.advancedarrows.entities.ricochetArrow; import com.jenny.advancedarrows.entities.sharpenedArrow; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.projectile.AbstractArrow; diff --git a/src/main/java/com/jenny/advancedarrows/items/ArrowSwitch.java b/src/main/java/com/jenny/advancedarrows/items/ArrowSwitch.java index 1553a19..5f20c35 100644 --- a/src/main/java/com/jenny/advancedarrows/items/ArrowSwitch.java +++ b/src/main/java/com/jenny/advancedarrows/items/ArrowSwitch.java @@ -1,6 +1,5 @@ package com.jenny.advancedarrows.items; -import com.jenny.advancedarrows.entities.sharpenedArrow; import com.jenny.advancedarrows.entities.switchArrow; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.projectile.AbstractArrow; diff --git a/src/main/java/com/jenny/advancedarrows/items/items.java b/src/main/java/com/jenny/advancedarrows/items/items.java index 7b52d80..bc44ec7 100644 --- a/src/main/java/com/jenny/advancedarrows/items/items.java +++ b/src/main/java/com/jenny/advancedarrows/items/items.java @@ -1,10 +1,21 @@ package com.jenny.advancedarrows.items; +import com.jenny.advancedarrows.entities.baseArrow; +import com.jenny.advancedarrows.entities.entities; +import net.minecraft.core.Position; +import net.minecraft.core.dispenser.AbstractProjectileDispenseBehavior; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.projectile.AbstractArrow; +import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.DispenserBlock; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; +import org.jetbrains.annotations.NotNull; import static com.jenny.advancedarrows.advancedArrows.MODID; @@ -20,8 +31,36 @@ public class items { 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); } + + + public static void registerDispenser() { + class ArrowDispenseBehaviour extends AbstractProjectileDispenseBehavior { + private final EntityType arrowType; + + public ArrowDispenseBehaviour(EntityType arrow) { + this.arrowType = arrow; + } + + @Override + protected @NotNull Projectile getProjectile(@NotNull Level pLevel, @NotNull Position pPosition, @NotNull ItemStack pStack) { + baseArrow arrow = arrowType.create(pLevel); + assert arrow != null; + arrow.setPos(pPosition.x(), pPosition.y(), pPosition.z()); + arrow.pickup = AbstractArrow.Pickup.ALLOWED; + return arrow; + } + } + + DispenserBlock.registerBehavior(ARROW_INCENDIARY.get(), new ArrowDispenseBehaviour(entities.ARROW_INCENDIARY.get())); + DispenserBlock.registerBehavior(ARROW_RICOCHET.get(), new ArrowDispenseBehaviour(entities.ARROW_RICOCHET.get())); + DispenserBlock.registerBehavior(ARROW_KINETIC.get(), new ArrowDispenseBehaviour(entities.ARROW_KINETIC.get())); + DispenserBlock.registerBehavior(ARROW_SHARPENED.get(), new ArrowDispenseBehaviour(entities.ARROW_SHARPENED.get())); + DispenserBlock.registerBehavior(ARROW_SWITCH.get(), new ArrowDispenseBehaviour(entities.ARROW_SWITCH.get())); + DispenserBlock.registerBehavior(ARROW_BREACHING.get(), new ArrowDispenseBehaviour(entities.ARROW_BREACHING.get())); + DispenserBlock.registerBehavior(ARROW_HOMING.get(), new ArrowDispenseBehaviour(entities.ARROW_HOMING.get())); + DispenserBlock.registerBehavior(ARROW_ENDER.get(), new ArrowDispenseBehaviour(entities.ARROW_ENDER.get())); + } } diff --git a/src/main/java/com/jenny/advancedarrows/particles/ArrowParticle.java b/src/main/java/com/jenny/advancedarrows/particles/ArrowParticle.java new file mode 100644 index 0000000..478775e --- /dev/null +++ b/src/main/java/com/jenny/advancedarrows/particles/ArrowParticle.java @@ -0,0 +1,60 @@ +package com.jenny.advancedarrows.particles; + +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.particle.*; +import net.minecraft.core.particles.SimpleParticleType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import org.jetbrains.annotations.NotNull; + +public class ArrowParticle extends TextureSheetParticle { + private final float quadSizeStart; + + protected ArrowParticle(ClientLevel level, double xCoord, double yCoord, double zCoord, + SpriteSet spriteSet, double xd, double yd, double zd) { + super(level, xCoord, yCoord, zCoord, xd, yd, zd); + this.friction = 0.8F; + this.xd = xd; + this.yd = yd; + this.zd = zd; + this.quadSizeStart = this.quadSize; + this.lifetime = 40; + this.setSpriteFromAge(spriteSet); + + this.rCol = 1f; + this.gCol = 1f; + this.bCol = 1f; + } + + @Override + public void tick() { + super.tick(); + fadeOut(); + } + + private void fadeOut() { + this.alpha = (-(1 / (float) lifetime) * age + 1); + this.quadSize = this.quadSizeStart * ((float) age / lifetime); + } + + @Override + @NotNull + public ParticleRenderType getRenderType() { + return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT; + } + + @OnlyIn(Dist.CLIENT) + public static class Provider implements ParticleProvider { + private final SpriteSet sprites; + + public Provider(SpriteSet spriteSet) { + this.sprites = spriteSet; + } + + public Particle createParticle(@NotNull SimpleParticleType particleType, @NotNull ClientLevel level, + double x, double y, double z, + double dx, double dy, double dz) { + return new ArrowParticle(level, x, y, z, this.sprites, dx, dy, dz); + } + } +} diff --git a/src/main/java/com/jenny/advancedarrows/particles/particles.java b/src/main/java/com/jenny/advancedarrows/particles/particles.java new file mode 100644 index 0000000..7ecb653 --- /dev/null +++ b/src/main/java/com/jenny/advancedarrows/particles/particles.java @@ -0,0 +1,27 @@ +package com.jenny.advancedarrows.particles; + +import net.minecraft.client.particle.ParticleEngine; +import net.minecraft.core.particles.ParticleType; +import net.minecraft.core.particles.SimpleParticleType; +import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.registries.DeferredRegister; +import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.registries.RegistryObject; +import org.jetbrains.annotations.NotNull; + +import static com.jenny.advancedarrows.advancedArrows.MODID; + +public class particles { + public static final DeferredRegister> PARTICLES = DeferredRegister.create(ForgeRegistries.PARTICLE_TYPES, MODID); + + public static final RegistryObject PARTICLE_BREACHING_ARROW = + PARTICLES.register("particle_breaching_arrow", () -> new SimpleParticleType(true)); + + public static void register(IEventBus bus) { + PARTICLES.register(bus); + } + + public static void registerClient(@NotNull ParticleEngine pEngine) { + pEngine.register(PARTICLE_BREACHING_ARROW.get(), ArrowParticle.Provider::new); + } +} diff --git a/src/main/resources/assets/advancedarrows/particles/particle_breaching_arrow.json b/src/main/resources/assets/advancedarrows/particles/particle_breaching_arrow.json new file mode 100644 index 0000000..c1e2bf2 --- /dev/null +++ b/src/main/resources/assets/advancedarrows/particles/particle_breaching_arrow.json @@ -0,0 +1,5 @@ +{ + "textures": [ + "advancedarrows:particle_breaching_arrow" + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/advancedarrows/textures/item/arrow_ricochet.png.mcmeta b/src/main/resources/assets/advancedarrows/textures/item/arrow_ricochet.png.mcmeta index 6c5be66..256794b 100644 --- a/src/main/resources/assets/advancedarrows/textures/item/arrow_ricochet.png.mcmeta +++ b/src/main/resources/assets/advancedarrows/textures/item/arrow_ricochet.png.mcmeta @@ -1,10 +1,6 @@ { "animation": { "frametime": 15, - "interpolate": false, - "frames": [ - 0, - 1 - ] + "interpolate": false } } \ No newline at end of file diff --git a/src/main/resources/assets/advancedarrows/textures/particle/particle_breaching_arrow.png b/src/main/resources/assets/advancedarrows/textures/particle/particle_breaching_arrow.png new file mode 100644 index 0000000..d40af1a Binary files /dev/null and b/src/main/resources/assets/advancedarrows/textures/particle/particle_breaching_arrow.png differ diff --git a/src/main/resources/data/minecraft/tags/entity_types/arrows.json b/src/main/resources/data/minecraft/tags/entity_types/arrows.json new file mode 100644 index 0000000..0ef5d26 --- /dev/null +++ b/src/main/resources/data/minecraft/tags/entity_types/arrows.json @@ -0,0 +1,12 @@ +{ + "values": [ + "advancedarrows:arrow_incendiary", + "advancedarrows:arrow_ricochet", + "advancedarrows:arrow_kinetic", + "advancedarrows:arrow_sharpened", + "advancedarrows:arrow_switch", + "advancedarrows:arrow_breaching", + "advancedarrows:arrow_homing", + "advancedarrows:arrow_ender" + ] +} \ No newline at end of file