添加集装箱开启提示
This commit is contained in:
parent
f8fe42a253
commit
38c751818d
5 changed files with 50 additions and 14 deletions
|
@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.block;
|
|||
import com.atsuishio.superbwarfare.block.entity.ContainerBlockEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
@ -47,20 +48,32 @@ public class ContainerBlock extends BaseEntityBlock {
|
|||
public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHit) {
|
||||
if (!pLevel.isClientSide) {
|
||||
ItemStack stack = pPlayer.getItemInHand(pHand);
|
||||
if (stack.is(ModItems.CROWBAR.get()) && canOpen(pLevel, pPos)) {
|
||||
pLevel.setBlockAndUpdate(pPos, pState.setValue(OPENED, true));
|
||||
return InteractionResult.SUCCESS;
|
||||
if (stack.is(ModItems.CROWBAR.get())) {
|
||||
if (!hasEntity(pLevel, pPos)) {
|
||||
pPlayer.displayClientMessage(Component.translatable("des.superbwarfare.container.fail.empty"), true);
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
if (canOpen(pLevel, pPos)) {
|
||||
pLevel.setBlockAndUpdate(pPos, pState.setValue(OPENED, true));
|
||||
return InteractionResult.SUCCESS;
|
||||
} else {
|
||||
pPlayer.displayClientMessage(Component.translatable("des.superbwarfare.container.fail.open"), true);
|
||||
}
|
||||
} else {
|
||||
pPlayer.displayClientMessage(Component.translatable("des.superbwarfare.container.fail.crowbar"), true);
|
||||
}
|
||||
pPlayer.displayClientMessage(Component.literal("打不开哼哼啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊"), true);
|
||||
}
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
public boolean canOpen(Level pLevel, BlockPos pPos) {
|
||||
public boolean hasEntity(Level pLevel, BlockPos pPos) {
|
||||
BlockEntity blockEntity = pLevel.getBlockEntity(pPos);
|
||||
if (!(blockEntity instanceof ContainerBlockEntity containerBlockEntity)) return false;
|
||||
if (containerBlockEntity.entity == null && containerBlockEntity.entityType == null) return false;
|
||||
return containerBlockEntity.entity != null || containerBlockEntity.entityType != null;
|
||||
}
|
||||
|
||||
public boolean canOpen(Level pLevel, BlockPos pPos) {
|
||||
boolean flag = true;
|
||||
|
||||
for (int i = -4; i < 5; i++) {
|
||||
|
@ -93,15 +106,23 @@ public class ContainerBlock extends BaseEntityBlock {
|
|||
super.appendHoverText(pStack, pLevel, pTooltip, pFlag);
|
||||
CompoundTag compoundtag = BlockItem.getBlockEntityData(pStack);
|
||||
if (compoundtag != null) {
|
||||
if (compoundtag.contains("Entity")) {
|
||||
pTooltip.add(Component.literal("Entity: " + compoundtag.getString("Entity")));
|
||||
}
|
||||
if (compoundtag.contains("EntityType")) {
|
||||
pTooltip.add(Component.literal("EntityType: " + compoundtag.getString("EntityType")));
|
||||
String s = getTranslationKey(compoundtag.getString("EntityType"));
|
||||
pTooltip.add(Component.translatable(s == null ? "des.superbwarfare.container.empty" : s).withStyle(ChatFormatting.GRAY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getTranslationKey(String path) {
|
||||
String[] parts = path.split(":");
|
||||
if (parts.length > 1) {
|
||||
return "entity." + parts[0] + "." + parts[1];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
|
||||
return state.getValue(OPENED) ? box(1, 0, 1, 15, 14, 15) : box(0, 0, 0, 16, 15, 16);
|
||||
|
|
|
@ -102,12 +102,14 @@ public class ModTabs {
|
|||
.icon(() -> new ItemStack(ModItems.TARGET_DEPLOYER.get()))
|
||||
.withTabsBefore(AMMO_TAB.getKey())
|
||||
.displayItems((param, output) -> ModItems.ITEMS.getEntries().forEach(registryObject -> {
|
||||
output.accept(registryObject.get());
|
||||
if (registryObject.get() == ModItems.ARMOR_PLATE.get()) {
|
||||
output.accept(ArmorPlate.getInfiniteInstance());
|
||||
}
|
||||
if (registryObject.get() == ModItems.CONTAINER.get()) {
|
||||
output.accept(ContainerBlockItem.createMk42Instance());
|
||||
output.accept(ContainerBlockItem.createMle1934Instance());
|
||||
} else {
|
||||
output.accept(registryObject.get());
|
||||
if (registryObject.get() == ModItems.ARMOR_PLATE.get()) {
|
||||
output.accept(ArmorPlate.getInfiniteInstance());
|
||||
}
|
||||
}
|
||||
}))
|
||||
.build());
|
||||
|
|
|
@ -61,6 +61,7 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
|
|||
ItemStack stack = new ItemStack(ModBlocks.CONTAINER.get());
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put("Entity", entity.serializeNBT());
|
||||
tag.putString("EntityType", EntityType.getKey(entity.getType()).toString());
|
||||
BlockItem.setBlockEntityData(stack, ModBlockEntities.CONTAINER.get(), tag);
|
||||
return stack;
|
||||
}
|
||||
|
@ -76,4 +77,8 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
|
|||
public static ItemStack createMk42Instance() {
|
||||
return createInstance(ModEntities.MK_42.get());
|
||||
}
|
||||
|
||||
public static ItemStack createMle1934Instance() {
|
||||
return createInstance(ModEntities.MLE_1934.get());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,6 +150,10 @@
|
|||
"item.superbwarfare.javelin_missile": "Javelin Missile",
|
||||
|
||||
"block.superbwarfare.container": "Container",
|
||||
"des.superbwarfare.container.empty": "空的",
|
||||
"des.superbwarfare.container.fail.empty": "这个箱子是空的",
|
||||
"des.superbwarfare.container.fail.open": "没有足够的空间",
|
||||
"des.superbwarfare.container.fail.crowbar": "或许应该换个工具试试",
|
||||
"item.superbwarfare.firing_parameters": "Firing Parameters",
|
||||
"item.superbwarfare.ancient_cpu": "Ancient CPU",
|
||||
"item.superbwarfare.target_deployer": "Target",
|
||||
|
|
|
@ -150,6 +150,10 @@
|
|||
"item.superbwarfare.javelin_missile": "标枪导弹",
|
||||
|
||||
"block.superbwarfare.container": "集装箱",
|
||||
"des.superbwarfare.container.empty": "空的",
|
||||
"des.superbwarfare.container.fail.empty": "这个箱子是空的",
|
||||
"des.superbwarfare.container.fail.open": "没有足够的空间",
|
||||
"des.superbwarfare.container.fail.crowbar": "或许应该换个工具试试",
|
||||
"item.superbwarfare.firing_parameters": "射击诸元",
|
||||
"item.superbwarfare.ancient_cpu": "古代处理器",
|
||||
"item.superbwarfare.target_deployer": "标靶",
|
||||
|
|
Loading…
Add table
Reference in a new issue