use of net.minecraft.util.text.ITextComponent 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);
}
}
}
use of net.minecraft.util.text.ITextComponent in project Cavern2 by kegare.
the class ClientEventHooks method onConnected.
@SubscribeEvent
public void onConnected(ClientConnectedToServerEvent event) {
Minecraft mc = FMLClientHandler.instance().getClient();
if (GeneralConfig.versionNotify) {
ITextComponent message;
ITextComponent name = new TextComponentString(Cavern.metadata.name);
name.getStyle().setColor(TextFormatting.AQUA);
if (Version.isOutdated()) {
ITextComponent latest = new TextComponentString(Version.getLatest().toString());
latest.getStyle().setColor(TextFormatting.YELLOW);
message = new TextComponentTranslation("cavern.version.message", name);
message.appendText(" : ").appendSibling(latest);
message.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Cavern.metadata.url));
mc.ingameGUI.getChatGUI().printChatMessage(message);
}
message = null;
if (Version.DEV_DEBUG) {
message = new TextComponentTranslation("cavern.version.message.dev", name);
} else if (Version.isBeta()) {
message = new TextComponentTranslation("cavern.version.message.beta", name);
} else if (Version.isAlpha()) {
message = new TextComponentTranslation("cavern.version.message.alpha", name);
}
if (message != null) {
mc.ingameGUI.getChatGUI().printChatMessage(message);
}
}
}
use of net.minecraft.util.text.ITextComponent in project Cavern2 by kegare.
the class MagicEventHooks method onTick.
@SubscribeEvent
public void onTick(ClientTickEvent event) {
if (event.phase != Phase.END) {
return;
}
Minecraft mc = FMLClientHandler.instance().getClient();
if (mc.world == null || mc.player == null || mc.currentScreen != null) {
return;
}
MagicBook book = MagicBook.get(mc.player);
boolean isMagicKeyDown = CaveKeyBindings.KEY_MAGIC_BOOK.isKeyDown();
if (isMagicKeyDown || mc.gameSettings.keyBindUseItem.isKeyDown()) {
ItemStack stack = book.getSpellingMagicBook();
Magic magic = book.getSpellingMagic();
if (spellingResult != null && spellingResult != EnumActionResult.PASS) {
if (!sendResult) {
if (magic != null) {
if (spellingResult == EnumActionResult.SUCCESS) {
ActionResult<ITextComponent> result = magic.fireMagic();
CaveNetworkRegistry.sendToServer(new MagicResultMessage(result.getType()));
ITextComponent message = result.getResult();
if (message != null) {
mc.ingameGUI.setOverlayMessage(message, true);
}
if (magic.isOverload()) {
book.setSpecialMagic(null);
}
} else {
CaveNetworkRegistry.sendToServer(new MagicResultMessage(EnumActionResult.FAIL));
}
magic.onCloseBook();
SoundEvent sound = magic.getCloseSound();
if (sound != null) {
mc.getSoundHandler().playDelayedSound(PositionedSoundRecord.getMasterRecord(sound, 1.0F), 5);
}
}
book.setSpellingMagic(null);
sendResult = true;
}
return;
}
if (book.isSpellingCanceled()) {
spellingResult = EnumActionResult.FAIL;
return;
}
if (magic == null) {
Pair<EnumHand, ItemStack> magicBook = getMagicBook(mc.player);
if (magicBook == null) {
spellingResult = EnumActionResult.FAIL;
return;
}
stack = magicBook.getRight();
magic = EnumType.byItemStack(stack).createMagic(mc.world, mc.player, magicBook.getLeft());
if (magic == null) {
spellingResult = EnumActionResult.FAIL;
return;
}
book.setSpellingMagic(magic);
if (magic.getSpellingHand() == EnumHand.MAIN_HAND) {
spellingSlot = mc.player.inventory.currentItem;
}
CaveNetworkRegistry.sendToServer(new MagicBookMessage(magic.getSpellingHand()));
}
boolean hasSpecialMagic = book.getSpecialMagic() != null;
boolean infinity = hasSpecialMagic && book.getSpecialMagic() instanceof MagicInfinity;
if (hasSpecialMagic && magic instanceof SpecialMagic) {
spellingResult = EnumActionResult.FAIL;
return;
}
if (!mc.player.capabilities.isCreativeMode && ItemMagicBook.isInCoolTime(mc.player, stack)) {
mc.ingameGUI.setOverlayMessage(new TextComponentTranslation("item.magicBook.fail.time"), false);
spellingResult = EnumActionResult.FAIL;
return;
}
if (magic.getSpellingHand() == EnumHand.MAIN_HAND) {
mc.player.inventory.currentItem = spellingSlot;
}
double progress = magic.getSpellingProgress();
if (infinity) {
progress = MathHelper.clamp(progress * 2.5D, 0.0D, 1.0D);
}
if (progress >= 1.0D) {
spellingResult = EnumActionResult.SUCCESS;
return;
}
EnumActionResult result = magic.onSpelling();
if (result != EnumActionResult.PASS) {
spellingResult = result;
return;
}
if (++spellingSoundTicks >= (infinity ? 8 : 12)) {
SoundEvent sound = magic.getSpellingSound();
if (sound != null) {
mc.getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(sound, 1.0F));
}
spellingSoundTicks = 0;
}
for (int i = 0; i < 2; ++i) {
int var1 = RANDOM.nextInt(2) * 2 - 1;
int var2 = RANDOM.nextInt(2) * 2 - 1;
double ptX = mc.player.posX + 0.25D * var1;
double ptY = mc.player.posY + 0.7D + RANDOM.nextFloat();
double ptZ = mc.player.posZ + 0.25D * var2;
double motionX = RANDOM.nextFloat() * 1.0F * var1;
double motionY = (RANDOM.nextFloat() - 0.25D) * 0.125D;
double motionZ = RANDOM.nextFloat() * 1.0F * var2;
ParticleMagicSpell particle = new ParticleMagicSpell(mc.world, ptX, ptY, ptZ, motionX, motionY, motionZ);
mc.effectRenderer.addEffect(particle);
}
} else {
Magic magic = book.getSpellingMagic();
if (magic != null) {
CaveNetworkRegistry.sendToServer(new MagicResultMessage(EnumActionResult.FAIL));
magic.onCloseBook();
SoundEvent sound = magic.getCloseSound();
if (sound != null) {
mc.getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(sound, 1.0F));
}
}
book.setSpellingMagic(null);
spellingResult = null;
spellingSlot = 0;
spellingSoundTicks = 0;
sendResult = false;
}
SpecialMagic magic = book.getSpecialMagic();
if (magic != null && magic.getEffectProgress() >= 1.0D) {
ITextComponent message = magic.finishMagic();
if (message != null) {
mc.ingameGUI.setOverlayMessage(message, false);
}
CaveNetworkRegistry.sendToServer(new SpecialMagicMessage());
book.setSpecialMagic(null);
}
}
use of net.minecraft.util.text.ITextComponent in project Cavern2 by kegare.
the class MinerStats method addPoint.
@Override
public void addPoint(int value, boolean adjust) {
MinerStatsEvent.AddPoint event = new MinerStatsEvent.AddPoint(entityPlayer, this, value);
if (MinecraftForge.EVENT_BUS.post(event)) {
return;
}
setPoint(point + event.getNewPoint(), adjust);
if (entityPlayer != null && value > 0 && point > 0 && point % 100 == 0) {
entityPlayer.addExperience(entityPlayer.xpBarCap() / 2);
}
MinerRank current = MinerRank.get(rank);
int max = MinerRank.values().length - 1;
boolean promoted = false;
while (current.getRank() < max) {
MinerRank next = MinerRank.get(rank + 1);
if (point >= next.getPhase()) {
++rank;
promoted = true;
current = next;
setPoint(point - current.getPhase(), false);
} else
break;
}
if (promoted) {
if (adjust) {
adjustData();
}
if (entityPlayer != null && entityPlayer instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) entityPlayer;
MinecraftServer server = player.mcServer;
ITextComponent name = new TextComponentTranslation(current.getUnlocalizedName());
name.getStyle().setBold(true);
ITextComponent component = new TextComponentTranslation("cavern.minerrank.promoted", player.getDisplayName(), name);
component.getStyle().setColor(TextFormatting.GRAY).setItalic(true);
server.getPlayerList().sendMessage(component);
double x = player.posX;
double y = player.posY + player.getEyeHeight();
double z = player.posZ;
player.getServerWorld().playSound(null, x, y, z, CaveSounds.RANK_PROMOTE, SoundCategory.MASTER, 0.85F, 1.0F);
switch(current) {
case IRON_MINER:
PlayerHelper.grantAdvancement(player, "iron_miner");
break;
case GOLD_MINER:
PlayerHelper.grantAdvancement(player, "gold_miner");
break;
case HEXCITE_MINER:
PlayerHelper.grantAdvancement(player, "hexcite_miner");
break;
case DIAMOND_MINER:
PlayerHelper.grantAdvancement(player, "diamond_miner");
break;
default:
}
if (current.getRank() >= MiningAssistConfig.minerRank.getValue()) {
PlayerHelper.grantToast(player, "mining_assist");
}
}
MinecraftForge.EVENT_BUS.post(new MinerStatsEvent.PromoteRank(entityPlayer, this));
}
}
use of net.minecraft.util.text.ITextComponent in project Cavern2 by kegare.
the class MagicResultMessage method process.
@Override
public IMessage process(EntityPlayerMP player) {
MagicBook book = MagicBook.get(player);
Magic magic = book.getSpellingMagic();
if (magic != null) {
EnumActionResult type;
ITextComponent message;
if (clientResult == EnumActionResult.PASS) {
ActionResult<ITextComponent> result = magic.fireMagic();
type = result.getType();
message = result.getResult();
} else {
type = clientResult;
message = null;
}
if (type == EnumActionResult.SUCCESS) {
ItemStack stack = book.getSpellingMagicBook();
World world = player.getServerWorld();
int cost = 0;
SpecialMagic specialMagic = book.getSpecialMagic();
if (specialMagic != null && specialMagic != magic && specialMagic.hasSpecialCost(magic)) {
cost = specialMagic.getSpecialCost(magic);
} else {
cost = magic.getCost();
}
if (cost == 0) {
ItemMagicBook.setLastUseTime(stack, world.getTotalWorldTime());
} else {
if (ItemMagicBook.consumeMana(stack, cost) > 0) {
ItemMagicBook.setLastUseTime(stack, world.getTotalWorldTime());
} else {
player.setHeldItem(magic.getSpellingHand(), new ItemStack(Items.BOOK));
}
}
SoundEvent sound = magic.getSuccessSound();
if (sound != null) {
world.playSound(null, player.posX, player.posY + 0.25D, player.posZ, sound, SoundCategory.PLAYERS, 1.0F, 1.0F);
}
if (magic.isOverload()) {
book.setSpecialMagic(null);
}
}
if (message != null) {
player.sendStatusMessage(message, true);
}
magic.onCloseBook();
}
book.setSpellingMagic(null);
return null;
}
Aggregations