Campfire WTHIT and TOP integration
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package me.hypherionmc.hyperlighting.common.integration.top;
|
||||
|
||||
import mcjty.theoneprobe.api.IProbeConfig;
|
||||
import mcjty.theoneprobe.api.ITheOneProbe;
|
||||
import mcjty.theoneprobe.api.ITheOneProbePlugin;
|
||||
import me.hypherionmc.hyperlighting.common.integration.top.overrides.TOPCampfireInfoProvider;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* @date 27/08/2022
|
||||
*/
|
||||
public class TOPIntegration implements ITheOneProbePlugin {
|
||||
|
||||
private static ITheOneProbe theOneProbe;
|
||||
|
||||
@Override
|
||||
public void onLoad(ITheOneProbe apiInstance) {
|
||||
TOPIntegration.theOneProbe = apiInstance;
|
||||
|
||||
theOneProbe.registerBlockDisplayOverride(new TOPCampfireInfoProvider());
|
||||
}
|
||||
|
||||
public static IProbeConfig getProbeConfig() {
|
||||
return theOneProbe.createProbeConfig();
|
||||
}
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
package me.hypherionmc.hyperlighting.common.integration.top.overrides;
|
||||
|
||||
import mcjty.theoneprobe.api.*;
|
||||
import me.hypherionmc.hyperlighting.Constants;
|
||||
import me.hypherionmc.hyperlighting.common.blockentities.AdvancedCampfireBlockEntity;
|
||||
import me.hypherionmc.hyperlighting.common.integration.top.TOPIntegration;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import static mcjty.theoneprobe.api.IProbeConfig.ConfigMode.EXTENDED;
|
||||
import static mcjty.theoneprobe.api.IProbeConfig.ConfigMode.NORMAL;
|
||||
import static mcjty.theoneprobe.api.TextStyleClass.MODNAME;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* @date 27/08/2022
|
||||
*/
|
||||
public class TOPCampfireInfoProvider implements IBlockDisplayOverride {
|
||||
|
||||
@Override
|
||||
public boolean overrideStandardInfo(ProbeMode probeMode, IProbeInfo iProbeInfo, Player playerEntity, Level world, BlockState blockState, IProbeHitData iProbeHitData) {
|
||||
IProbeConfig config = TOPIntegration.getProbeConfig();
|
||||
|
||||
if (probeMode != ProbeMode.DEBUG) {
|
||||
if (world.getBlockEntity(iProbeHitData.getPos()) instanceof AdvancedCampfireBlockEntity tileCampFire) {
|
||||
String modName = FabricLoader.getInstance().getModContainer(Constants.MOD_ID).get().getMetadata().getName();
|
||||
iProbeInfo
|
||||
.horizontal()
|
||||
.item(iProbeHitData.getPickBlock())
|
||||
.vertical()
|
||||
.text(CompoundText.create().name(blockState.getBlock().getName()))
|
||||
.vertical()
|
||||
.text(CompoundText.create().info(MODNAME + modName));
|
||||
|
||||
for (int i = 0; i < tileCampFire.getItems().size(); i++) {
|
||||
ItemStack stack = tileCampFire.getItems().get(i);
|
||||
if (!stack.isEmpty()) {
|
||||
iProbeInfo
|
||||
.horizontal()
|
||||
.item(stack)
|
||||
.horizontal()
|
||||
.progress(
|
||||
(int) ((float) tileCampFire.cookingTime[i] / tileCampFire.cookingProgress[i] * 100),
|
||||
100,
|
||||
iProbeInfo.defaultProgressStyle().suffix(" %").alignment(ElementAlignment.ALIGN_TOPLEFT));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean show(ProbeMode mode, IProbeConfig.ConfigMode cfg) {
|
||||
return cfg == NORMAL || (cfg == EXTENDED && mode == ProbeMode.EXTENDED);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package me.hypherionmc.hyperlighting.common.integration.wthit;
|
||||
|
||||
import mcp.mobius.waila.api.IPluginConfig;
|
||||
import mcp.mobius.waila.api.IServerAccessor;
|
||||
import mcp.mobius.waila.api.IServerDataProvider;
|
||||
import me.hypherionmc.hyperlighting.common.blockentities.AdvancedCampfireBlockEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* @date 27/08/2022
|
||||
*/
|
||||
public class CampfireDataProvider implements IServerDataProvider<AdvancedCampfireBlockEntity> {
|
||||
|
||||
@Override
|
||||
public void appendServerData(CompoundTag data, IServerAccessor<AdvancedCampfireBlockEntity> accessor, IPluginConfig config) {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
accessor.getTarget().saveAdditional(tag);
|
||||
data.put("hl_campfire", tag);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
package me.hypherionmc.hyperlighting.common.integration.wthit;
|
||||
|
||||
import mcp.mobius.waila.api.IBlockAccessor;
|
||||
import mcp.mobius.waila.api.IBlockComponentProvider;
|
||||
import mcp.mobius.waila.api.IPluginConfig;
|
||||
import mcp.mobius.waila.api.ITooltip;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.ContainerHelper;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* @date 27/08/2022
|
||||
*/
|
||||
public class CampfireProvider implements IBlockComponentProvider {
|
||||
|
||||
@Override
|
||||
public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) {
|
||||
CompoundTag compound = accessor.getServerData().getCompound("hl_campfire");
|
||||
int[] cookingTimes = new int[4];
|
||||
int[] cookingTotalTimes = new int[4];
|
||||
NonNullList<ItemStack> inventory = NonNullList.withSize(4, ItemStack.EMPTY);
|
||||
|
||||
inventory.clear();
|
||||
ContainerHelper.loadAllItems(compound, inventory);
|
||||
if (compound.contains("CookingTimes", 11)) {
|
||||
int[] aint = compound.getIntArray("CookingTimes");
|
||||
System.arraycopy(aint, 0, cookingTimes, 0, Math.min(cookingTotalTimes.length, aint.length));
|
||||
}
|
||||
|
||||
if (compound.contains("CookingTotalTimes", 11)) {
|
||||
int[] aint1 = compound.getIntArray("CookingTotalTimes");
|
||||
System.arraycopy(aint1, 0, cookingTotalTimes, 0, Math.min(cookingTotalTimes.length, aint1.length));
|
||||
}
|
||||
|
||||
if (inventory.isEmpty()) {
|
||||
tooltip.addLine(Component.literal(ChatFormatting.RED + "Empty"));
|
||||
} else {
|
||||
for (int i = 0; i < inventory.size(); i++) {
|
||||
if (!inventory.get(i).isEmpty()) {
|
||||
int progress = (int) ((float) cookingTimes[i] / cookingTotalTimes[i] * 100);
|
||||
tooltip.addLine(Component.literal(inventory.get(i).getDisplayName().getString() + " : " + ChatFormatting.YELLOW + progress + "%"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package me.hypherionmc.hyperlighting.common.integration.wthit;
|
||||
|
||||
import mcp.mobius.waila.api.IRegistrar;
|
||||
import mcp.mobius.waila.api.IWailaPlugin;
|
||||
import mcp.mobius.waila.api.TooltipPosition;
|
||||
import me.hypherionmc.hyperlighting.Constants;
|
||||
import me.hypherionmc.hyperlighting.common.blockentities.AdvancedCampfireBlockEntity;
|
||||
import me.hypherionmc.hyperlighting.common.blocks.AdvancedCampfire;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* @date 27/08/2022
|
||||
*/
|
||||
public class HLWTHITPlugin implements IWailaPlugin {
|
||||
|
||||
@Override
|
||||
public void register(IRegistrar registrar) {
|
||||
Constants.LOG.info("Registering WTHIT Plugins");
|
||||
//registrar.addComponent(new FogMachineProvider(), TooltipPosition.BODY, FogMachineBlock.class);
|
||||
|
||||
registrar.addBlockData(new CampfireDataProvider(), AdvancedCampfireBlockEntity.class);
|
||||
registrar.addComponent(new CampfireProvider(), TooltipPosition.BODY, AdvancedCampfire.class);
|
||||
}
|
||||
}
|
@@ -23,6 +23,9 @@
|
||||
],
|
||||
"client": [
|
||||
"me.hypherionmc.hyperlighting.client.HyperLightingFabricClient"
|
||||
],
|
||||
"top_plugin": [
|
||||
"me.hypherionmc.hyperlighting.common.integration.top.TOPIntegration"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
@@ -37,5 +40,11 @@
|
||||
"java": ">=17",
|
||||
"craterlib": "*"
|
||||
},
|
||||
"custom": {
|
||||
"waila:plugins": {
|
||||
"id": "hyperlighting:waila_compat",
|
||||
"initializer": "me.hypherionmc.hyperlighting.common.integration.wthit.HLWTHITPlugin"
|
||||
}
|
||||
},
|
||||
"accessWidener": "hyperlighting.aw"
|
||||
}
|
||||
|
Reference in New Issue
Block a user