package mcjty.deepresonance.items.rftoolsmodule;
import elec332.core.world.WorldHelper;
import mcjty.deepresonance.items.RadiationMonitorItem;
import mcjty.deepresonance.radiation.RadiationConfiguration;
import mcjty.lib.varia.BlockPosTools;
import mcjty.lib.varia.GlobalCoordinate;
import mcjty.rftools.api.screens.IScreenDataHelper;
import mcjty.rftools.api.screens.IScreenModule;
import mcjty.rftools.api.screens.data.IModuleDataInteger;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
public class RadiationScreenModule implements IScreenModule<IModuleDataInteger> {
private int dim = 0;
private BlockPos coordinate = BlockPosTools.INVALID;
@Override
public IModuleDataInteger getData(IScreenDataHelper h, World worldObj, long millis) {
World world = DimensionManager.getWorld(dim);
if (world == null) {
return null;
}
if (!WorldHelper.chunkLoaded(world, coordinate)) {
return null;
}
Block block = world.getBlockState(coordinate).getBlock();
if (block != RFToolsSupport.radiationSensorBlock) {
return null;
}
float strength = RadiationMonitorItem.calculateRadiationStrength(world, new GlobalCoordinate(coordinate, dim));
return h.createInteger((int) strength);
}
@Override
public void setupFromNBT(NBTTagCompound tagCompound, int dim, BlockPos pos) {
if (tagCompound != null) {
coordinate = BlockPosTools.INVALID;
if (tagCompound.hasKey("monitorx")) {
if (tagCompound.hasKey("monitordim")) {
this.dim = tagCompound.getInteger("monitordim");
} else {
// Compatibility reasons
this.dim = tagCompound.getInteger("dim");
}
if (dim == this.dim) {
BlockPos c = new BlockPos(tagCompound.getInteger("monitorx"), tagCompound.getInteger("monitory"), tagCompound.getInteger("monitorz"));
int dx = Math.abs(c.getX() - pos.getX());
int dy = Math.abs(c.getY() - pos.getY());
int dz = Math.abs(c.getZ() - pos.getZ());
if (dx <= 64 && dy <= 64 && dz <= 64) {
coordinate = c;
}
}
}
}
}
@Override
public int getRfPerTick() {
return RadiationConfiguration.RADIATIONMODULE_RFPERTICK;
}
@Override
public void mouseClick(World world, int x, int y, boolean clicked, EntityPlayer player) {
}
}