添加集装箱内容显示jade集成

This commit is contained in:
Light_Quanta 2025-02-20 04:02:36 +08:00
parent aa990802ae
commit c8d747811a
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
5 changed files with 60 additions and 5 deletions

View file

@ -132,7 +132,7 @@ public class ContainerBlock extends BaseEntityBlock {
super.appendHoverText(pStack, pLevel, pTooltip, pFlag);
CompoundTag tag = BlockItem.getBlockEntityData(pStack);
if (tag != null && tag.contains("EntityType")) {
String s = getTranslationKey(tag.getString("EntityType"));
String s = getEntityTranslationKey(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);
@ -159,7 +159,7 @@ public class ContainerBlock extends BaseEntityBlock {
}
@Nullable
public String getTranslationKey(String path) {
public static String getEntityTranslationKey(String path) {
String[] parts = path.split(":");
if (parts.length > 1) {
return "entity." + parts[0] + "." + parts[1];

View file

@ -1,5 +1,7 @@
package com.atsuishio.superbwarfare.compat.jade;
import com.atsuishio.superbwarfare.block.ContainerBlock;
import com.atsuishio.superbwarfare.compat.jade.providers.ContainerEntityProvider;
import com.atsuishio.superbwarfare.compat.jade.providers.VehicleHealthProvider;
import com.atsuishio.superbwarfare.entity.vehicle.VehicleEntity;
import snownee.jade.api.IWailaClientRegistration;
@ -12,11 +14,11 @@ public class SbwJadePlugin implements IWailaPlugin {
@Override
public void register(IWailaCommonRegistration registration) {
}
@Override
public void registerClient(IWailaClientRegistration registration) {
registration.registerEntityComponent(VehicleHealthProvider.INSTANCE, VehicleEntity.class);
registration.registerBlockComponent(ContainerEntityProvider.INSTANCE, ContainerBlock.class);
}
}

View file

@ -0,0 +1,51 @@
package com.atsuishio.superbwarfare.compat.jade.providers;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.block.ContainerBlock;
import com.atsuishio.superbwarfare.block.entity.ContainerBlockEntity;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import snownee.jade.api.BlockAccessor;
import snownee.jade.api.IBlockComponentProvider;
import snownee.jade.api.ITooltip;
import snownee.jade.api.config.IPluginConfig;
public enum ContainerEntityProvider implements IBlockComponentProvider {
INSTANCE;
private static final ResourceLocation ID = ModUtils.loc("container_entity");
public void appendTooltip(ITooltip iTooltip, BlockAccessor blockAccessor, IPluginConfig iPluginConfig) {
var container = (ContainerBlockEntity) blockAccessor.getBlockEntity();
// 实体名称显示
var registerName = EntityType.getKey(container.entityType).toString();
var translationKey = ContainerBlock.getEntityTranslationKey(registerName);
iTooltip.add(Component.translatable(translationKey == null ? "des.superbwarfare.container.empty" : translationKey).withStyle(ChatFormatting.GRAY));
// 所需尺寸显示
var entityType = EntityType.byString(registerName).orElse(null);
if (entityType != null) {
int w = (int) (entityType.getDimensions().width + 1);
if (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));
}
}
// 空间不足提示
if (!ContainerBlock.canOpen(blockAccessor.getLevel(), container.getBlockPos(), container.entityType, container.entity)) {
iTooltip.add(Component.translatable("des.superbwarfare.container.fail.open").withStyle(ChatFormatting.RED));
}
}
public ResourceLocation getUid() {
return ID;
}
}

View file

@ -523,5 +523,6 @@
"jei.superbwarfare.charging_station": "Generates power by consuming fuel or food, and can also accept FE energy input. This block supplies FE energy to adjacent blocks, and can also charge rechargeable vehicles within range.",
"config.jade.plugin_superbwarfare.vehicle_energy": "Vehicle Energy",
"config.jade.plugin_superbwarfare.vehicle_health": "Vehicle Health"
"config.jade.plugin_superbwarfare.vehicle_health": "Vehicle Health",
"config.jade.plugin_superbwarfare.container_entity": "Container Entity"
}

View file

@ -523,5 +523,6 @@
"jei.superbwarfare.charging_station": "使用燃料或食物进行发电也可以接收主动输入的FE能量。能够为相邻的方块提供FE能量为周围一定范围内的可充能载具充能。",
"config.jade.plugin_superbwarfare.vehicle_energy": "载具能量",
"config.jade.plugin_superbwarfare.vehicle_health": "载具血量"
"config.jade.plugin_superbwarfare.vehicle_health": "载具血量",
"config.jade.plugin_superbwarfare.container_entity": "集装箱实体"
}