package mcjty.deepresonance.items.rftoolsmodule;
import mcjty.deepresonance.items.GenericDRItem;
import mcjty.deepresonance.radiation.RadiationConfiguration;
import mcjty.deepresonance.varia.BlockInfo;
import mcjty.lib.varia.Logging;
import mcjty.rftools.api.screens.IClientScreenModule;
import mcjty.rftools.api.screens.IModuleProvider;
import mcjty.rftools.api.screens.IScreenModule;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
public class RadiationModuleItem extends GenericDRItem implements IModuleProvider {
public RadiationModuleItem() {
super("radiation_module");
setMaxStackSize(1);
}
@Override
public int getMaxItemUseDuration(ItemStack stack) {
return 1;
}
@Override
public Class<? extends IScreenModule> getServerScreenModule() {
return RadiationScreenModule.class;
}
@Override
public Class<? extends IClientScreenModule> getClientScreenModule() {
return RadiationClientScreenModule.class;
}
@Override
public String getName() {
return "Rad";
}
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack itemStack, EntityPlayer player, List<String> list, boolean whatIsThis) {
super.addInformation(itemStack, player, list, whatIsThis);
list.add(TextFormatting.GREEN + "Uses " + RadiationConfiguration.RADIATIONMODULE_RFPERTICK + " RF/tick");
boolean hasTarget = false;
NBTTagCompound tagCompound = itemStack.getTagCompound();
if (tagCompound != null) {
list.add(TextFormatting.YELLOW + "Label: " + tagCompound.getString("text"));
if (tagCompound.hasKey("monitorx")) {
int monitorx = tagCompound.getInteger("monitorx");
int monitory = tagCompound.getInteger("monitory");
int monitorz = tagCompound.getInteger("monitorz");
String monitorname = tagCompound.getString("monitorname");
list.add(TextFormatting.YELLOW + "Monitoring: " + monitorname + " (at " + monitorx + "," + monitory + "," + monitorz + ")");
hasTarget = true;
}
}
if (!hasTarget) {
list.add(TextFormatting.YELLOW + "Sneak right-click on a radiation sensor to set the");
list.add(TextFormatting.YELLOW + "target for this module");
}
}
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
NBTTagCompound tagCompound = stack.getTagCompound();
if (tagCompound == null) {
tagCompound = new NBTTagCompound();
}
if (block == RFToolsSupport.radiationSensorBlock) {
tagCompound.setInteger("monitordim", world.provider.getDimension());
tagCompound.setInteger("monitorx", pos.getX());
tagCompound.setInteger("monitory", pos.getY());
tagCompound.setInteger("monitorz", pos.getZ());
String name = "<invalid>";
if (block != null && !block.isAir(state, world, pos)) {
name = BlockInfo.getReadableName(state);
}
tagCompound.setString("monitorname", name);
if (world.isRemote) {
Logging.message(player, "Radiation module is set to block '" + name + "'");
}
} else {
tagCompound.removeTag("monitordim");
tagCompound.removeTag("monitorx");
tagCompound.removeTag("monitory");
tagCompound.removeTag("monitorz");
tagCompound.removeTag("monitorname");
if (world.isRemote) {
Logging.message(player, "Radiation module is cleared");
}
}
stack.setTagCompound(tagCompound);
return EnumActionResult.SUCCESS;
}
}