实现正确的集装箱占地大小算法

This commit is contained in:
17146 2025-05-08 13:33:08 +08:00 committed by Light_Quanta
parent 97d4d5df0f
commit 9653b1396a
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
2 changed files with 11 additions and 11 deletions

View file

@ -142,7 +142,8 @@ public class ContainerBlock extends BaseEntityBlock {
var entityType = EntityType.byString(tag.getString("EntityType")).orElse(null);
if (entityType != null) {
int w = 0, h = 0;
float w = 0;
int h = 0;
Level level = null;
try {
@ -150,21 +151,21 @@ public class ContainerBlock extends BaseEntityBlock {
} catch (Exception ignored) {
}
if (level != null && tag.contains("Entity")) {
if (level instanceof Level && tag.contains("Entity")) {
var entity = entityType.create(level);
if (entity != null) {
entity.load(tag.getCompound("Entity"));
w = (int) (entity.getType().getDimensions().width() + 1);
if (w % 2 == 0) w++;
w = (float) Math.ceil(entity.getType().getDimensions().width() / 2);
h = (int) (entity.getType().getDimensions().height() + 1);
}
} else {
w = (int) (entityType.getDimensions().width() + 1);
if (w % 2 == 0) w++;
w = (float) Math.ceil(entityType.getDimensions().width() / 2);
h = (int) (entityType.getDimensions().height() + 1);
}
if (w != 0 && h != 0) {
tooltipComponents.add(Component.literal(w + " x " + w + " x " + h).withStyle(ChatFormatting.YELLOW));
w *= 2;
if ((int) w % 2 == 0) w++;
tooltipComponents.add(Component.literal((int) w + " x " + (int) w + " x " + h).withStyle(ChatFormatting.YELLOW));
}
}
}

View file

@ -28,11 +28,11 @@ public enum ContainerEntityProvider implements IBlockComponentProvider {
// 所需尺寸显示
var entityType = EntityType.byString(registerName).orElse(null);
if (entityType != null) {
int w = (int) (entityType.getDimensions().width() + 1);
if (w % 2 == 0) w++;
float w = (float) Math.ceil(entityType.getDimensions().width() / 2) * 2;
if ((int) w % 2 == 0) w++;
int h = (int) (entityType.getDimensions().height() + 1);
if (h != 0) {
iTooltip.add(Component.literal(w + " x " + w + " x " + h).withStyle(ChatFormatting.YELLOW));
iTooltip.add(Component.literal((int) w + " x " + (int) w + " x " + h).withStyle(ChatFormatting.YELLOW));
}
}
@ -46,6 +46,5 @@ public enum ContainerEntityProvider implements IBlockComponentProvider {
public ResourceLocation getUid() {
return ID;
}
}