diff --git a/src/api/java/blusunrize/immersiveengineering/api/tool/BulletHandler.java b/src/api/java/blusunrize/immersiveengineering/api/tool/BulletHandler.java index be20c24911..e097475705 100644 --- a/src/api/java/blusunrize/immersiveengineering/api/tool/BulletHandler.java +++ b/src/api/java/blusunrize/immersiveengineering/api/tool/BulletHandler.java @@ -8,6 +8,7 @@ package blusunrize.immersiveengineering.api.tool; +import blusunrize.immersiveengineering.api.utils.Color4; import blusunrize.immersiveengineering.api.utils.SetRestrictedField; import com.google.common.base.Preconditions; import com.google.common.base.Supplier; @@ -124,13 +125,16 @@ default int getProjectileCount(@Nullable Player shooter) */ default Entity getProjectile(@Nullable Player shooter, StackData data, Entity projectile, boolean charged) { + // TODO why is charged not passed through globally? return projectile; } /** * called when the bullet hits a target */ - void onHitTarget(Level world, HitResult target, @Nullable UUID shooter, Entity projectile, boolean headshot); + void onHitTarget( + Level world, HitResult target, @Nullable UUID shooter, Entity projectile, boolean headshot, + StackData bulletData); /** * @return the casing left when fired. Can return the static ItemStacks in BulletHandler @@ -145,7 +149,10 @@ default Entity getProjectile(@Nullable Player shooter, StackData data, Entity pr /** * @return the colour applied to the given layer */ - int getColour(StackData data, int layer); + default Color4 getColour(StackData data, int layer) + { + return Color4.WHITE; + } /** * @return whether this cartridge should be allowed to be placed in, and used from a turret.
@@ -207,7 +214,7 @@ protected float getDamage(Entity hitEntity, boolean headshot) } @Override - public void onHitTarget(Level world, HitResult rtr, @Nullable UUID shooterUUID, Entity projectile, boolean headshot) + public void onHitTarget(Level world, HitResult rtr, @Nullable UUID shooterUUID, Entity projectile, boolean headshot, StackData bulletData) { if(!(rtr instanceof EntityHitResult)) return; @@ -240,12 +247,6 @@ public ResourceLocation[] getTextures() return textures; } - @Override - public int getColour(StackData data, int layer) - { - return 0xffffffff; - } - @Override public boolean isValidForTurret() { diff --git a/src/api/java/blusunrize/immersiveengineering/api/utils/Color4.java b/src/api/java/blusunrize/immersiveengineering/api/utils/Color4.java index 1d09a8d512..452755e477 100644 --- a/src/api/java/blusunrize/immersiveengineering/api/utils/Color4.java +++ b/src/api/java/blusunrize/immersiveengineering/api/utils/Color4.java @@ -14,6 +14,7 @@ import malte0811.dualcodecs.DualCompositeCodecs; import net.minecraft.nbt.Tag; import net.minecraft.world.item.DyeColor; +import org.joml.Vector3f; public record Color4(float r, float g, float b, float a) { @@ -68,4 +69,9 @@ public int toInt() final int aInt = (int)(255*a); return (aInt<<24)|(rInt<<16)|(gInt<<8)|bInt; } + + public Vector3f toVector3f() + { + return new Vector3f(r, g, b); + } } diff --git a/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/TurretGunBlockEntity.java b/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/TurretGunBlockEntity.java index 8e643976a4..174ffb6eed 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/TurretGunBlockEntity.java +++ b/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/TurretGunBlockEntity.java @@ -12,7 +12,6 @@ import blusunrize.immersiveengineering.api.tool.BulletHandler.IBullet; import blusunrize.immersiveengineering.common.blocks.BlockCapabilityRegistration.BECapabilityRegistrar; import blusunrize.immersiveengineering.common.config.IEServerConfig; -import blusunrize.immersiveengineering.common.entities.RevolvershotEntity; import blusunrize.immersiveengineering.common.items.BulletItem; import blusunrize.immersiveengineering.common.network.MessageBlockEntitySync; import blusunrize.immersiveengineering.common.register.IEMenuTypes; @@ -33,7 +32,6 @@ import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ChunkPos; -import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; @@ -91,7 +89,7 @@ protected void activate() ItemStack bulletStack = inventory.get(0); if(bulletStack.getItem() instanceof BulletItem&&this.energyStorage.extractEnergy(energy, true)==energy) { - IBullet bullet = ((BulletItem)bulletStack.getItem()).getType(); + IBullet bullet = ((BulletItem)bulletStack.getItem()).getType(); if(bullet!=null&&bullet.isValidForTurret()) { ItemStack casing = bullet.getCasing(bulletStack); @@ -105,16 +103,12 @@ protected void activate() int count = bullet.getProjectileCount(null); if(count==1) - { - Entity entBullet = getBulletEntity(level, vec, bullet); - level.addFreshEntity(bullet.getProjectile(null, bulletStack, entBullet, false)); - } + level.addFreshEntity(getBulletEntity(vec, bulletStack)); else for(int i = 0; i < count; i++) { Vec3 vecDir = vec.add(ApiUtils.RANDOM.nextGaussian()*.1, ApiUtils.RANDOM.nextGaussian()*.1, ApiUtils.RANDOM.nextGaussian()*.1); - Entity entBullet = getBulletEntity(level, vecDir, bullet); - level.addFreshEntity(bullet.getProjectile(null, bulletStack, entBullet, false)); + level.addFreshEntity(getBulletEntity(vecDir, bulletStack)); } bulletStack.shrink(1); if(bulletStack.getCount() <= 0) @@ -158,12 +152,11 @@ protected void sendRenderPacket() ); } - RevolvershotEntity getBulletEntity(Level world, Vec3 vecDir, IBullet type) + private Entity getBulletEntity(Vec3 vecDir, ItemStack bulletStack) { - Vec3 gunPos = getGunPosition(); - RevolvershotEntity bullet = new RevolvershotEntity(world, gunPos.x+vecDir.x, gunPos.y+vecDir.y, gunPos.z+vecDir.z, 0, 0, 0, type); - bullet.setDeltaMovement(vecDir); - return bullet; + return ((BulletItem)bulletStack.getItem()).createBullet( + level, null, getGunPosition(), vecDir, bulletStack, false + ); } @Override diff --git a/src/main/java/blusunrize/immersiveengineering/common/entities/RevolvershotEntity.java b/src/main/java/blusunrize/immersiveengineering/common/entities/RevolvershotEntity.java index 13801e6f88..7bc7ce9c2b 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/entities/RevolvershotEntity.java +++ b/src/main/java/blusunrize/immersiveengineering/common/entities/RevolvershotEntity.java @@ -10,14 +10,22 @@ import blusunrize.immersiveengineering.api.tool.BulletHandler; import blusunrize.immersiveengineering.api.tool.BulletHandler.IBullet; +import blusunrize.immersiveengineering.common.items.bullets.IEBullets; import blusunrize.immersiveengineering.common.network.MessageBirthdayParty; +import blusunrize.immersiveengineering.common.register.IEEntityDataSerializers; import blusunrize.immersiveengineering.common.register.IEEntityTypes; import blusunrize.immersiveengineering.common.util.EnergyHelper; import blusunrize.immersiveengineering.common.util.IESounds; import blusunrize.immersiveengineering.common.util.Utils; +import com.google.common.base.Preconditions; +import malte0811.dualcodecs.DualCodec; +import malte0811.dualcodecs.DualCodecs; +import malte0811.dualcodecs.DualMapCodec; import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.network.syncher.SynchedEntityData.Builder; import net.minecraft.sounds.SoundSource; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.effect.MobEffectInstance; @@ -35,11 +43,16 @@ import net.minecraft.world.phys.Vec3; import net.neoforged.neoforge.network.PacketDistributor; +import java.util.UUID; + public class RevolvershotEntity extends IEProjectileEntity { - private IBullet bulletType; + private static final EntityDataAccessor> DATAMARKER_BULLET = SynchedEntityData.defineId( + RevolvershotEntity.class, IEEntityDataSerializers.BULLET.get() + ); + + private BulletData bullet; public boolean bulletElectro = false; - public ItemStack bulletPotion = ItemStack.EMPTY; private float gravity; private float movementDecay; @@ -48,28 +61,43 @@ public RevolvershotEntity(EntityType type, Level w super(type, world); } - public RevolvershotEntity(EntityType eType, Level world, LivingEntity shooter, double x, double y, double z, - double ax, double ay, double az, IBullet type) + public RevolvershotEntity( + EntityType eType, Level world, LivingEntity shooter, + double x, double y, double z, double ax, double ay, double az, + IBullet bullet, T bulletData + ) { super(eType, world, shooter, x, y, z, ax, ay, az); this.setPos(x, y, z); - this.bulletType = type; + this.bullet = new BulletData<>(bullet, bulletData); + this.entityData.set(DATAMARKER_BULLET, this.bullet); } - public RevolvershotEntity(Level world, double x, double y, double z, - double ax, double ay, double az, IBullet type) + public RevolvershotEntity( + Level world, + double x, double y, double z, double ax, double ay, double az, + IBullet bullet, T bulletData + ) { - this(IEEntityTypes.REVOLVERSHOT.get(), world, null, x, y, z, ax, ay, az, type); + this(IEEntityTypes.REVOLVERSHOT.get(), world, null, x, y, z, ax, ay, az, bullet, bulletData); } - public RevolvershotEntity(Level world, LivingEntity living, double ax, double ay, double az, IBullet type) + public RevolvershotEntity( + Level world, LivingEntity living, + double ax, double ay, double az, + IBullet bullet, T bulletData + ) { - this(IEEntityTypes.REVOLVERSHOT.get(), world, living, ax, ay, az, type); + this(IEEntityTypes.REVOLVERSHOT.get(), world, living, ax, ay, az, bullet, bulletData); } - public RevolvershotEntity(EntityType eType, Level world, LivingEntity living, double ax, double ay, double az, IBullet type) + public RevolvershotEntity( + EntityType eType, Level world, LivingEntity living, + double ax, double ay, double az, + IBullet bullet, T bulletData + ) { - this(eType, world, living, living.getX()+ax, living.getY()+living.getEyeHeight()+ay, living.getZ()+az, ax, ay, az, type); + this(eType, world, living, living.getX()+ax, living.getY()+living.getEyeHeight()+ay, living.getZ()+az, ax, ay, az, bullet, bulletData); setShooterSynced(); setDeltaMovement(Vec3.ZERO); } @@ -82,6 +110,21 @@ public boolean shouldRenderAtSqrDistance(double distance) return distance < d1*d1; } + @Override + protected void defineSynchedData(Builder builder) + { + super.defineSynchedData(builder); + builder.define(DATAMARKER_BULLET, new BulletData<>(BulletHandler.getBullet(IEBullets.CASULL))); + } + + public BulletData getBullet() + { + if(level().isClientSide) + return entityData.get(DATAMARKER_BULLET); + else + return bullet; + } + @Override public void onHit(HitResult mop) { @@ -93,9 +136,9 @@ public void onHit(HitResult mop) headshot = Utils.isVecInEntityHead((LivingEntity)hitEntity, position()); } - if(this.bulletType!=null) + if(this.bullet!=null) { - bulletType.onHitTarget(level(), mop, this.shooterUUID, this, headshot); + bullet.onHitTarget(level(), mop, this.shooterUUID, this, headshot); if(mop instanceof EntityHitResult) { Entity hitEntity = ((EntityHitResult)mop).getEntity(); @@ -125,7 +168,7 @@ public void secondaryImpact(HitResult mop) if(bulletElectro&&hitEntity instanceof LivingEntity&&shooterUUID!=null) { Player shooter = level().getPlayerByUUID(shooterUUID); - float percentualDrain = .15f/(bulletType==null?1: bulletType.getProjectileCount(shooter)); + float percentualDrain = .15f/(bullet==null?1: bullet.bullet.getProjectileCount(shooter)); ((LivingEntity)hitEntity).addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 15, 4)); for(EquipmentSlot slot : EquipmentSlot.values()) { @@ -151,18 +194,14 @@ public void addAdditionalSaveData(CompoundTag nbt) { super.addAdditionalSaveData(nbt); nbt.putByte("inGround", (byte)(this.inGround?1: 0)); - nbt.putString("bulletType", BulletHandler.findRegistryName(this.bulletType).toString()); - if(!bulletPotion.isEmpty()) - nbt.put("bulletPotion", bulletPotion.save(level().registryAccess())); + nbt.put("bullet", BulletData.CODECS.toNBT(bullet)); } @Override public void readAdditionalSaveData(CompoundTag nbt) { super.readAdditionalSaveData(nbt); - this.bulletType = BulletHandler.getBullet(ResourceLocation.parse(nbt.getString("bulletType"))); - if(nbt.contains("bulletPotion", Tag.TAG_COMPOUND)) - this.bulletPotion = ItemStack.parseOptional(level().registryAccess(), nbt.getCompound("bulletPotion")); + this.bullet = BulletData.CODECS.fromNBT(nbt.get("bullet")); } @Override @@ -210,4 +249,44 @@ protected float getMotionDecayFactor() { return movementDecay; } + + public record BulletData(IBullet bullet, T data) + { + public static final DualCodec> CODECS = DualCodecs.RESOURCE_LOCATION + .castStream() + .dispatch( + bd -> BulletHandler.findRegistryName(bd.bullet), + rl -> specificCodec(BulletHandler.getBullet(rl)) + ); + + public BulletData(IBullet bullet) + { + this(bullet, bullet.getCodec().defaultValue()); + } + + public void onHitTarget( + Level level, HitResult mop, UUID shooterUUID, RevolvershotEntity revolvershotEntity, boolean headshot + ) + { + bullet.onHitTarget(level, mop, shooterUUID, revolvershotEntity, headshot, data); + } + + public T1 getForOptional(IBullet type) + { + return type==bullet?(T1)data: null; + } + + public T1 getFor(IBullet type) + { + return Preconditions.checkNotNull(getForOptional(type)); + } + + private static DualMapCodec> specificCodec(IBullet bullet) + { + DualCodec> codec = bullet.getCodec().codecs().map( + t -> new BulletData<>(bullet, t), bd -> (T)bd.data + ); + return codec.castStream().fieldOf("data"); + } + } } \ No newline at end of file diff --git a/src/main/java/blusunrize/immersiveengineering/common/entities/RevolvershotFlareEntity.java b/src/main/java/blusunrize/immersiveengineering/common/entities/RevolvershotFlareEntity.java index 3b3f5ad806..bcf8b4d801 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/entities/RevolvershotFlareEntity.java +++ b/src/main/java/blusunrize/immersiveengineering/common/entities/RevolvershotFlareEntity.java @@ -9,14 +9,11 @@ package blusunrize.immersiveengineering.common.entities; import blusunrize.immersiveengineering.api.ApiUtils; -import blusunrize.immersiveengineering.api.tool.BulletHandler.IBullet; +import blusunrize.immersiveengineering.api.utils.Color4; +import blusunrize.immersiveengineering.common.items.bullets.IEBullets; import blusunrize.immersiveengineering.common.register.IEEntityTypes; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.DustParticleOptions; -import net.minecraft.network.syncher.EntityDataAccessor; -import net.minecraft.network.syncher.EntityDataSerializers; -import net.minecraft.network.syncher.SynchedEntityData; -import net.minecraft.network.syncher.SynchedEntityData.Builder; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -26,12 +23,9 @@ import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; -import org.joml.Vector3f; public class RevolvershotFlareEntity extends RevolvershotEntity { - public int colour = -1; - private static final EntityDataAccessor dataMarker_colour = SynchedEntityData.defineId(RevolvershotFlareEntity.class, EntityDataSerializers.INT); private BlockPos lightPos; public RevolvershotFlareEntity(EntityType type, Level world) @@ -40,57 +34,36 @@ public RevolvershotFlareEntity(EntityType type, Level w this.setTickLimit(400); } - public RevolvershotFlareEntity(Level world, double x, double y, double z, double ax, double ay, double az, IBullet type) + public RevolvershotFlareEntity(Level world, double x, double y, double z, double ax, double ay, double az, Color4 color) { - super(IEEntityTypes.FLARE_REVOLVERSHOT.get(), world, null, x, y, z, ax, ay, az, type); + super(IEEntityTypes.FLARE_REVOLVERSHOT.get(), world, null, x, y, z, ax, ay, az, IEBullets.FLARE_TYPE, color); this.setTickLimit(400); } - public RevolvershotFlareEntity(Level world, LivingEntity living, double ax, double ay, double az, IBullet type) + public RevolvershotFlareEntity(Level world, LivingEntity living, double ax, double ay, double az, Color4 color) { - super(IEEntityTypes.FLARE_REVOLVERSHOT.get(), world, living, ax, ay, az, type); + super(IEEntityTypes.FLARE_REVOLVERSHOT.get(), world, living, ax, ay, az, IEBullets.FLARE_TYPE, color); this.setTickLimit(400); } - @Override - protected void defineSynchedData(Builder builder) - { - super.defineSynchedData(builder); - builder.define(dataMarker_colour, -1); - } - - public void setColourSynced() - { - this.entityData.set(dataMarker_colour, colour); - } - - public int getColourSynced() - { - return this.entityData.get(dataMarker_colour); - } - - public int getColour() + public Color4 getColour() { - return colour; + return getBullet().getFor(IEBullets.FLARE_TYPE); } @Override public void tick() { super.tick(); - if(colour < 0) - colour = getColourSynced(); if(level().isClientSide) { - float r = (getColour()>>16&255)/255f; - float g = (getColour()>>8&255)/255f; - float b = (getColour()&255)/255f; - level().addParticle(new DustParticleOptions(new Vector3f(r, g, b), 1), getX(), getY(), getZ(), 0, 0, 0); + var color = getColour(); + level().addParticle(new DustParticleOptions(color.toVector3f(), 1), getX(), getY(), getZ(), 0, 0, 0); if(tickCount > 40) for(int i = 0; i < 20; i++) { Vec3 v = new Vec3(ApiUtils.RANDOM.nextDouble()-.5, ApiUtils.RANDOM.nextDouble()-.5, ApiUtils.RANDOM.nextDouble()-.5); - level().addParticle(new DustParticleOptions(new Vector3f(r, g, b), 1), getX()+v.x, getY()+v.y, getZ()+v.z, v.x/10, v.y/10, v.z/10); + level().addParticle(new DustParticleOptions(color.toVector3f(), 1), getX()+v.x, getY()+v.y, getZ()+v.z, v.x/10, v.y/10, v.z/10); } } if(tickCount==40) @@ -135,13 +108,10 @@ else if(mop instanceof BlockHitResult) private void spawnParticles() { - float r = (getColour() >> 16&255)/255f; - float g = (getColour() >> 8&255)/255f; - float b = (getColour()&255)/255f; for(int i = 0; i < 80; i++) { Vec3 v = new Vec3((ApiUtils.RANDOM.nextDouble()-.5)*i > 40?2: 1, (ApiUtils.RANDOM.nextDouble()-.5)*i > 40?2: 1, (ApiUtils.RANDOM.nextDouble()-.5)*i > 40?2: 1); - level().addParticle(new DustParticleOptions(new Vector3f(r, g, b), 1), getX()+v.x, getY()+v.y, getZ()+v.z, v.x/10, v.y/10, v.z/10); + level().addParticle(new DustParticleOptions(getColour().toVector3f(), 1), getX()+v.x, getY()+v.y, getZ()+v.z, v.x/10, v.y/10, v.z/10); } } } \ No newline at end of file diff --git a/src/main/java/blusunrize/immersiveengineering/common/entities/RevolvershotHomingEntity.java b/src/main/java/blusunrize/immersiveengineering/common/entities/RevolvershotHomingEntity.java index 0858f710d5..16559fff6c 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/entities/RevolvershotHomingEntity.java +++ b/src/main/java/blusunrize/immersiveengineering/common/entities/RevolvershotHomingEntity.java @@ -10,6 +10,7 @@ import blusunrize.immersiveengineering.api.tool.BulletHandler.IBullet; import blusunrize.immersiveengineering.common.register.IEEntityTypes; +import com.mojang.datafixers.util.Unit; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.Level; @@ -27,24 +28,24 @@ public RevolvershotHomingEntity(EntityType t super(type, world); } - public RevolvershotHomingEntity(EntityType eType, Level world, double x, double y, double z, double ax, double ay, double az, IBullet type) + public RevolvershotHomingEntity(EntityType eType, Level world, double x, double y, double z, double ax, double ay, double az, IBullet type) { - super(eType, world, null, x, y, z, ax, ay, az, type); + super(eType, world, null, x, y, z, ax, ay, az, type, Unit.INSTANCE); } - public RevolvershotHomingEntity(Level world, double x, double y, double z, double ax, double ay, double az, IBullet type) + public RevolvershotHomingEntity(Level world, double x, double y, double z, double ax, double ay, double az, IBullet type) { this(IEEntityTypes.HOMING_REVOLVERSHOT.get(), world, x, y, z, ax, ay, az, type); } - public RevolvershotHomingEntity(Level world, LivingEntity living, double ax, double ay, double az, IBullet type) + public RevolvershotHomingEntity(Level world, LivingEntity living, double ax, double ay, double az, IBullet type) { - super(IEEntityTypes.HOMING_REVOLVERSHOT.get(), world, living, ax, ay, az, type); + super(IEEntityTypes.HOMING_REVOLVERSHOT.get(), world, living, ax, ay, az, type, Unit.INSTANCE); } - public RevolvershotHomingEntity(EntityType type, Level world, LivingEntity living, double ax, double ay, double az, IBullet type1) + public RevolvershotHomingEntity(EntityType type, Level world, LivingEntity living, double ax, double ay, double az, IBullet type1) { - super(type, world, living, ax, ay, az, type1); + super(type, world, living, ax, ay, az, type1, Unit.INSTANCE); } @Override @@ -75,10 +76,10 @@ public LivingEntity getTarget() double r = 20D; AABB aabb = new AABB(getX()-r, getY()-r, getZ()-r, getX()+r, getY()+r, getZ()+r); LivingEntity target = null; - for(Object o : level().getEntitiesOfClass(LivingEntity.class, aabb)) - if(o instanceof LivingEntity&&!((LivingEntity)o).getUUID().equals(this.shooterUUID)) - if(target==null||((LivingEntity)o).distanceToSqr(this) < target.distanceToSqr(this)) - target = (LivingEntity)o; + for(LivingEntity o : level().getEntitiesOfClass(LivingEntity.class, aabb)) + if(o!=null&&!o.getUUID().equals(this.shooterUUID)) + if(target==null||o.distanceToSqr(this) < target.distanceToSqr(this)) + target = o; return target; } } \ No newline at end of file diff --git a/src/main/java/blusunrize/immersiveengineering/common/entities/WolfpackShotEntity.java b/src/main/java/blusunrize/immersiveengineering/common/entities/WolfpackShotEntity.java index 7f1585e84c..e54b46cbe4 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/entities/WolfpackShotEntity.java +++ b/src/main/java/blusunrize/immersiveengineering/common/entities/WolfpackShotEntity.java @@ -12,6 +12,7 @@ import blusunrize.immersiveengineering.common.config.IEServerConfig; import blusunrize.immersiveengineering.common.register.IEEntityTypes; import blusunrize.immersiveengineering.common.util.IEDamageSources; +import com.mojang.datafixers.util.Unit; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -28,14 +29,14 @@ public WolfpackShotEntity(EntityType type, Level world) redirectionSpeed = .1875; } - public WolfpackShotEntity(Level world, double x, double y, double z, double ax, double ay, double az, IBullet type) + public WolfpackShotEntity(Level world, double x, double y, double z, double ax, double ay, double az, IBullet type) { super(IEEntityTypes.WOLFPACK_SHOT.get(), world, x, y, z, ax, ay, az, type); trackCountdown = 15; redirectionSpeed = .1875; } - public WolfpackShotEntity(Level world, LivingEntity living, double ax, double ay, double az, IBullet type) + public WolfpackShotEntity(Level world, LivingEntity living, double ax, double ay, double az, IBullet type) { super(IEEntityTypes.WOLFPACK_SHOT.get(), world, living, ax, ay, az, type); trackCountdown = 15; diff --git a/src/main/java/blusunrize/immersiveengineering/common/items/BulletItem.java b/src/main/java/blusunrize/immersiveengineering/common/items/BulletItem.java index 772ecd5116..c2852b4ec1 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/items/BulletItem.java +++ b/src/main/java/blusunrize/immersiveengineering/common/items/BulletItem.java @@ -9,15 +9,21 @@ package blusunrize.immersiveengineering.common.items; import blusunrize.immersiveengineering.api.tool.BulletHandler.IBullet; +import blusunrize.immersiveengineering.common.entities.RevolvershotEntity; import blusunrize.immersiveengineering.common.items.IEItemInterfaces.IColouredItem; import blusunrize.immersiveengineering.common.register.IEDataComponents; import net.minecraft.core.component.DataComponentType; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.Vec3; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.List; public class BulletItem extends IEBaseItem implements IColouredItem @@ -42,6 +48,7 @@ public void appendHoverText(ItemStack stack, TooltipContext ctx, List @Override public Component getName(@Nonnull ItemStack stack) { + // TODO fix String s = "item.immersiveengineering.bullet."; String key = BuiltInRegistries.ITEM.getKey(this).getPath(); s += key; @@ -52,11 +59,29 @@ public Component getName(@Nonnull ItemStack stack) @Override public int getColourForIEItem(ItemStack stack, int pass) { - return type.getColour(stack.get(component), pass); + return type.getColour(stack.get(component), pass).toInt(); } public IBullet getType() { return type; } + + public Entity createBullet( + Level world, + @Nullable Player shooter, + Vec3 startPosition, Vec3 vecDir, + ItemStack bulletStack, boolean electro + ) + { + T data = bulletStack.get(IEDataComponents.getBulletData(type)); + RevolvershotEntity bullet = new RevolvershotEntity( + world, + startPosition.x+vecDir.x, startPosition.y+vecDir.y, startPosition.z+vecDir.z, + vecDir.x, vecDir.y, vecDir.z, + type, data + ); + bullet.bulletElectro = electro; + return type.getProjectile(shooter, data, bullet, false); + } } \ No newline at end of file diff --git a/src/main/java/blusunrize/immersiveengineering/common/items/RevolverItem.java b/src/main/java/blusunrize/immersiveengineering/common/items/RevolverItem.java index 5b3cc3451f..08835407c9 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/items/RevolverItem.java +++ b/src/main/java/blusunrize/immersiveengineering/common/items/RevolverItem.java @@ -20,10 +20,7 @@ import blusunrize.immersiveengineering.api.tool.upgrade.UpgradeEffect; import blusunrize.immersiveengineering.api.utils.ItemUtils; import blusunrize.immersiveengineering.api.utils.codec.IEDualCodecs; -import malte0811.dualcodecs.DualCodec; -import malte0811.dualcodecs.DualCodecs; import blusunrize.immersiveengineering.client.render.tooltip.RevolverServerTooltip; -import blusunrize.immersiveengineering.common.entities.RevolvershotEntity; import blusunrize.immersiveengineering.common.gui.IESlot; import blusunrize.immersiveengineering.common.items.IEItemInterfaces.IBulletContainer; import blusunrize.immersiveengineering.common.items.ItemCapabilityRegistration.ItemCapabilityRegistrar; @@ -37,6 +34,8 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import io.netty.buffer.ByteBuf; +import malte0811.dualcodecs.DualCodec; +import malte0811.dualcodecs.DualCodecs; import malte0811.dualcodecs.DualCompositeCodecs; import net.minecraft.ChatFormatting; import net.minecraft.core.NonNullList; @@ -337,16 +336,12 @@ public static float fireProjectile(Level world, LivingEntity shooter, ItemStack boolean electro = getUpgradesStatic(revolver).has(UpgradeEffect.ELECTRO); int count = bullet.getProjectileCount(player); if(count==1) - { - Entity entBullet = getBullet(shooter, vec, bullet, electro); - shooter.level().addFreshEntity(bullet.getProjectile(player, bulletStack, entBullet, electro)); - } + shooter.level().addFreshEntity(getBullet(shooter, player, vec, bulletStack, electro)); else for(int i = 0; i < count; i++) { Vec3 vecDir = vec.add(shooter.getRandom().nextGaussian()*.1, shooter.getRandom().nextGaussian()*.1, shooter.getRandom().nextGaussian()*.1); - Entity entBullet = getBullet(shooter, vecDir, bullet, electro); - shooter.level().addFreshEntity(bullet.getProjectile(player, bulletStack, entBullet, electro)); + shooter.level().addFreshEntity(getBullet(shooter, player, vecDir, bulletStack, electro)); } var upgrades = getUpgradesStatic(revolver); @@ -379,12 +374,13 @@ public NonNullList getBullets(ItemStack revolver) /* ------------- BULLET UTILITY ------------- */ - private static RevolvershotEntity getBullet(LivingEntity living, Vec3 vecDir, IBullet type, boolean electro) + private static Entity getBullet( + LivingEntity living, @Nullable Player player, Vec3 vecDir, ItemStack bulletStack, boolean electro + ) { - RevolvershotEntity bullet = new RevolvershotEntity(living.level(), living, vecDir.x*1.5, vecDir.y*1.5, vecDir.z*1.5, type); - bullet.setDeltaMovement(vecDir.scale(2)); - bullet.bulletElectro = electro; - return bullet; + return ((BulletItem)bulletStack.getItem()).createBullet( + living.level(), player, living.getEyePosition(), vecDir, bulletStack, electro + ); } public void setBullets(ItemStack revolver, NonNullList bullets, boolean ignoreExtendedMag) diff --git a/src/main/java/blusunrize/immersiveengineering/common/items/bullets/FireworkBullet.java b/src/main/java/blusunrize/immersiveengineering/common/items/bullets/FireworkBullet.java index 7692db8311..4a1d6845be 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/items/bullets/FireworkBullet.java +++ b/src/main/java/blusunrize/immersiveengineering/common/items/bullets/FireworkBullet.java @@ -11,8 +11,8 @@ import blusunrize.immersiveengineering.api.IEApi; import blusunrize.immersiveengineering.api.tool.BulletHandler; import blusunrize.immersiveengineering.api.tool.BulletHandler.CodecsAndDefault; -import malte0811.dualcodecs.DualCodec; import blusunrize.immersiveengineering.common.util.IESounds; +import malte0811.dualcodecs.DualCodec; import net.minecraft.core.component.DataComponents; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -67,7 +67,7 @@ public SoundEvent getSound() } @Override - public void onHitTarget(Level world, HitResult target, UUID shooter, Entity projectile, boolean headshot) + public void onHitTarget(Level world, HitResult target, UUID shooter, Entity projectile, boolean headshot, Fireworks bulletData) { } @@ -91,12 +91,6 @@ public void addTooltip(Fireworks data, TooltipContext world, List lis Items.FIREWORK_ROCKET.appendHoverText(fireworkStack, world, list, flag); } - @Override - public int getColour(Fireworks data, int layer) - { - return 0xffffffff; - } - @Override public boolean isValidForTurret() { diff --git a/src/main/java/blusunrize/immersiveengineering/common/items/bullets/FlareBullet.java b/src/main/java/blusunrize/immersiveengineering/common/items/bullets/FlareBullet.java index 3bf7527ab5..8ccb29cbd9 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/items/bullets/FlareBullet.java +++ b/src/main/java/blusunrize/immersiveengineering/common/items/bullets/FlareBullet.java @@ -12,12 +12,10 @@ import blusunrize.immersiveengineering.api.Lib; import blusunrize.immersiveengineering.api.tool.BulletHandler; import blusunrize.immersiveengineering.api.tool.BulletHandler.CodecsAndDefault; -import malte0811.dualcodecs.DualCodecs; +import blusunrize.immersiveengineering.api.utils.Color4; import blusunrize.immersiveengineering.client.utils.FontUtils; import blusunrize.immersiveengineering.common.entities.RevolvershotFlareEntity; -import com.mojang.serialization.Codec; import net.minecraft.network.chat.Component; -import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; @@ -30,38 +28,36 @@ import java.util.List; import java.util.UUID; -public class FlareBullet implements BulletHandler.IBullet +public class FlareBullet implements BulletHandler.IBullet { static ResourceLocation[] textures = {IEApi.ieLoc("item/bullet_flare"), IEApi.ieLoc("item/bullet_flare_layer")}; - private static final CodecsAndDefault CODEC = new CodecsAndDefault<>(DualCodecs.INT, 0xcc2e06); + private static final CodecsAndDefault CODEC = new CodecsAndDefault<>(Color4.CODECS, Color4.fromRGB(0xcc2e06)); public FlareBullet() { } @Override - public CodecsAndDefault getCodec() + public CodecsAndDefault getCodec() { return CODEC; } @Override - public Entity getProjectile(Player shooter, Integer color, Entity projectile, boolean electro) + public Entity getProjectile(Player shooter, Color4 color, Entity projectile, boolean electro) { RevolvershotFlareEntity flare = shooter!=null?new RevolvershotFlareEntity(projectile.level(), shooter, projectile.getDeltaMovement().x*1.5, projectile.getDeltaMovement().y*1.5, - projectile.getDeltaMovement().z*1.5, this): - new RevolvershotFlareEntity(projectile.level(), projectile.getX(), projectile.getY(), projectile.getZ(), 0, 0, 0, this); + projectile.getDeltaMovement().z*1.5, color): + new RevolvershotFlareEntity(projectile.level(), projectile.getX(), projectile.getY(), projectile.getZ(), 0, 0, 0, color); flare.setDeltaMovement(projectile.getDeltaMovement()); flare.bulletElectro = electro; - flare.colour = color; - flare.setColourSynced(); return flare; } @Override - public void onHitTarget(Level world, HitResult target, UUID shooter, Entity projectile, boolean headshot) + public void onHitTarget(Level world, HitResult target, UUID shooter, Entity projectile, boolean headshot, Color4 bulletData) { } @@ -78,16 +74,16 @@ public ResourceLocation[] getTextures() } @Override - public void addTooltip(Integer color, TooltipContext world, List list, TooltipFlag flag) + public void addTooltip(Color4 color, TooltipContext world, List list, TooltipFlag flag) { - list.add(FontUtils.withAppendColoredColour(Component.translatable(Lib.DESC_INFO+"bullet.flareColour"), color)); + list.add(FontUtils.withAppendColoredColour(Component.translatable(Lib.DESC_INFO+"bullet.flareColour"), color.toInt())); } @Override - public int getColour(Integer color, int layer) + public Color4 getColour(Color4 color, int layer) { if(layer!=1) - return 0xffffffff; + return Color4.WHITE; return color; } diff --git a/src/main/java/blusunrize/immersiveengineering/common/items/bullets/IEBullets.java b/src/main/java/blusunrize/immersiveengineering/common/items/bullets/IEBullets.java index 787c2d68b6..8368fcac16 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/items/bullets/IEBullets.java +++ b/src/main/java/blusunrize/immersiveengineering/common/items/bullets/IEBullets.java @@ -11,7 +11,9 @@ import blusunrize.immersiveengineering.api.IEApi; import blusunrize.immersiveengineering.api.tool.BulletHandler; import blusunrize.immersiveengineering.api.tool.BulletHandler.CodecsAndDefault; +import blusunrize.immersiveengineering.api.tool.BulletHandler.IBullet; import blusunrize.immersiveengineering.api.tool.ShieldDisablingHandler; +import blusunrize.immersiveengineering.api.utils.Color4; import blusunrize.immersiveengineering.common.config.IEServerConfig; import blusunrize.immersiveengineering.common.entities.RevolvershotEntity; import blusunrize.immersiveengineering.common.util.IEDamageSources; @@ -46,6 +48,8 @@ public class IEBullets public static final ResourceLocation WOLFPACK = IEApi.ieLoc("wolfpack"); public static final ResourceLocation WOLFPACK_PART = IEApi.ieLoc("wolfpack_part"); + public static final IBullet FLARE_TYPE = new FlareBullet(); + public static void initBullets() { BulletHandler.registerBullet(CASULL, new BulletHandler.DamagingBullet<>( @@ -78,9 +82,9 @@ public int getProjectileCount(Player shooter) } @Override - public void onHitTarget(Level world, HitResult rtr, @Nullable UUID shooterUUID, Entity projectile, boolean headshot) + public void onHitTarget(Level world, HitResult rtr, @Nullable UUID shooterUUID, Entity projectile, boolean headshot, Unit bulletData) { - super.onHitTarget(world, rtr, shooterUUID, projectile, headshot); + super.onHitTarget(world, rtr, shooterUUID, projectile, headshot, bulletData); if(rtr instanceof EntityHitResult target&&target.getEntity() instanceof LivingEntity livingTarget) if(livingTarget.isBlocking()&&livingTarget.getRandom().nextFloat() < .15f) ShieldDisablingHandler.attemptDisabling(livingTarget); @@ -92,7 +96,7 @@ public void onHitTarget(Level world, HitResult rtr, @Nullable UUID shooterUUID, ) { @Override - public void onHitTarget(Level world, HitResult target, UUID shooterId, Entity projectile, boolean headshot) + public void onHitTarget(Level world, HitResult target, UUID shooterId, Entity projectile, boolean headshot, Unit bulletData) { Entity shooter = null; if(shooterId!=null&&world instanceof ServerLevel serverLevel) @@ -161,7 +165,7 @@ public Entity getProjectile(Player shooter, Unit ignored, Entity projectile, boo BulletHandler.registerBullet(POTION, new PotionBullet()); - BulletHandler.registerBullet(FLARE, new FlareBullet()); + BulletHandler.registerBullet(FLARE, FLARE_TYPE); BulletHandler.registerBullet(FIREWORK, new FireworkBullet()); diff --git a/src/main/java/blusunrize/immersiveengineering/common/items/bullets/PotionBullet.java b/src/main/java/blusunrize/immersiveengineering/common/items/bullets/PotionBullet.java index b9eec2a398..7e0bc78525 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/items/bullets/PotionBullet.java +++ b/src/main/java/blusunrize/immersiveengineering/common/items/bullets/PotionBullet.java @@ -12,14 +12,15 @@ import blusunrize.immersiveengineering.api.tool.BulletHandler; import blusunrize.immersiveengineering.api.tool.BulletHandler.CodecsAndDefault; import blusunrize.immersiveengineering.api.tool.BulletHandler.DamagingBullet; +import blusunrize.immersiveengineering.api.utils.Color4; import blusunrize.immersiveengineering.api.utils.codec.IEDualCodecs; -import malte0811.dualcodecs.DualCodec; -import malte0811.dualcodecs.DualCodecs; import blusunrize.immersiveengineering.common.config.IEServerConfig; import blusunrize.immersiveengineering.common.entities.RevolvershotEntity; import blusunrize.immersiveengineering.common.items.bullets.PotionBullet.Data; import blusunrize.immersiveengineering.common.util.IEDamageSources; import io.netty.buffer.ByteBuf; +import malte0811.dualcodecs.DualCodec; +import malte0811.dualcodecs.DualCodecs; import malte0811.dualcodecs.DualCompositeCodecs; import net.minecraft.core.component.DataComponents; import net.minecraft.network.RegistryFriendlyByteBuf; @@ -29,9 +30,10 @@ import net.minecraft.world.entity.AreaEffectCloud; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item.TooltipContext; -import net.minecraft.world.item.*; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.alchemy.PotionContents; import net.minecraft.world.level.Level; import net.minecraft.world.phys.EntityHitResult; @@ -67,22 +69,13 @@ else if(potion.type==PotionType.SPLASH) } @Override - public Entity getProjectile(Player shooter, Data potion, Entity projectile, boolean electro) - { - // TODO replace by automatic attachment of bullet data - ((RevolvershotEntity)projectile).bulletPotion = potion.makePotion(); - return projectile; - } - - @Override - public void onHitTarget(Level world, HitResult target, UUID shooterUUID, Entity projectile, boolean headshot) + public void onHitTarget(Level world, HitResult target, UUID shooterUUID, Entity projectile, boolean headshot, Data bulletData) { - super.onHitTarget(world, target, shooterUUID, projectile, headshot); + super.onHitTarget(world, target, shooterUUID, projectile, headshot, bulletData); RevolvershotEntity bullet = (RevolvershotEntity)projectile; - PotionContents potionType = bullet.bulletPotion.get(DataComponents.POTION_CONTENTS); - if(potionType!=null&&potionType.hasEffects()) + if(bulletData.contents!=null&&bulletData.contents.hasEffects()) { - var effects = potionType.getAllEffects(); + var effects = bulletData.contents.getAllEffects(); LivingEntity shooter = null; if(shooterUUID!=null&&world instanceof ServerLevel serverLevel) { @@ -90,54 +83,53 @@ public void onHitTarget(Level world, HitResult target, UUID shooterUUID, Entity if(e instanceof LivingEntity) shooter = (LivingEntity)e; } - if(effects!=null) - if(bullet.bulletPotion.getItem() instanceof LingeringPotionItem) - { - AreaEffectCloud entityareaeffectcloud = new AreaEffectCloud(bullet.level(), bullet.getX(), bullet.getY(), bullet.getZ()); - entityareaeffectcloud.setOwner(shooter); - entityareaeffectcloud.setRadius(3.0F); - entityareaeffectcloud.setRadiusOnUse(-0.5F); - entityareaeffectcloud.setWaitTime(10); - entityareaeffectcloud.setRadiusPerTick(-entityareaeffectcloud.getRadius()/(float)entityareaeffectcloud.getDuration()); - entityareaeffectcloud.setPotionContents(potionType); - for(MobEffectInstance potioneffect : effects) - entityareaeffectcloud.addEffect(new MobEffectInstance(potioneffect.getEffect(), potioneffect.getDuration(), potioneffect.getAmplifier())); - bullet.level().addFreshEntity(entityareaeffectcloud); - } - else if(bullet.bulletPotion.getItem() instanceof SplashPotionItem) - { - List livingEntities = bullet.level().getEntitiesOfClass(LivingEntity.class, bullet.getBoundingBox().inflate(4.0D, 2.0D, 4.0D)); - if(livingEntities!=null&&!livingEntities.isEmpty()) - for(LivingEntity living : livingEntities) - if(living.isAffectedByPotions()) + if(bulletData.type==PotionType.LINGERING) + { + AreaEffectCloud entityareaeffectcloud = new AreaEffectCloud(bullet.level(), bullet.getX(), bullet.getY(), bullet.getZ()); + entityareaeffectcloud.setOwner(shooter); + entityareaeffectcloud.setRadius(3.0F); + entityareaeffectcloud.setRadiusOnUse(-0.5F); + entityareaeffectcloud.setWaitTime(10); + entityareaeffectcloud.setRadiusPerTick(-entityareaeffectcloud.getRadius()/(float)entityareaeffectcloud.getDuration()); + entityareaeffectcloud.setPotionContents(bulletData.contents); + for(MobEffectInstance potioneffect : effects) + entityareaeffectcloud.addEffect(new MobEffectInstance(potioneffect.getEffect(), potioneffect.getDuration(), potioneffect.getAmplifier())); + bullet.level().addFreshEntity(entityareaeffectcloud); + } + else if(bulletData.type==PotionType.SPLASH) + { + List livingEntities = bullet.level().getEntitiesOfClass(LivingEntity.class, bullet.getBoundingBox().inflate(4.0D, 2.0D, 4.0D)); + if(livingEntities!=null&&!livingEntities.isEmpty()) + for(LivingEntity living : livingEntities) + if(living.isAffectedByPotions()) + { + double dist = bullet.distanceToSqr(living); + if(dist < 16D) { - double dist = bullet.distanceToSqr(living); - if(dist < 16D) - { - double dist2 = 1-Math.sqrt(dist)/4D; - if(target instanceof EntityHitResult&&living==((EntityHitResult)target).getEntity()) - dist2 = 1D; - for(MobEffectInstance p : effects) - if(p.getEffect().value().isInstantenous()) - p.getEffect().value().applyInstantenousEffect(bullet, shooter, living, p.getAmplifier(), dist2); - else - { - int j = (int)(dist2*p.getDuration()+.5D); - if(j > 20) - living.addEffect(new MobEffectInstance(p.getEffect(), j, p.getAmplifier())); - } - } + double dist2 = 1-Math.sqrt(dist)/4D; + if(target instanceof EntityHitResult&&living==((EntityHitResult)target).getEntity()) + dist2 = 1D; + for(MobEffectInstance p : effects) + if(p.getEffect().value().isInstantenous()) + p.getEffect().value().applyInstantenousEffect(bullet, shooter, living, p.getAmplifier(), dist2); + else + { + int j = (int)(dist2*p.getDuration()+.5D); + if(j > 20) + living.addEffect(new MobEffectInstance(p.getEffect(), j, p.getAmplifier())); + } } + } + } + else if(target instanceof EntityHitResult&&((EntityHitResult)target).getEntity() instanceof LivingEntity) + for(MobEffectInstance p : effects) + { + if(p.getDuration() < 1) + p = new MobEffectInstance(p.getEffect(), 1); + ((LivingEntity)((EntityHitResult)target).getEntity()).addEffect(p); } - else if(target instanceof EntityHitResult&&((EntityHitResult)target).getEntity() instanceof LivingEntity) - for(MobEffectInstance p : effects) - { - if(p.getDuration() < 1) - p = new MobEffectInstance(p.getEffect(), 1); - ((LivingEntity)((EntityHitResult)target).getEntity()).addEffect(p); - } - world.levelEvent(2002, bullet.blockPosition(), potionType.getColor()); + world.levelEvent(2002, bullet.blockPosition(), bulletData.contents.getColor()); } } @@ -150,11 +142,11 @@ public void addTooltip(Data data, TooltipContext world, List list, To } @Override - public int getColour(Data data, int layer) + public Color4 getColour(Data data, int layer) { if(layer==1) - return data.contents.getColor(); - return 0xffffffff; + return Color4.fromRGB(data.contents.getColor()); + return Color4.WHITE; } public record Data(PotionContents contents, PotionType type) diff --git a/src/main/java/blusunrize/immersiveengineering/common/items/bullets/WolfpackBullet.java b/src/main/java/blusunrize/immersiveengineering/common/items/bullets/WolfpackBullet.java index eae30d5536..5d38ce37c3 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/items/bullets/WolfpackBullet.java +++ b/src/main/java/blusunrize/immersiveengineering/common/items/bullets/WolfpackBullet.java @@ -41,9 +41,9 @@ public WolfpackBullet() } @Override - public void onHitTarget(Level world, HitResult target, UUID shooterUUID, Entity projectile, boolean headshot) + public void onHitTarget(Level world, HitResult target, UUID shooterUUID, Entity projectile, boolean headshot, Unit bulletData) { - super.onHitTarget(world, target, shooterUUID, projectile, headshot); + super.onHitTarget(world, target, shooterUUID, projectile, headshot, bulletData); Vec3 v = projectile.getDeltaMovement().scale(-1); int split = 6; for(int i = 0; i < split; i++) diff --git a/src/main/java/blusunrize/immersiveengineering/common/register/IEEntityDataSerializers.java b/src/main/java/blusunrize/immersiveengineering/common/register/IEEntityDataSerializers.java index cc106ffb4b..78647cd23d 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/register/IEEntityDataSerializers.java +++ b/src/main/java/blusunrize/immersiveengineering/common/register/IEEntityDataSerializers.java @@ -9,11 +9,12 @@ package blusunrize.immersiveengineering.common.register; import blusunrize.immersiveengineering.api.Lib; +import blusunrize.immersiveengineering.common.entities.RevolvershotEntity; +import blusunrize.immersiveengineering.common.entities.RevolvershotEntity.BulletData; import blusunrize.immersiveengineering.common.fluids.IEFluid; import net.minecraft.network.syncher.EntityDataSerializer; import net.neoforged.neoforge.fluids.FluidStack; import net.neoforged.neoforge.registries.DeferredRegister; -import net.minecraft.core.Holder; import net.neoforged.neoforge.registries.NeoForgeRegistries; import java.util.function.Supplier; @@ -27,4 +28,7 @@ public class IEEntityDataSerializers public static final Supplier> FLUID_STACK = REGISTER.register( "fluid_stack", IEFluid.EntityFluidSerializer::new ); + public static final Supplier>> BULLET = REGISTER.register( + "bullet", () -> EntityDataSerializer.forValueType(BulletData.CODECS.streamCodec()) + ); }