移植Jade适配
This commit is contained in:
parent
0374c4de83
commit
111519ea3a
6 changed files with 227 additions and 0 deletions
|
@ -0,0 +1,29 @@
|
||||||
|
package com.atsuishio.superbwarfare.compat;
|
||||||
|
|
||||||
|
//@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
|
||||||
|
public class CompatHolder {
|
||||||
|
|
||||||
|
public static final String DMV = "dreamaticvoyage";
|
||||||
|
public static final String VRC = "virtuarealcraft";
|
||||||
|
public static final String CLOTH_CONFIG = "cloth_config";
|
||||||
|
|
||||||
|
// @ObjectHolder(registryName = "minecraft:mob_effect", value = DMV + ":bleeding")
|
||||||
|
// public static final MobEffect DMV_BLEEDING = null;
|
||||||
|
//
|
||||||
|
// @ObjectHolder(registryName = "minecraft:mob_effect", value = VRC + ":curse_flame")
|
||||||
|
// public static final MobEffect VRC_CURSE_FLAME = null;
|
||||||
|
//
|
||||||
|
// @ObjectHolder(registryName = "minecraft:entity_type", value = VRC + ":rain_shower_butterfly")
|
||||||
|
// public static final EntityType<? extends Projectile> VRC_RAIN_SHOWER_BUTTERFLY = null;
|
||||||
|
|
||||||
|
// @SubscribeEvent
|
||||||
|
// public static void onInterModEnqueue(final InterModEnqueueEvent event) {
|
||||||
|
// event.enqueueWork(() -> hasMod(CLOTH_CONFIG, () -> DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> ClothConfigHelper::registerScreen)));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public static void hasMod(String modid, Runnable runnable) {
|
||||||
|
// if (ModList.get().isLoaded(modid)) {
|
||||||
|
// runnable.run();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
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.base.VehicleEntity;
|
||||||
|
import snownee.jade.api.IWailaClientRegistration;
|
||||||
|
import snownee.jade.api.IWailaCommonRegistration;
|
||||||
|
import snownee.jade.api.IWailaPlugin;
|
||||||
|
import snownee.jade.api.WailaPlugin;
|
||||||
|
|
||||||
|
@WailaPlugin
|
||||||
|
public class SbwJadePlugin implements IWailaPlugin {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(IWailaCommonRegistration registration) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerClient(IWailaClientRegistration registration) {
|
||||||
|
registration.registerEntityComponent(VehicleHealthProvider.INSTANCE, VehicleEntity.class);
|
||||||
|
// TODO C4
|
||||||
|
// registration.registerEntityComponent(C4InfoProvider.INSTANCE, C4Entity.class);
|
||||||
|
registration.registerBlockComponent(ContainerEntityProvider.INSTANCE, ContainerBlock.class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.atsuishio.superbwarfare.compat.jade.elements;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.Font;
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.phys.Vec2;
|
||||||
|
import snownee.jade.api.theme.IThemeHelper;
|
||||||
|
import snownee.jade.api.ui.Element;
|
||||||
|
import snownee.jade.overlay.DisplayHelper;
|
||||||
|
import snownee.jade.overlay.OverlayRenderer;
|
||||||
|
|
||||||
|
import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit;
|
||||||
|
|
||||||
|
public class WrenchHealthElement extends Element {
|
||||||
|
private final String text;
|
||||||
|
|
||||||
|
public WrenchHealthElement(float maxHealth, float health) {
|
||||||
|
this.text = String.format(" %s/%s", DisplayHelper.dfCommas.format(health), DisplayHelper.dfCommas.format(maxHealth));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vec2 getSize() {
|
||||||
|
Font font = Minecraft.getInstance().font;
|
||||||
|
return new Vec2(8F + font.width(this.text), 10.0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final ResourceLocation WRENCH_ICON = ModUtils.loc("textures/screens/vehicle_health.png");
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(GuiGraphics guiGraphics, float x, float y, float maxX, float maxY) {
|
||||||
|
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, OverlayRenderer.alpha);
|
||||||
|
RenderSystem.setShaderTexture(0, WRENCH_ICON);
|
||||||
|
RenderSystem.enableBlend();
|
||||||
|
RenderSystem.defaultBlendFunc();
|
||||||
|
|
||||||
|
// 扳手图标
|
||||||
|
preciseBlit(guiGraphics, WRENCH_ICON, x + 2, y, 0, 0, 8, 8, 8, 8);
|
||||||
|
// 文字
|
||||||
|
DisplayHelper.INSTANCE.drawText(guiGraphics, this.text, x + 6, y, IThemeHelper.get().getNormalColor());
|
||||||
|
|
||||||
|
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.atsuishio.superbwarfare.compat.jade.providers;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import snownee.jade.api.EntityAccessor;
|
||||||
|
import snownee.jade.api.IEntityComponentProvider;
|
||||||
|
import snownee.jade.api.ITooltip;
|
||||||
|
import snownee.jade.api.config.IPluginConfig;
|
||||||
|
|
||||||
|
public enum C4InfoProvider implements IEntityComponentProvider {
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
private static final ResourceLocation ID = ModUtils.loc("c4_info");
|
||||||
|
|
||||||
|
public void appendTooltip(ITooltip tooltip, EntityAccessor accessor, IPluginConfig config) {
|
||||||
|
// TODO C4 Info
|
||||||
|
// var c4 = (C4Entity) accessor.getEntity();
|
||||||
|
//
|
||||||
|
// if (c4.getEntityData().get(C4Entity.IS_CONTROLLABLE)) {
|
||||||
|
// // 遥控
|
||||||
|
// tooltip.add(Component.translatable("des.jade_plugin_superbwarfare.c4.remote_control").withStyle(ChatFormatting.YELLOW));
|
||||||
|
// } else {
|
||||||
|
// // 定时
|
||||||
|
// var timeLeft = ExplosionConfig.C4_EXPLOSION_COUNTDOWN.get() - c4.tickCount;
|
||||||
|
// tooltip.add(Component.translatable(
|
||||||
|
// "des.jade_plugin_superbwarfare.c4.time_left",
|
||||||
|
// String.format("%.2f", timeLeft / 20.0)
|
||||||
|
// ).withStyle(ChatFormatting.YELLOW));
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceLocation getUid() {
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDefaultPriority() {
|
||||||
|
return -4501;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.atsuishio.superbwarfare.compat.jade.providers;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
|
import com.atsuishio.superbwarfare.compat.jade.elements.WrenchHealthElement;
|
||||||
|
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import snownee.jade.api.EntityAccessor;
|
||||||
|
import snownee.jade.api.IEntityComponentProvider;
|
||||||
|
import snownee.jade.api.ITooltip;
|
||||||
|
import snownee.jade.api.config.IPluginConfig;
|
||||||
|
|
||||||
|
public enum VehicleHealthProvider implements IEntityComponentProvider {
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
private static final ResourceLocation ID = ModUtils.loc("vehicle_health");
|
||||||
|
|
||||||
|
public void appendTooltip(ITooltip tooltip, EntityAccessor accessor, IPluginConfig config) {
|
||||||
|
// 对EntityHealthAndArmorProvider的拙劣模仿罢了
|
||||||
|
|
||||||
|
var vehicle = (VehicleEntity) accessor.getEntity();
|
||||||
|
float health = vehicle.getHealth();
|
||||||
|
float maxHealth = vehicle.getMaxHealth();
|
||||||
|
tooltip.add(new WrenchHealthElement(maxHealth, health));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceLocation getUid() {
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDefaultPriority() {
|
||||||
|
return -4501;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue