use of cavern.miningassist.MiningAssist 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.miningassist.MiningAssist in project Cavern2 by kegare.
the class MiningAssistEventHooks method onBlockBreak.
@SubscribeEvent
public void onBlockBreak(BreakEvent event) {
World world = event.getWorld();
if (world.isRemote) {
return;
}
EntityPlayer player = event.getPlayer();
if (player == null || player instanceof FakePlayer) {
return;
}
BlockPos pos = event.getPos();
MiningAssistUnit assist = MiningAssistUnit.get(player);
if (assist.addExperience(pos, event.getExpToDrop())) {
event.setExpToDrop(0);
}
if (breaking) {
return;
}
if (!(player instanceof EntityPlayerMP)) {
return;
}
IBlockState state = event.getState();
if (!isActive(player, state)) {
return;
}
MiningAssist type = MiningAssist.byPlayer(player);
MiningSnapshot snapshot = assist.getSnapshot(type, pos, state);
if (snapshot.isEmpty()) {
return;
}
PlayerInteractionManager im = ((EntityPlayerMP) player).interactionManager;
assist.captureDrops(MiningAssistConfig.collectDrops);
assist.captureExperiences(MiningAssistConfig.collectExps);
breaking = true;
for (BlockPos target : snapshot.getTargets()) {
if (snapshot.validTarget(target) && !harvestBlock(im, target)) {
break;
}
}
breaking = false;
Map<BlockPos, NonNullList<ItemStack>> drops = assist.captureDrops(false);
if (drops != null && !drops.isEmpty()) {
for (NonNullList<ItemStack> items : drops.values()) {
for (ItemStack stack : items) {
Block.spawnAsEntity(world, pos, stack);
}
}
}
Map<BlockPos, Integer> experiences = assist.captureExperiences(false);
if (experiences != null && !experiences.isEmpty() && !im.isCreative() && world.getGameRules().getBoolean("doTileDrops")) {
int exp = experiences.values().stream().mapToInt(Integer::intValue).sum();
while (exp > 0) {
int i = EntityXPOrb.getXPSplit(exp);
exp -= i;
world.spawnEntity(new EntityXPOrb(world, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, i));
}
}
}
use of cavern.miningassist.MiningAssist 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.miningassist.MiningAssist in project Cavern2 by kegare.
the class MiningAssistEventHooks method onBreakSpeed.
@SubscribeEvent
public void onBreakSpeed(BreakSpeed event) {
if (!MiningAssistConfig.modifiedHardness || !Cavern.proxy.isSinglePlayer()) {
return;
}
if (checking) {
return;
}
EntityPlayer player = event.getEntityPlayer();
IBlockState state = event.getState();
if (!isActive(player, state)) {
return;
}
MiningAssistUnit assist = MiningAssistUnit.get(player);
MiningAssist type = MiningAssist.byPlayer(player);
BlockPos pos = event.getPos();
checking = true;
MiningSnapshot snapshot = assist.getSnapshot(type, pos, state);
if (!snapshot.isEmpty()) {
event.setNewSpeed(assist.getBreakSpeed(snapshot));
}
checking = false;
}
use of cavern.miningassist.MiningAssist in project Cavern2 by kegare.
the class ClientEventHooks method onPlayerLoggedIn.
@SubscribeEvent
public void onPlayerLoggedIn(PlayerLoggedInEvent event) {
EntityPlayer player = event.player;
if (MiningAssistConfig.miningAssistNotify) {
MiningAssist assist = MiningAssist.byPlayer(player);
if (assist != MiningAssist.DISABLED) {
ITextComponent message = new TextComponentTranslation(assist.getUnlocalizedName());
message.getStyle().setColor(TextFormatting.GRAY).setItalic(Boolean.valueOf(true));
message = new TextComponentTranslation("cavern.miningassist.notify.message", message);
player.sendMessage(message);
}
}
}
Aggregations