修复渲染问题

This commit is contained in:
17146 2024-12-03 21:57:03 +08:00
parent e79fcf88ee
commit 7f2fc4c9aa
10 changed files with 41 additions and 19 deletions

View file

@ -16,6 +16,7 @@ import software.bernie.geckolib.cache.object.BakedGeoModel;
import software.bernie.geckolib.renderer.GeoEntityRenderer;
public class Mle1934Renderer extends GeoEntityRenderer<Mle1934Entity> {
public Mle1934Renderer(EntityRendererProvider.Context renderManager) {
super(renderManager, new Mle1934Model());
this.shadowRadius = 2f;

View file

@ -31,8 +31,10 @@ import java.text.DecimalFormat;
@Mod.EventBusSubscriber(value = Dist.CLIENT)
public class CannonHudOverlay {
public static float health = 0;
public static float maxHealth = 0;
private static final ResourceLocation ARMOR = ModUtils.loc("textures/screens/armor.png");
private static final ResourceLocation HEALTH = ModUtils.loc("textures/screens/armor_value.png");
private static final ResourceLocation HEALTH_FRAME = ModUtils.loc("textures/screens/armor_value_frame.png");

View file

@ -59,6 +59,7 @@ import java.util.Objects;
import java.util.UUID;
public class DroneEntity extends LivingEntity implements GeoEntity {
public static final EntityDataAccessor<Boolean> LINKED = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<String> CONTROLLER = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.STRING);
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.INT);
@ -74,7 +75,6 @@ public class DroneEntity extends LivingEntity implements GeoEntity {
private boolean move = false;
public static double lastTickSpeed = 0;
public DroneEntity(PlayMessages.SpawnEntity packet, Level world) {
this(ModEntities.DRONE.get(), world);
}
@ -174,7 +174,6 @@ public class DroneEntity extends LivingEntity implements GeoEntity {
this.entityData.set(ROT_Z, compound.getFloat("rotZ"));
}
public Vector3f getForwardDirection() {
return new Vector3f(
Mth.sin(-getYRot() * ((float) Math.PI / 180)),
@ -183,7 +182,6 @@ public class DroneEntity extends LivingEntity implements GeoEntity {
).normalize();
}
public Vector3f getRightDirection() {
return new Vector3f(
Mth.cos(-getYRot() * ((float) Math.PI / 180)),
@ -521,7 +519,7 @@ public class DroneEntity extends LivingEntity implements GeoEntity {
kamikazeExplosion(source.getEntity());
}
ItemStack stack = new ItemStack(ModItems.RGO_GRENADE.get(),this.entityData.get(AMMO));
ItemStack stack = new ItemStack(ModItems.RGO_GRENADE.get(), this.entityData.get(AMMO));
if (this.level() instanceof ServerLevel level) {
ItemEntity itemEntity = new ItemEntity(level, this.getX(), this.getY(), this.getZ(), stack);

View file

@ -3,5 +3,6 @@ package com.atsuishio.superbwarfare.entity;
import net.minecraft.world.entity.player.Player;
public interface ICannonEntity {
void cannonShoot(Player player);
}

View file

@ -54,7 +54,9 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.FLOAT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static final float MAX_HEALTH = CannonConfig.MK42_HP.get();
protected int interpolationSteps;
protected double serverYRot;
protected double serverXRot;
@ -164,7 +166,7 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
if (player.isShiftKeyDown()) {
if (player.getMainHandItem().is(ModItems.CROWBAR.get()) && this.getFirstPassenger() == null) {
ItemStack stack = ContainerBlockItem.createInstance(this);
if (!player.addItem(stack)){
if (!player.addItem(stack)) {
player.drop(stack, false);
}
@ -348,7 +350,7 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
for (Entity target : level.getEntitiesOfClass(Entity.class, new AABB(center, center).inflate(20), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(center))).toList()) {
if (target instanceof ServerPlayer serverPlayer) {
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(15,15,45, this.getX(), this.getEyeY(), this.getZ()));
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(15, 15, 45, this.getX(), this.getEyeY(), this.getZ()));
}
}
}

View file

@ -486,8 +486,6 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
this.clampRotation(entity);
}
private PlayState movementPredicate(AnimationState<Mle1934Entity> event) {
if (this.entityData.get(COOL_DOWN) > 64) {
if (this.entityData.get(TYPE) == 1) {

View file

@ -46,6 +46,7 @@ import software.bernie.geckolib.core.object.PlayState;
import software.bernie.geckolib.util.GeckoLibUtil;
public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity {
public static final EntityDataAccessor<Integer> FIRE_TIME = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> PITCH = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> Y_ROT = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT);

View file

@ -35,6 +35,7 @@ import software.bernie.geckolib.core.object.PlayState;
import software.bernie.geckolib.util.GeckoLibUtil;
public class SenpaiEntity extends Monster implements GeoEntity, AnimatedEntity {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public SenpaiEntity(PlayMessages.SpawnEntity packet, Level world) {

View file

@ -2,7 +2,6 @@ package com.atsuishio.superbwarfare.entity.layer;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.config.server.CannonConfig;
import com.atsuishio.superbwarfare.entity.Mk42Entity;
import com.atsuishio.superbwarfare.entity.Mle1934Entity;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
@ -16,16 +15,17 @@ import software.bernie.geckolib.renderer.GeoRenderer;
import software.bernie.geckolib.renderer.layer.GeoRenderLayer;
public class Mle1934DamageLayer extends GeoRenderLayer<Mle1934Entity> {
private static final ResourceLocation LAYER = new ResourceLocation(ModUtils.MODID, "textures/entity/mle1934_damage.png");
public Mle1934DamageLayer(GeoRenderer<Mle1934Entity> entityRenderer) {
super(entityRenderer);
}
private static final ResourceLocation LAYER = ModUtils.loc("textures/entity/mle1934_damage.png");
@Override
public void render(PoseStack poseStack, Mle1934Entity animatable, BakedGeoModel bakedModel, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, float partialTick, int packedLight, int packedOverlay) {
RenderType glowRenderType = RenderType.entityTranslucent(LAYER);
float heal = Mth.clamp((0.3f * CannonConfig.MLE1934_HP.get() - animatable.getEntityData().get(Mk42Entity.HEALTH)) * 0.000007f * CannonConfig.MLE1934_HP.get(), 0.1f, 1);
getRenderer().reRender(getDefaultBakedModel(animatable), poseStack, bufferSource, animatable, glowRenderType, bufferSource.getBuffer(glowRenderType), partialTick, packedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, heal);
}
public Mle1934DamageLayer(GeoRenderer<Mle1934Entity> entityRenderer) {
super(entityRenderer);
}
@Override
public void render(PoseStack poseStack, Mle1934Entity animatable, BakedGeoModel bakedModel, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, float partialTick, int packedLight, int packedOverlay) {
RenderType glowRenderType = RenderType.entityTranslucent(LAYER);
float heal = Mth.clamp((0.3f * CannonConfig.MLE1934_HP.get() - animatable.getEntityData().get(Mle1934Entity.HEALTH)) * 0.000007f * CannonConfig.MLE1934_HP.get(), 0.1f, 1);
getRenderer().reRender(getDefaultBakedModel(animatable), poseStack, bufferSource, animatable, glowRenderType, bufferSource.getBuffer(glowRenderType), partialTick, packedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, heal);
}
}

View file

@ -5,6 +5,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
@ -49,6 +50,23 @@ public class LaserEntity extends AbstractLaserEntity {
if (this.tickCount >= this.getCountDown()) {
this.calculateEndPos(RADIUS);
CustomHitResult result = new CustomHitResult();
result.setBlockHit(this.level().clip(new ClipContext(new Vec3(getX(), getY(), getZ()), new Vec3(endPosX, endPosY, endPosZ),
ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)));
if (result.getBlockHit() != null) {
Vec3 hitVec = result.getBlockHit().getLocation();
collidePosX = hitVec.x;
collidePosY = hitVec.y;
collidePosZ = hitVec.z;
blockSide = result.getBlockHit().getDirection();
} else {
collidePosX = endPosX;
collidePosY = endPosY;
collidePosZ = endPosZ;
blockSide = null;
}
if (this.blockSide != null) {
this.spawnExplosionParticles();
}