package com.yolp900.itsjustacharm.common.affinities.affinityInteractionHandlers;
import com.yolp900.itsjustacharm.api.affinities.IAffinity;
import com.yolp900.itsjustacharm.api.affinities.IAffinityHolderItem;
import com.yolp900.itsjustacharm.api.affinities.IAffinityHolderTile;
import com.yolp900.itsjustacharm.client.guis.huds.HudHandler;
import com.yolp900.itsjustacharm.common.blocks.BlockConstructionTable;
import com.yolp900.itsjustacharm.common.tileEntities.TileEntityConstructionTable;
import com.yolp900.itsjustacharm.reference.LibTexts;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.List;
public class ConstructionTableInteractionHandler extends ModAffinityInteractionHandler {
@Override
public void onInteraction(ItemStack stack, IAffinityHolderItem holderItem, TileEntity tile, IAffinityHolderTile holderTile, Block block, BlockPos pos, EntityPlayer player, World world) {
if (holderTile instanceof TileEntityConstructionTable && block instanceof BlockConstructionTable && player.isSneaking()) {
IAffinity affinity = holderItem.getStoredAffinity(stack, holderItem.getCurrentAffinityIndex(stack, player, world), player, world);
if (affinity != null) {
boolean success = holderTile.storeAffinity(affinity, player, world);
if (!success) {
List<String> popup = LibTexts.Popups.FailureStoringAffinity.getLinedFormattedText(affinity.getName().toLowerCase(), block.getLocalizedName().toLowerCase());
HudHandler.affinityInteraction.set(popup, 0x880000, affinity.getAffinityIconTexture(player, world), new ItemStack(block));
HudHandler.affinityInteraction.startRendering(player, world);
} else {
List<String> popup = LibTexts.Popups.SuccessStoringAffinity.getLinedFormattedText(affinity.getName().toLowerCase(), block.getLocalizedName().toLowerCase());
HudHandler.affinityInteraction.set(popup, 0x009900, affinity.getAffinityIconTexture(player, world), new ItemStack(block));
HudHandler.affinityInteraction.startRendering(player, world);
}
}
}
}
}