use of cavern.api.IMinerStats in project Cavern2 by kegare.
the class MinerStats method adjustData.
public static void adjustData(EntityPlayerMP player) {
IMinerStats stats = MinerStats.get(player, true);
if (stats != null) {
stats.adjustData();
CaveNetworkRegistry.sendTo(new MiningRecordsMessage(stats), player);
}
}
use of cavern.api.IMinerStats in project Cavern2 by kegare.
the class MinerDataMessage method process.
@SideOnly(Side.CLIENT)
@Override
public IMessage process(EntityPlayerSP player) {
IMinerStats stats = MinerStats.get(player, true);
if (stats != null) {
stats.setPoint(point, false);
stats.setRank(rank, false);
stats.setMiningAssist(miningAssist, false);
}
return null;
}
use of cavern.api.IMinerStats in project Cavern2 by kegare.
the class MiningAssistEventHooks method isActive.
private boolean isActive(EntityPlayer player, IBlockState state) {
ItemStack held = player.getHeldItemMainhand();
if (!MiningAssistConfig.isEffectiveItem(held)) {
return false;
}
IMinerStats stats = MinerStats.get(player);
if (stats.getRank() < MiningAssistConfig.minerRank.getValue()) {
return false;
}
MiningAssist type = MiningAssist.get(stats.getMiningAssist());
if (type == MiningAssist.DISABLED) {
return false;
}
return type.isEffectiveTarget(held, state);
}
use of cavern.api.IMinerStats in project Cavern2 by kegare.
the class MinerStatsHUDEventHooks method onRenderGamePostOverlay.
@SubscribeEvent
public void onRenderGamePostOverlay(RenderGameOverlayEvent.Post event) {
if (event.getType() != ElementType.HOTBAR) {
return;
}
Minecraft mc = FMLClientHandler.instance().getClient();
ConfigDisplayPos.Type displayType = getDisplayType();
if (!canRenderHUD(mc)) {
miningPointPer = -1.0D;
return;
}
ScaledResolution resolution = event.getResolution();
IMinerStats stats = MinerStats.get(mc.player, true);
if (stats == null || stats.getPoint() < 0) {
return;
}
MinerRank minerRank = MinerRank.get(stats.getRank());
MiningAssist miningAssist = MiningAssist.get(stats.getMiningAssist());
String point = Integer.toString(stats.getPoint());
String rank = I18n.format(minerRank.getUnlocalizedName());
if (miningAssist != MiningAssist.DISABLED && stats.getRank() >= MiningAssistConfig.minerRank.getValue()) {
rank += " / " + I18n.format(miningAssist.getUnlocalizedName());
}
setDisplayPos(displayType, mc, resolution.getScaledWidth(), resolution.getScaledHeight());
int x = posX;
int y = posY;
RenderItem renderItem = mc.getRenderItem();
FontRenderer renderer = mc.fontRenderer;
boolean flag = false;
IMiningData data = MiningData.get(mc.player);
long processTime = mc.world.getTotalWorldTime() - data.getLastMiningTime();
if (data.getLastMiningTime() > 0L && processTime < 50 && data.getLastMiningBlock() != null && data.getLastMiningPoint() != 0) {
IBlockState state = data.getLastMiningBlock();
ItemStack stack = new ItemStack(CaveRenderingRegistry.getRenderBlock(state.getBlock()), 1, state.getBlock().getMetaFromState(state));
RenderHelper.enableGUIStandardItemLighting();
renderItem.renderItemIntoGUI(stack, x, y);
renderItem.renderItemOverlayIntoGUI(renderer, stack, x, y, Integer.toString(data.getLastMiningPoint()));
RenderHelper.disableStandardItemLighting();
flag = true;
}
if (flag) {
x += displayType.isLeft() ? 20 : -20;
}
renderItem.renderItemIntoGUI(minerRank.getItemStack(), x, y);
GlStateManager.pushMatrix();
GlStateManager.disableDepth();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
if (point.length() <= 1) {
point = " " + point;
}
MinerRank nextRank = MinerRank.get(stats.getRank() + 1);
if (minerRank.getRank() < nextRank.getRank()) {
String per = String.format("%.2f", calcMiningPointPer(stats.getPoint(), nextRank.getPhase(), false)) + "%";
point = displayType.isLeft() ? point + " < " + per : per + " > " + point;
}
String combo = null;
if (data.getMiningCombo() > 0) {
TextFormatting format = TextFormatting.WHITE;
if (processTime < 3 * 20) {
format = TextFormatting.BOLD;
} else if (processTime > 12 * 20) {
format = TextFormatting.GRAY;
}
combo = format + String.format("%d COMBO!", data.getMiningCombo()) + TextFormatting.RESET;
}
boolean showRank = DisplayConfig.showMinerRank;
boolean hasCombo = combo != null;
int pointX = displayType.isLeft() ? x + 5 : x + 17 - renderer.getStringWidth(point);
int pointY = y + 9;
int rankX = showRank ? displayType.isLeft() ? posX + 5 : posX + 17 - renderer.getStringWidth(rank) : -1;
int rankY = showRank ? displayType.isTop() ? y + 21 : y - 12 : -1;
int comboX = hasCombo ? displayType.isLeft() ? posX + 5 : posX + 17 - renderer.getStringWidth(combo) : -1;
int comboY = hasCombo ? displayType.isTop() ? y + 33 : y - 24 : -1;
renderer.drawStringWithShadow(point, pointX, pointY, 0xCECECE);
if (showRank) {
renderer.drawStringWithShadow(rank, rankX, rankY, 0xCECECE);
if (hasCombo) {
renderer.drawStringWithShadow(combo, comboX, comboY, 0xFFFFFF);
}
}
GlStateManager.enableDepth();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
use of cavern.api.IMinerStats in project Cavern2 by kegare.
the class CaveCapabilities method onPlayerClone.
@SubscribeEvent
public void onPlayerClone(PlayerEvent.Clone event) {
EntityPlayer player = event.getEntityPlayer();
if (player.world.isRemote) {
return;
}
EntityPlayer original = event.getOriginal();
IPortalCache originalPortalCache = getCapability(original, PORTAL_CACHE);
IPortalCache portalCache = getCapability(player, PORTAL_CACHE);
if (originalPortalCache != null && portalCache != null) {
NBTTagCompound nbt = new NBTTagCompound();
originalPortalCache.writeToNBT(nbt);
portalCache.readFromNBT(nbt);
}
IPlayerData originalPlayerData = getCapability(original, PLAYER_DATA);
IPlayerData playerData = getCapability(player, PLAYER_DATA);
if (originalPlayerData != null && playerData != null) {
NBTTagCompound nbt = new NBTTagCompound();
originalPlayerData.writeToNBT(nbt);
playerData.readFromNBT(nbt);
}
IMinerStats originalMinerStats = getCapability(original, MINER_STATS);
IMinerStats minerStats = getCapability(player, MINER_STATS);
if (originalMinerStats != null && minerStats != null) {
NBTTagCompound nbt = new NBTTagCompound();
originalMinerStats.writeToNBT(nbt);
minerStats.readFromNBT(nbt);
}
}
Aggregations