package com.yolp900.itsjustacharm.common.integration.waila;
import com.yolp900.itsjustacharm.reference.LibModIntegrations;
import mcp.mobius.waila.api.*;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.event.FMLInterModComms;
import java.util.List;
public class WailaIntegration implements IWailaDataProvider {
public static void init() {
FMLInterModComms.sendMessage(LibModIntegrations.Waila.MOD_ID, LibModIntegrations.Waila.REGISTER, LibModIntegrations.Waila.REGISTER_METHOD_LOCATION);
}
public static void handleIntegration(IWailaRegistrar registrar) {
WailaIntegration instance = new WailaIntegration();
registrar.registerStackProvider(instance, Block.class);
registrar.registerHeadProvider(instance, Block.class);
registrar.registerBodyProvider(instance, Block.class);
registrar.registerTailProvider(instance, Block.class);
}
@Override
public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config) {
TileEntity tile = accessor.getTileEntity();
Block block = accessor.getBlock();
if (tile instanceof IWailaStackProvider) {
return ((IWailaStackProvider)tile).getWailaStack(accessor, config);
}
if (block instanceof IWailaStackProvider) {
return ((IWailaStackProvider)block).getWailaStack(accessor, config);
}
return accessor.getStack();
}
@Override
public List<String> getWailaHead(ItemStack stack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
TileEntity tile = accessor.getTileEntity();
Block block = accessor.getBlock();
if (tile instanceof IWailaHeadProvider) {
return ((IWailaHeadProvider)tile).getWailaHead(stack, currenttip, accessor, config).getLinedFormattedText();
}
if (block instanceof IWailaHeadProvider) {
return ((IWailaHeadProvider)block).getWailaHead(stack, currenttip, accessor, config).getLinedFormattedText();
}
return currenttip;
}
@Override
public List<String> getWailaBody(ItemStack stack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
TileEntity tile = accessor.getTileEntity();
Block block = accessor.getBlock();
if (tile instanceof IWailaBodyProvider) {
return ((IWailaBodyProvider)tile).getWailaBody(stack, currenttip, accessor, config).getLinedFormattedText();
}
if (block instanceof IWailaBodyProvider) {
return ((IWailaBodyProvider)block).getWailaBody(stack, currenttip, accessor, config).getLinedFormattedText();
}
return currenttip;
}
@Override
public List<String> getWailaTail(ItemStack stack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
TileEntity tile = accessor.getTileEntity();
Block block = accessor.getBlock();
if (tile instanceof IWailaTailProvider) {
return ((IWailaTailProvider)tile).getWailaTail(stack, currenttip, accessor, config).getLinedFormattedText();
}
if (block instanceof IWailaTailProvider) {
return ((IWailaTailProvider)block).getWailaTail(stack, currenttip, accessor, config).getLinedFormattedText();
}
return currenttip;
}
@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, BlockPos pos) {
if (tile != null)
tile.writeToNBT(tag);
return tag;
}
}