|
| 1 | +package gregtech.integration.hwyla.provider; |
| 2 | + |
| 3 | +import gregtech.api.GTValues; |
| 4 | +import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; |
| 5 | +import gregtech.common.metatileentities.multi.multiblockpart.appeng.MetaTileEntityAEHostablePart; |
| 6 | + |
| 7 | +import net.minecraft.client.resources.I18n; |
| 8 | +import net.minecraft.entity.player.EntityPlayerMP; |
| 9 | +import net.minecraft.item.ItemStack; |
| 10 | +import net.minecraft.nbt.NBTTagCompound; |
| 11 | +import net.minecraft.tileentity.TileEntity; |
| 12 | +import net.minecraft.util.math.BlockPos; |
| 13 | +import net.minecraft.world.World; |
| 14 | + |
| 15 | +import mcp.mobius.waila.api.IWailaConfigHandler; |
| 16 | +import mcp.mobius.waila.api.IWailaDataAccessor; |
| 17 | +import mcp.mobius.waila.api.IWailaDataProvider; |
| 18 | +import mcp.mobius.waila.api.IWailaRegistrar; |
| 19 | +import org.jetbrains.annotations.NotNull; |
| 20 | + |
| 21 | +import java.util.List; |
| 22 | + |
| 23 | +public class AEMultiblockHatchProvider implements IWailaDataProvider { |
| 24 | + |
| 25 | + private static final String NBT_KEY = "ae_part_online"; |
| 26 | + |
| 27 | + public static final AEMultiblockHatchProvider INSTANCE = new AEMultiblockHatchProvider(); |
| 28 | + |
| 29 | + public void register(@NotNull IWailaRegistrar registrar) { |
| 30 | + registrar.registerBodyProvider(this, IGregTechTileEntity.class); |
| 31 | + registrar.registerNBTProvider(this, IGregTechTileEntity.class); |
| 32 | + registrar.addConfig(GTValues.MOD_NAME, "gregtech.ae_multiblock_hatch_provider"); |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + public @NotNull NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, |
| 37 | + BlockPos pos) { |
| 38 | + if (te instanceof IGregTechTileEntity gtte && |
| 39 | + gtte.getMetaTileEntity() instanceof MetaTileEntityAEHostablePart<?>aeHostablePart) { |
| 40 | + tag.setBoolean(NBT_KEY, aeHostablePart.isOnline()); |
| 41 | + } |
| 42 | + |
| 43 | + return tag; |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public @NotNull List<String> getWailaBody(ItemStack itemStack, List<String> tooltip, IWailaDataAccessor accessor, |
| 48 | + IWailaConfigHandler config) { |
| 49 | + if (accessor.getNBTData().hasKey(NBT_KEY)) { |
| 50 | + if (accessor.getNBTData().getBoolean(NBT_KEY)) { |
| 51 | + tooltip.add(I18n.format("gregtech.gui.me_network.online")); |
| 52 | + } else { |
| 53 | + tooltip.add(I18n.format("gregtech.gui.me_network.offline")); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + return tooltip; |
| 58 | + } |
| 59 | +} |
0 commit comments