优化中口径火箭弹注册方式

This commit is contained in:
Light_Quanta 2025-07-13 19:50:23 +08:00
parent ca2bdc884e
commit a26434880d
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
5 changed files with 40 additions and 122 deletions

View file

@ -48,16 +48,17 @@ public class MediumRocketEntity extends FastThrowableProjectile implements GeoEn
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
private boolean ap = true;
private boolean he = false;
private boolean cm = false;
public enum Type {
AP, HE, CM
}
private Type type = Type.AP;
private float damage = 0;
private float radius = 0;
private float explosionDamage = 0;
private float fireProbability = 0;
private int fireTime = 0;
public Set<Long> loadedChunks = new HashSet<>();
private float gravity = 0.05f;
private boolean active;
private int sparedTime;
@ -68,7 +69,7 @@ public class MediumRocketEntity extends FastThrowableProjectile implements GeoEn
this.noCulling = true;
}
public MediumRocketEntity(EntityType<? extends ThrowableItemProjectile> pEntityType, double pX, double pY, double pZ, Level pLevel, float damage, float radius, float explosionDamage, float fireProbability, int fireTime, boolean ap, boolean he, boolean cm, int sparedAmount) {
public MediumRocketEntity(EntityType<? extends ThrowableItemProjectile> pEntityType, double pX, double pY, double pZ, Level pLevel, float damage, float radius, float explosionDamage, float fireProbability, int fireTime, Type type, int sparedAmount) {
super(pEntityType, pX, pY, pZ, pLevel);
this.noCulling = true;
this.damage = damage;
@ -76,13 +77,11 @@ public class MediumRocketEntity extends FastThrowableProjectile implements GeoEn
this.explosionDamage = explosionDamage;
this.fireProbability = fireProbability;
this.fireTime = fireTime;
this.ap = ap;
this.he = he;
this.cm = cm;
this.type = type;
this.sparedAmount = sparedAmount;
}
public MediumRocketEntity(LivingEntity entity, Level world, float damage, float radius, float explosionDamage, float fireProbability, int fireTime, boolean ap, boolean he, boolean cm, int sparedAmount) {
public MediumRocketEntity(LivingEntity entity, Level world, float damage, float radius, float explosionDamage, float fireProbability, int fireTime, Type type, int sparedAmount) {
super(ModEntities.MEDIUM_ROCKET.get(), entity, world);
this.noCulling = true;
this.damage = damage;
@ -90,9 +89,7 @@ public class MediumRocketEntity extends FastThrowableProjectile implements GeoEn
this.explosionDamage = explosionDamage;
this.fireProbability = fireProbability;
this.fireTime = fireTime;
this.ap = ap;
this.he = he;
this.cm = cm;
this.type = type;
this.sparedAmount = sparedAmount;
}
@ -177,7 +174,7 @@ public class MediumRocketEntity extends FastThrowableProjectile implements GeoEn
@Override
public void onHitBlock(@NotNull BlockHitResult blockHitResult) {
if (this.level() instanceof ServerLevel) {
if (he || cm) {
if (type == Type.HE || type == Type.CM) {
causeExplode(blockHitResult.getLocation());
this.discard();
return;
@ -257,7 +254,7 @@ public class MediumRocketEntity extends FastThrowableProjectile implements GeoEn
this.discard();
}
if (cm && getDeltaMovement().y < 0.1 && !active) {
if (type == Type.CM && getDeltaMovement().y < 0.1 && !active) {
if (position().y < level().getMinBuildHeight() || position().y > level().getMaxBuildHeight()) return;
BlockPos hitBlock = ProjectileCalculator.calculateImpactPosition(level(), position(), getDeltaMovement(), -0.05);
@ -331,7 +328,7 @@ public class MediumRocketEntity extends FastThrowableProjectile implements GeoEn
@Override
protected double getDefaultGravity() {
return gravity;
return 0.05f;
}
@Override

View file

@ -1,6 +1,7 @@
package com.atsuishio.superbwarfare.init;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.entity.projectile.MediumRocketEntity;
import com.atsuishio.superbwarfare.item.*;
import com.atsuishio.superbwarfare.item.armor.*;
import com.atsuishio.superbwarfare.item.common.BlueprintItem;
@ -120,9 +121,9 @@ public class ModItems {
public static final DeferredHolder<Item, Blu43MineItem> BLU_43_MINE = AMMO.register("blu_43_mine", Blu43MineItem::new);
public static final DeferredHolder<Item, Item> SMALL_SHELL = AMMO.register("small_shell", SmallShellItem::new);
public static final DeferredHolder<Item, SmallRocketItem> SMALL_ROCKET = AMMO.register("small_rocket", SmallRocketItem::new);
public static final DeferredHolder<Item, MediumRocketAPItem> MEDIUM_ROCKET_AP = AMMO.register("medium_rocket_ap", MediumRocketAPItem::new);
public static final DeferredHolder<Item, MediumRocketHEItem> MEDIUM_ROCKET_HE = AMMO.register("medium_rocket_he", MediumRocketHEItem::new);
public static final DeferredHolder<Item, MediumRocketCMItem> MEDIUM_ROCKET_CM = AMMO.register("medium_rocket_cm", MediumRocketCMItem::new);
public static final DeferredHolder<Item, MediumRocketItem> MEDIUM_ROCKET_AP = AMMO.register("medium_rocket_ap", () -> new MediumRocketItem(500, 6, 100, 0, 0, MediumRocketEntity.Type.AP, 0));
public static final DeferredHolder<Item, MediumRocketItem> MEDIUM_ROCKET_HE = AMMO.register("medium_rocket_he", () -> new MediumRocketItem(200, 12, 200, 0.2f, 40, MediumRocketEntity.Type.HE, 0));
public static final DeferredHolder<Item, MediumRocketItem> MEDIUM_ROCKET_CM = AMMO.register("medium_rocket_cm", () -> new MediumRocketItem(300, 12, 300, 0, 0, MediumRocketEntity.Type.CM, 50));
public static final DeferredHolder<Item, WireGuideMissileItem> WIRE_GUIDE_MISSILE = AMMO.register("wire_guide_missile", WireGuideMissileItem::new);
public static final DeferredHolder<Item, AgmItem> AGM = AMMO.register("agm", AgmItem::new);
public static final DeferredHolder<Item, SwarmDroneItem> SWARM_DRONE = AMMO.register("swarm_drone", SwarmDroneItem::new);
@ -356,9 +357,9 @@ public class ModItems {
DispenserBlock.registerBehavior(RGO_GRENADE.get(), new RgoGrenade.RgoGrenadeDispenserBehavior());
DispenserBlock.registerBehavior(M18_SMOKE_GRENADE.get(), new M18SmokeGrenade.SmokeGrenadeDispenserBehavior());
DispenserBlock.registerBehavior(TM_62.get(), new Tm62Item.Tm62DispenseBehavior());
DispenserBlock.registerBehavior(MEDIUM_ROCKET_AP.get(), new MediumRocketAPItem.MediumRocketDispenseBehavior());
DispenserBlock.registerBehavior(MEDIUM_ROCKET_CM.get(), new MediumRocketCMItem.MediumRocketDispenseBehavior());
DispenserBlock.registerBehavior(MEDIUM_ROCKET_HE.get(), new MediumRocketHEItem.MediumRocketDispenseBehavior());
DispenserBlock.registerBehavior(MEDIUM_ROCKET_AP.get(), new MediumRocketItem.MediumRocketDispenseBehavior(MEDIUM_ROCKET_AP.get()));
DispenserBlock.registerBehavior(MEDIUM_ROCKET_CM.get(), new MediumRocketItem.MediumRocketDispenseBehavior(MEDIUM_ROCKET_CM.get()));
DispenserBlock.registerBehavior(MEDIUM_ROCKET_HE.get(), new MediumRocketItem.MediumRocketDispenseBehavior(MEDIUM_ROCKET_HE.get()));
}
public static void register(IEventBus bus) {

View file

@ -1,48 +0,0 @@
package com.atsuishio.superbwarfare.item.common.ammo;
import com.atsuishio.superbwarfare.entity.projectile.MediumRocketEntity;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import net.minecraft.core.Direction;
import net.minecraft.core.Position;
import net.minecraft.core.dispenser.BlockSource;
import net.minecraft.core.dispenser.ProjectileDispenseBehavior;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ProjectileItem;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
import javax.annotation.ParametersAreNonnullByDefault;
public class MediumRocketCMItem extends Item implements ProjectileItem {
public MediumRocketCMItem() {
super(new Properties());
}
public static class MediumRocketDispenseBehavior extends ProjectileDispenseBehavior {
public MediumRocketDispenseBehavior() {
super(ModItems.MEDIUM_ROCKET_CM.get());
}
@Override
protected void playSound(BlockSource blockSource) {
blockSource.level().playSound(null, blockSource.pos(), ModSounds.SMALL_ROCKET_FIRE_3P.get(), SoundSource.BLOCKS, 2.0F, 1.0F);
}
}
@Override
@ParametersAreNonnullByDefault
public @NotNull Projectile asProjectile(Level level, Position pos, ItemStack stack, Direction direction) {
return new MediumRocketEntity(ModEntities.MEDIUM_ROCKET.get(), pos.x(), pos.y(), pos.z(), level, 300, 12, 300, 0, 0, false, false, true, 50);
}
@Override
public @NotNull ProjectileItem.DispenseConfig createDispenseConfig() {
return ProjectileItem.DispenseConfig.builder().power(6).build();
}
}

View file

@ -1,47 +0,0 @@
package com.atsuishio.superbwarfare.item.common.ammo;
import com.atsuishio.superbwarfare.entity.projectile.MediumRocketEntity;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import net.minecraft.core.Direction;
import net.minecraft.core.Position;
import net.minecraft.core.dispenser.ProjectileDispenseBehavior;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ProjectileItem;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
import javax.annotation.ParametersAreNonnullByDefault;
public class MediumRocketHEItem extends Item implements ProjectileItem {
public MediumRocketHEItem() {
super(new Properties());
}
public static class MediumRocketDispenseBehavior extends ProjectileDispenseBehavior {
public MediumRocketDispenseBehavior() {
super(ModItems.MEDIUM_ROCKET_HE.get());
}
@Override
protected void playSound(net.minecraft.core.dispenser.BlockSource blockSource) {
blockSource.level().playSound(null, blockSource.pos(), ModSounds.SMALL_ROCKET_FIRE_3P.get(), SoundSource.BLOCKS, 2.0F, 1.0F);
}
}
@Override
@ParametersAreNonnullByDefault
public @NotNull Projectile asProjectile(Level level, Position pos, ItemStack stack, Direction direction) {
return new MediumRocketEntity(ModEntities.MEDIUM_ROCKET.get(), pos.x(), pos.y(), pos.z(), level, 200, 12, 200, 0.2f, 40, false, true, false, 0);
}
@Override
public @NotNull DispenseConfig createDispenseConfig() {
return DispenseConfig.builder().power(6).build();
}
}

View file

@ -2,7 +2,6 @@ package com.atsuishio.superbwarfare.item.common.ammo;
import com.atsuishio.superbwarfare.entity.projectile.MediumRocketEntity;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import net.minecraft.core.Direction;
import net.minecraft.core.Position;
@ -18,15 +17,31 @@ import org.jetbrains.annotations.NotNull;
import javax.annotation.ParametersAreNonnullByDefault;
public class MediumRocketAPItem extends Item implements ProjectileItem {
public class MediumRocketItem extends Item implements ProjectileItem {
public MediumRocketAPItem() {
private final float damage;
private final float radius;
private final float explosionDamage;
private final float fireProbability;
private final int fireTime;
private final MediumRocketEntity.Type type;
private final int sparedAmount;
public MediumRocketItem(float damage, float radius, float explosionDamage, float fireProbability, int fireTime, MediumRocketEntity.Type type, int sparedAmount) {
super(new Properties());
this.damage = damage;
this.radius = radius;
this.explosionDamage = explosionDamage;
this.fireProbability = fireProbability;
this.fireTime = fireTime;
this.type = type;
this.sparedAmount = sparedAmount;
}
public static class MediumRocketDispenseBehavior extends ProjectileDispenseBehavior {
public MediumRocketDispenseBehavior() {
super(ModItems.MEDIUM_ROCKET_AP.get());
public MediumRocketDispenseBehavior(Item item) {
super(item);
}
@Override
@ -38,7 +53,7 @@ public class MediumRocketAPItem extends Item implements ProjectileItem {
@Override
@ParametersAreNonnullByDefault
public @NotNull Projectile asProjectile(Level level, Position pos, ItemStack stack, Direction direction) {
return new MediumRocketEntity(ModEntities.MEDIUM_ROCKET.get(), pos.x(), pos.y(), pos.z(), level, 500, 6, 100, 0, 0, true, false, false, 0);
return new MediumRocketEntity(ModEntities.MEDIUM_ROCKET.get(), pos.x(), pos.y(), pos.z(), level, damage, radius, explosionDamage, fireProbability, fireTime, type, sparedAmount);
}
@Override