试图修改子弹rgb

This commit is contained in:
17146 2024-08-08 16:38:24 +08:00
parent eba3b630b6
commit 78ec337a85
6 changed files with 67 additions and 36 deletions

View file

@ -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<Float> COLOR_R = SynchedEntityData.defineId(ProjectileEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> COLOR_G = SynchedEntityData.defineId(ProjectileEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> COLOR_B = SynchedEntityData.defineId(ProjectileEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<String> 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<? extends ProjectileEntity> 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];
}
}

View file

@ -24,6 +24,6 @@ public class ProjectileEntityInsideLayer extends GeoRenderLayer<ProjectileEntity
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.5f);
1, 1, 1, 0.5f);
}
}

View file

@ -19,12 +19,15 @@ public class ProjectileEntityLayer extends GeoRenderLayer<ProjectileEntity> {
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);
}
}

View file

@ -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();
}

View file

@ -21,7 +21,8 @@ public class ModPerks {
public static final DeferredRegister<Perk> PERKS = DeferredRegister.create(new ResourceLocation(ModUtils.MODID, "perk"), ModUtils.MODID);
public static final RegistryObject<AmmoPerk> SILVER_BULLET = PERKS.register("silver_bullet", () -> new AmmoPerk("silver_bullet", Perk.Type.AMMO, 0.1f));
public static final RegistryObject<AmmoPerk> 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<Perk> FOURTH_TIMES_CHARM = PERKS.register("fourth_times_charm", () -> new Perk("fourth_times_charm", Perk.Type.FUNCTIONAL));
public static final RegistryObject<Perk> HEAL_CLIP = PERKS.register("heal_clip", () -> new Perk("heal_clip", Perk.Type.FUNCTIONAL));

View file

@ -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);
public static class Builder {
String descriptionId;
Type type;
float bypassArmorRate = 0.0f;
float[] rgb = {1, 222 / 255f, 39 / 255f};
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);
}
public AmmoPerk rgb(float[] rgb) {
this.rgb = rgb;
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;
}
}
}