修改开箱判定
This commit is contained in:
parent
2a66820647
commit
33949c21eb
1 changed files with 32 additions and 15 deletions
|
@ -1,9 +1,7 @@
|
||||||
package com.atsuishio.superbwarfare.block;
|
package com.atsuishio.superbwarfare.block;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.block.entity.ContainerBlockEntity;
|
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.ModBlockEntities;
|
||||||
import com.atsuishio.superbwarfare.init.ModEntities;
|
|
||||||
import com.atsuishio.superbwarfare.init.ModItems;
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
|
@ -87,22 +85,20 @@ public class ContainerBlock extends BaseEntityBlock {
|
||||||
return containerBlockEntity.entity != null || containerBlockEntity.entityType != null;
|
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;
|
boolean flag = true;
|
||||||
|
|
||||||
int w = 0;
|
int w = 0;
|
||||||
int h = 0;
|
int h = 0;
|
||||||
|
|
||||||
boolean extra = entityType == ModEntities.MLE_1934.get() || entityType == ModEntities.MK_42.get() || entity instanceof ICannonEntity;
|
|
||||||
|
|
||||||
if (entityType != null) {
|
if (entityType != null) {
|
||||||
w = (int) (entityType.getDimensions().width / 2 + (extra ? 2 : 0));
|
w = (int) (entityType.getDimensions().width / 2 + 1);
|
||||||
h = (int) (entityType.getDimensions().height + (extra ? 2 : 0));
|
h = (int) (entityType.getDimensions().height + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
w = (int) (entity.getType().getDimensions().width / 2 + (extra ? 2 : 0));
|
w = (int) (entity.getType().getDimensions().width / 2 + 1);
|
||||||
h = (int) (entity.getType().getDimensions().height + (extra ? 2 : 0));
|
h = (int) (entity.getType().getDimensions().height + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = -w; i < w + 1; i++) {
|
for (int i = -w; i < w + 1; i++) {
|
||||||
|
@ -111,8 +107,8 @@ public class ContainerBlock extends BaseEntityBlock {
|
||||||
if (i == 0 && j == 0 && k == 0) {
|
if (i == 0 && j == 0 && k == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//TODO 修改开箱
|
|
||||||
if (!pLevel.getBlockState(pPos.offset(i, j, k)).isAir()) {
|
if (pLevel.getBlockState(pPos.offset(i, j, k)).canOcclude()) {
|
||||||
flag = false;
|
flag = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,11 +130,32 @@ public class ContainerBlock extends BaseEntityBlock {
|
||||||
@Override
|
@Override
|
||||||
public void appendHoverText(ItemStack pStack, @Nullable BlockGetter pLevel, List<Component> pTooltip, TooltipFlag pFlag) {
|
public void appendHoverText(ItemStack pStack, @Nullable BlockGetter pLevel, List<Component> pTooltip, TooltipFlag pFlag) {
|
||||||
super.appendHoverText(pStack, pLevel, pTooltip, pFlag);
|
super.appendHoverText(pStack, pLevel, pTooltip, pFlag);
|
||||||
CompoundTag compoundtag = BlockItem.getBlockEntityData(pStack);
|
CompoundTag tag = BlockItem.getBlockEntityData(pStack);
|
||||||
if (compoundtag != null) {
|
if (tag != null) {
|
||||||
if (compoundtag.contains("EntityType")) {
|
if (tag.contains("EntityType")) {
|
||||||
String s = getTranslationKey(compoundtag.getString("EntityType"));
|
String s = getTranslationKey(tag.getString("EntityType"));
|
||||||
pTooltip.add(Component.translatable(s == null ? "des.superbwarfare.container.empty" : s).withStyle(ChatFormatting.GRAY));
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue