diff --git a/src/main/java/net/mcreator/superbwarfare/entity/ProjectileEntity.java b/src/main/java/net/mcreator/superbwarfare/entity/ProjectileEntity.java index 8dee89a10..2004fbd21 100644 --- a/src/main/java/net/mcreator/superbwarfare/entity/ProjectileEntity.java +++ b/src/main/java/net/mcreator/superbwarfare/entity/ProjectileEntity.java @@ -60,7 +60,9 @@ import java.util.function.Function; import java.util.function.Predicate; public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnData, GeoEntity, AnimatedEntity { - + public static final EntityDataAccessor COLOR_R = SynchedEntityData.defineId(ProjectileEntity.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor COLOR_G = SynchedEntityData.defineId(ProjectileEntity.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor COLOR_B = SynchedEntityData.defineId(ProjectileEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor ANIMATION = SynchedEntityData.defineId(ProjectileEntity.class, EntityDataSerializers.STRING); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -85,7 +87,7 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa private float bypassArmorRate = 0.0f; private float undeadMultiple = 1.0f; - public float[] rgb = {1, 222 / 255f, 39 / 255f}; + public float colorR = 1, colorG = 222 / 255f, colorB = 39 / 255f; public ProjectileEntity(EntityType p_i50159_1_, Level p_i50159_2_) { super(p_i50159_1_, p_i50159_2_); @@ -218,7 +220,9 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa @Override protected void defineSynchedData() { - + this.entityData.define(COLOR_R, this.colorR); + this.entityData.define(COLOR_G, this.colorG); + this.entityData.define(COLOR_B, this.colorB); } @Override @@ -280,13 +284,17 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa } @Override - protected void readAdditionalSaveData(CompoundTag p_20052_) { - + protected void readAdditionalSaveData(CompoundTag compoundTag) { + this.colorR = compoundTag.getFloat("ColorR"); + this.colorG = compoundTag.getFloat("ColorG"); + this.colorB = compoundTag.getFloat("ColorB"); } @Override - protected void addAdditionalSaveData(CompoundTag p_20139_) { - + protected void addAdditionalSaveData(CompoundTag compoundTag) { + compoundTag.putFloat("ColorR", this.colorR); + compoundTag.putFloat("ColorG", this.colorG); + compoundTag.putFloat("ColorB", this.colorB); } protected void onProjectileTick() { @@ -303,7 +311,7 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa this.level().playSound(null, result.getLocation().x, result.getLocation().y, result.getLocation().z, event, SoundSource.AMBIENT, 1.0F, 1.0F); Vec3 hitVec = result.getLocation(); - if(state.getBlock() instanceof BellBlock bell) { + if (state.getBlock() instanceof BellBlock bell) { bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection()); } @@ -682,8 +690,9 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa return this; } - public ProjectileEntity rgb(float[] rgb) { - this.rgb = rgb; - return this; + public void setRGB(float[] rgb) { + this.colorR = rgb[0]; + this.colorG = rgb[1]; + this.colorB = rgb[2]; } } diff --git a/src/main/java/net/mcreator/superbwarfare/entity/layer/ProjectileEntityInsideLayer.java b/src/main/java/net/mcreator/superbwarfare/entity/layer/ProjectileEntityInsideLayer.java index 5284cdb2b..a14db90ca 100644 --- a/src/main/java/net/mcreator/superbwarfare/entity/layer/ProjectileEntityInsideLayer.java +++ b/src/main/java/net/mcreator/superbwarfare/entity/layer/ProjectileEntityInsideLayer.java @@ -24,6 +24,6 @@ public class ProjectileEntityInsideLayer extends GeoRenderLayer { super(entityRenderer); } - // TODO 实现更合理的layer渲染 + // TODO 解决RGB颜色问题 @Override public void render(PoseStack poseStack, ProjectileEntity animatable, BakedGeoModel bakedModel, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, float partialTick, int packedLight, int packedOverlay) { RenderType glowRenderType = RenderType.eyes(LAYER); - getRenderer().reRender(getDefaultBakedModel(animatable), poseStack, bufferSource, animatable, glowRenderType, bufferSource.getBuffer(glowRenderType), - partialTick, packedLight, OverlayTexture.NO_OVERLAY, - animatable.rgb[0], animatable.rgb[1], animatable.rgb[2], 0.8f); + getRenderer().reRender(getDefaultBakedModel(animatable), poseStack, bufferSource, animatable, glowRenderType, + bufferSource.getBuffer(glowRenderType), partialTick, packedLight, OverlayTexture.NO_OVERLAY, + animatable.getEntityData().get(ProjectileEntity.COLOR_R), + animatable.getEntityData().get(ProjectileEntity.COLOR_G), + animatable.getEntityData().get(ProjectileEntity.COLOR_B), + 0.8f); } } diff --git a/src/main/java/net/mcreator/superbwarfare/event/GunEventHandler.java b/src/main/java/net/mcreator/superbwarfare/event/GunEventHandler.java index 5d4f800bb..f9a347569 100644 --- a/src/main/java/net/mcreator/superbwarfare/event/GunEventHandler.java +++ b/src/main/java/net/mcreator/superbwarfare/event/GunEventHandler.java @@ -345,13 +345,6 @@ public class GunEventHandler { float headshot = (float) heldItem.getOrCreateTag().getDouble("headshot"); int monsterMultiple = EnchantmentHelper.getTagEnchantmentLevel(ModEnchantments.MONSTER_HUNTER.get(), heldItem); float damage = (float) (heldItem.getOrCreateTag().getDouble("damage") + heldItem.getOrCreateTag().getDouble("sentinelChargeDamage")) * (float) heldItem.getOrCreateTag().getDouble("levelDamageMultiple"); - float bypassArmorRate = (float) heldItem.getOrCreateTag().getDouble("BypassesArmor"); - - var perk = PerkHelper.getPerkByType(heldItem, Perk.Type.AMMO); - if (perk instanceof AmmoPerk ammoPerk) { - bypassArmorRate += ammoPerk.bypassArmorRate; - } - bypassArmorRate = Mth.clamp(bypassArmorRate, 0, 1); boolean zoom = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).zooming; double spread = heldItem.getOrCreateTag().getDouble("spread"); @@ -362,9 +355,18 @@ public class GunEventHandler { .damage(damage) .headShot(headshot) .zoom(zoom) - .bypassArmorRate(bypassArmorRate) .monsterMultiple(monsterMultiple); + float bypassArmorRate = (float) heldItem.getOrCreateTag().getDouble("BypassesArmor"); + var perk = PerkHelper.getPerkByType(heldItem, Perk.Type.AMMO); + if (perk instanceof AmmoPerk ammoPerk) { + bypassArmorRate += ammoPerk.bypassArmorRate; + projectile.setRGB(ammoPerk.rgb); + } + bypassArmorRate = Mth.clamp(bypassArmorRate, 0, 1); + + projectile.bypassArmorRate(bypassArmorRate); + if (heldItem.getOrCreateTag().getBoolean("beast")) { projectile.beast(); } diff --git a/src/main/java/net/mcreator/superbwarfare/init/ModPerks.java b/src/main/java/net/mcreator/superbwarfare/init/ModPerks.java index e8706d262..18657dcd1 100644 --- a/src/main/java/net/mcreator/superbwarfare/init/ModPerks.java +++ b/src/main/java/net/mcreator/superbwarfare/init/ModPerks.java @@ -21,7 +21,8 @@ public class ModPerks { public static final DeferredRegister PERKS = DeferredRegister.create(new ResourceLocation(ModUtils.MODID, "perk"), ModUtils.MODID); - public static final RegistryObject SILVER_BULLET = PERKS.register("silver_bullet", () -> new AmmoPerk("silver_bullet", Perk.Type.AMMO, 0.1f)); + public static final RegistryObject SILVER_BULLET = PERKS.register("silver_bullet", + () -> new AmmoPerk(new AmmoPerk.Builder("silver_bullet", Perk.Type.AMMO).bypassArmorRate(0.1f).rgb(231, 251, 255))); public static final RegistryObject FOURTH_TIMES_CHARM = PERKS.register("fourth_times_charm", () -> new Perk("fourth_times_charm", Perk.Type.FUNCTIONAL)); public static final RegistryObject HEAL_CLIP = PERKS.register("heal_clip", () -> new Perk("heal_clip", Perk.Type.FUNCTIONAL)); diff --git a/src/main/java/net/mcreator/superbwarfare/perk/AmmoPerk.java b/src/main/java/net/mcreator/superbwarfare/perk/AmmoPerk.java index a6d3fb3a3..dbaabba4b 100644 --- a/src/main/java/net/mcreator/superbwarfare/perk/AmmoPerk.java +++ b/src/main/java/net/mcreator/superbwarfare/perk/AmmoPerk.java @@ -3,20 +3,36 @@ package net.mcreator.superbwarfare.perk; import net.minecraft.util.Mth; public class AmmoPerk extends Perk { - public float bypassArmorRate = 0.0f; - public float[] rgb = {1, 222 / 255f, 39 / 255f}; + public float bypassArmorRate; + public float[] rgb; - public AmmoPerk(String descriptionId, Type type) { - super(descriptionId, type); + public AmmoPerk(AmmoPerk.Builder builder) { + super(builder.descriptionId, builder.type); + this.bypassArmorRate = builder.bypassArmorRate; + this.rgb = builder.rgb; } - public AmmoPerk(String descriptionId, Type type, float bypassArmorRate) { - super(descriptionId, type); - this.bypassArmorRate = Mth.clamp(bypassArmorRate, -1, 1); - } + public static class Builder { + String descriptionId; + Type type; + float bypassArmorRate = 0.0f; + float[] rgb = {1, 222 / 255f, 39 / 255f}; - public AmmoPerk rgb(float[] rgb) { - this.rgb = rgb; - return this; + public Builder(String descriptionId, Type type) { + this.descriptionId = descriptionId; + this.type = type; + } + + public AmmoPerk.Builder bypassArmorRate(float bypassArmorRate) { + this.bypassArmorRate = Mth.clamp(bypassArmorRate, -1, 1); + return this; + } + + public AmmoPerk.Builder rgb(int r, int g, int b) { + this.rgb[0] = r / 255f; + this.rgb[1] = g / 255f; + this.rgb[2] = b / 255f; + return this; + } } }