正确显示Type63装载弹药

This commit is contained in:
Light_Quanta 2025-07-13 20:32:41 +08:00
parent a26434880d
commit 8aa9a0d528
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
2 changed files with 26 additions and 7 deletions

View file

@ -15,6 +15,8 @@ import software.bernie.geckolib.cache.object.BakedGeoModel;
import software.bernie.geckolib.cache.object.GeoBone;
import software.bernie.geckolib.renderer.GeoEntityRenderer;
import static com.atsuishio.superbwarfare.entity.vehicle.Type63Entity.LOADED_AMMO;
public class Type63Renderer extends GeoEntityRenderer<Type63Entity> {
@ -71,12 +73,10 @@ public class Type63Renderer extends GeoEntityRenderer<Type63Entity> {
bone.setRotZ(-Mth.lerp(partialTick, animatable.turretYRotO, animatable.getTurretYRot()) * 6);
}
//TODO 正确实现每一个格子有物品时显示一发炮弹模型
for (int i = 0; i < 11; i++) {
var items = animatable.getItemStacks();
for (int i = 0; i < 12; i++) {
var items = animatable.getEntityData().get(LOADED_AMMO);
if (name.equals("shell" + i)) {
bone.setHidden(items.get(i).isEmpty());
bone.setHidden(items.get(i) == 0);
}
}

View file

@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.entity.OBBEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModSerializers;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
@ -21,6 +22,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.Container;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntityType;
@ -39,12 +41,14 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.ArrayList;
import java.util.List;
public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEntity, OBBEntity {
public static final EntityDataAccessor<Float> PITCH = SynchedEntityData.defineId(Type63Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> YAW = SynchedEntityData.defineId(Type63Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<List<Integer>> LOADED_AMMO = SynchedEntityData.defineId(Type63Entity.class, ModSerializers.INT_LIST_SERIALIZER.get());
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public OBB barrel0;
public OBB barrel1;
@ -88,9 +92,14 @@ public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEnt
@Override
protected void defineSynchedData(SynchedEntityData.Builder builder) {
super.defineSynchedData(builder);
var list = new ArrayList<Integer>();
for (int i = 0; i < this.getContainerSize(); i++) {
list.add(0);
}
builder.define(PITCH, 0F)
.define(YAW, 0F);
.define(YAW, 0F)
.define(LOADED_AMMO, list);
}
@Override
@ -294,7 +303,12 @@ public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEnt
@Override
public boolean canPlaceItem(int slot, @NotNull ItemStack stack) {
return true;
return false;
}
@Override
public boolean canTakeItem(@NotNull Container target, int slot, @NotNull ItemStack stack) {
return false;
}
@Override
@ -381,6 +395,11 @@ public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEnt
this.barrel11.setRotation(VectorTool.combineRotationsBarrel(1, this));
}
@Override
public void setChanged() {
this.entityData.set(LOADED_AMMO, this.items.stream().map(i -> i.isEmpty() ? 0 : 1).toList());
}
@Override
public boolean hasEnergyStorage() {
return false;