修改开箱判定

This commit is contained in:
17146 2025-01-06 21:34:01 +08:00
parent 2a66820647
commit 33949c21eb

View file

@ -1,9 +1,7 @@
package com.atsuishio.superbwarfare.block;
import com.atsuishio.superbwarfare.block.entity.ContainerBlockEntity;
import com.atsuishio.superbwarfare.entity.vehicle.ICannonEntity;
import com.atsuishio.superbwarfare.init.ModBlockEntities;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import net.minecraft.ChatFormatting;
@ -87,22 +85,20 @@ public class ContainerBlock extends BaseEntityBlock {
return containerBlockEntity.entity != null || containerBlockEntity.entityType != null;
}
public boolean canOpen(Level pLevel, BlockPos pPos, EntityType entityType, Entity entity) {
public boolean canOpen(Level pLevel, BlockPos pPos, EntityType<?> entityType, Entity entity) {
boolean flag = true;
int w = 0;
int h = 0;
boolean extra = entityType == ModEntities.MLE_1934.get() || entityType == ModEntities.MK_42.get() || entity instanceof ICannonEntity;
if (entityType != null) {
w = (int) (entityType.getDimensions().width / 2 + (extra ? 2 : 0));
h = (int) (entityType.getDimensions().height + (extra ? 2 : 0));
w = (int) (entityType.getDimensions().width / 2 + 1);
h = (int) (entityType.getDimensions().height + 1);
}
if (entity != null) {
w = (int) (entity.getType().getDimensions().width / 2 + (extra ? 2 : 0));
h = (int) (entity.getType().getDimensions().height + (extra ? 2 : 0));
w = (int) (entity.getType().getDimensions().width / 2 + 1);
h = (int) (entity.getType().getDimensions().height + 1);
}
for (int i = -w; i < w + 1; i++) {
@ -111,8 +107,8 @@ public class ContainerBlock extends BaseEntityBlock {
if (i == 0 && j == 0 && k == 0) {
continue;
}
//TODO 修改开箱
if (!pLevel.getBlockState(pPos.offset(i, j, k)).isAir()) {
if (pLevel.getBlockState(pPos.offset(i, j, k)).canOcclude()) {
flag = false;
}
}
@ -134,11 +130,32 @@ public class ContainerBlock extends BaseEntityBlock {
@Override
public void appendHoverText(ItemStack pStack, @Nullable BlockGetter pLevel, List<Component> pTooltip, TooltipFlag pFlag) {
super.appendHoverText(pStack, pLevel, pTooltip, pFlag);
CompoundTag compoundtag = BlockItem.getBlockEntityData(pStack);
if (compoundtag != null) {
if (compoundtag.contains("EntityType")) {
String s = getTranslationKey(compoundtag.getString("EntityType"));
CompoundTag tag = BlockItem.getBlockEntityData(pStack);
if (tag != null) {
if (tag.contains("EntityType")) {
String s = getTranslationKey(tag.getString("EntityType"));
pTooltip.add(Component.translatable(s == null ? "des.superbwarfare.container.empty" : s).withStyle(ChatFormatting.GRAY));
var entityType = EntityType.byString(tag.getString("EntityType")).orElse(null);
if (entityType != null) {
int w = 0, h = 0;
if (pLevel instanceof Level 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++;
h = (int) (entity.getType().getDimensions().height + 1);
}
} else {
w = (int) (entityType.getDimensions().width + 1);
if (w % 2 == 0) w++;
h = (int) (entityType.getDimensions().height + 1);
}
if (w != 0 && h != 0) {
pTooltip.add(Component.literal(w + " x " + w + " x " + h).withStyle(ChatFormatting.YELLOW));
}
}
}
}
}