试图修改子弹rgb
This commit is contained in:
parent
eba3b630b6
commit
78ec337a85
6 changed files with 67 additions and 36 deletions
|
@ -60,7 +60,9 @@ import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnData, GeoEntity, AnimatedEntity {
|
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);
|
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(ProjectileEntity.class, EntityDataSerializers.STRING);
|
||||||
|
|
||||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
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 bypassArmorRate = 0.0f;
|
||||||
private float undeadMultiple = 1.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_) {
|
public ProjectileEntity(EntityType<? extends ProjectileEntity> p_i50159_1_, Level p_i50159_2_) {
|
||||||
super(p_i50159_1_, p_i50159_2_);
|
super(p_i50159_1_, p_i50159_2_);
|
||||||
|
@ -218,7 +220,9 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void defineSynchedData() {
|
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
|
@Override
|
||||||
|
@ -280,13 +284,17 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@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() {
|
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);
|
this.level().playSound(null, result.getLocation().x, result.getLocation().y, result.getLocation().z, event, SoundSource.AMBIENT, 1.0F, 1.0F);
|
||||||
Vec3 hitVec = result.getLocation();
|
Vec3 hitVec = result.getLocation();
|
||||||
|
|
||||||
if(state.getBlock() instanceof BellBlock bell) {
|
if (state.getBlock() instanceof BellBlock bell) {
|
||||||
bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection());
|
bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -682,8 +690,9 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectileEntity rgb(float[] rgb) {
|
public void setRGB(float[] rgb) {
|
||||||
this.rgb = rgb;
|
this.colorR = rgb[0];
|
||||||
return this;
|
this.colorG = rgb[1];
|
||||||
|
this.colorB = rgb[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,6 @@ public class ProjectileEntityInsideLayer extends GeoRenderLayer<ProjectileEntity
|
||||||
RenderType glowRenderType = RenderType.eyes(LAYER);
|
RenderType glowRenderType = RenderType.eyes(LAYER);
|
||||||
getRenderer().reRender(getDefaultBakedModel(animatable), poseStack, bufferSource, animatable, glowRenderType, bufferSource.getBuffer(glowRenderType),
|
getRenderer().reRender(getDefaultBakedModel(animatable), poseStack, bufferSource, animatable, glowRenderType, bufferSource.getBuffer(glowRenderType),
|
||||||
partialTick, packedLight, OverlayTexture.NO_OVERLAY,
|
partialTick, packedLight, OverlayTexture.NO_OVERLAY,
|
||||||
animatable.rgb[0], animatable.rgb[1], animatable.rgb[2], 0.5f);
|
1, 1, 1, 0.5f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,15 @@ public class ProjectileEntityLayer extends GeoRenderLayer<ProjectileEntity> {
|
||||||
super(entityRenderer);
|
super(entityRenderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 实现更合理的layer渲染
|
// TODO 解决RGB颜色问题
|
||||||
@Override
|
@Override
|
||||||
public void render(PoseStack poseStack, ProjectileEntity animatable, BakedGeoModel bakedModel, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, float partialTick, int packedLight, int packedOverlay) {
|
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);
|
RenderType glowRenderType = RenderType.eyes(LAYER);
|
||||||
getRenderer().reRender(getDefaultBakedModel(animatable), poseStack, bufferSource, animatable, glowRenderType, bufferSource.getBuffer(glowRenderType),
|
getRenderer().reRender(getDefaultBakedModel(animatable), poseStack, bufferSource, animatable, glowRenderType,
|
||||||
partialTick, packedLight, OverlayTexture.NO_OVERLAY,
|
bufferSource.getBuffer(glowRenderType), partialTick, packedLight, OverlayTexture.NO_OVERLAY,
|
||||||
animatable.rgb[0], animatable.rgb[1], animatable.rgb[2], 0.8f);
|
animatable.getEntityData().get(ProjectileEntity.COLOR_R),
|
||||||
|
animatable.getEntityData().get(ProjectileEntity.COLOR_G),
|
||||||
|
animatable.getEntityData().get(ProjectileEntity.COLOR_B),
|
||||||
|
0.8f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,13 +345,6 @@ public class GunEventHandler {
|
||||||
float headshot = (float) heldItem.getOrCreateTag().getDouble("headshot");
|
float headshot = (float) heldItem.getOrCreateTag().getDouble("headshot");
|
||||||
int monsterMultiple = EnchantmentHelper.getTagEnchantmentLevel(ModEnchantments.MONSTER_HUNTER.get(), heldItem);
|
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 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;
|
boolean zoom = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).zooming;
|
||||||
double spread = heldItem.getOrCreateTag().getDouble("spread");
|
double spread = heldItem.getOrCreateTag().getDouble("spread");
|
||||||
|
@ -362,9 +355,18 @@ public class GunEventHandler {
|
||||||
.damage(damage)
|
.damage(damage)
|
||||||
.headShot(headshot)
|
.headShot(headshot)
|
||||||
.zoom(zoom)
|
.zoom(zoom)
|
||||||
.bypassArmorRate(bypassArmorRate)
|
|
||||||
.monsterMultiple(monsterMultiple);
|
.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")) {
|
if (heldItem.getOrCreateTag().getBoolean("beast")) {
|
||||||
projectile.beast();
|
projectile.beast();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 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> 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));
|
public static final RegistryObject<Perk> HEAL_CLIP = PERKS.register("heal_clip", () -> new Perk("heal_clip", Perk.Type.FUNCTIONAL));
|
||||||
|
|
|
@ -3,20 +3,36 @@ package net.mcreator.superbwarfare.perk;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
|
|
||||||
public class AmmoPerk extends Perk {
|
public class AmmoPerk extends Perk {
|
||||||
public float bypassArmorRate = 0.0f;
|
public float bypassArmorRate;
|
||||||
public float[] rgb = {1, 222 / 255f, 39 / 255f};
|
public float[] rgb;
|
||||||
|
|
||||||
public AmmoPerk(String descriptionId, Type type) {
|
public AmmoPerk(AmmoPerk.Builder builder) {
|
||||||
super(descriptionId, type);
|
super(builder.descriptionId, builder.type);
|
||||||
|
this.bypassArmorRate = builder.bypassArmorRate;
|
||||||
|
this.rgb = builder.rgb;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AmmoPerk(String descriptionId, Type type, float bypassArmorRate) {
|
public static class Builder {
|
||||||
super(descriptionId, type);
|
String descriptionId;
|
||||||
this.bypassArmorRate = Mth.clamp(bypassArmorRate, -1, 1);
|
Type type;
|
||||||
}
|
float bypassArmorRate = 0.0f;
|
||||||
|
float[] rgb = {1, 222 / 255f, 39 / 255f};
|
||||||
|
|
||||||
public AmmoPerk rgb(float[] rgb) {
|
public Builder(String descriptionId, Type type) {
|
||||||
this.rgb = rgb;
|
this.descriptionId = descriptionId;
|
||||||
return this;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue