2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-07-03 20:57:00 +02:00
|
|
|
* This file ("ClientEvents.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.event;
|
2015-05-04 17:26:50 +02:00
|
|
|
|
2018-06-24 02:44:47 +02:00
|
|
|
import java.util.Locale;
|
|
|
|
|
2018-05-10 11:38:58 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
2016-07-03 20:57:00 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.IHudDisplay;
|
2017-03-04 22:25:40 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.ConfigValues;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
|
2016-08-03 17:17:52 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
|
2017-02-13 15:23:28 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.data.WorldData;
|
2016-07-21 13:22:55 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.inventory.gui.EnergyDisplay;
|
2016-12-31 16:15:56 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.items.ItemWingsOfTheBats;
|
2016-07-03 20:57:00 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.IEnergyDisplay;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
|
2016-11-16 20:31:16 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraft.block.Block;
|
2015-09-13 20:50:32 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraft.client.gui.FontRenderer;
|
2016-03-18 15:42:06 +01:00
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
2016-07-22 00:58:39 +02:00
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-08-01 00:30:56 +02:00
|
|
|
import net.minecraft.item.Item;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2016-12-31 16:15:56 +01:00
|
|
|
import net.minecraft.item.ItemSword;
|
2016-01-22 19:40:00 +01:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-12-24 17:24:16 +01:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
2016-07-03 22:53:12 +02:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2015-05-04 17:26:50 +02:00
|
|
|
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
2017-02-13 15:23:28 +01:00
|
|
|
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
|
|
|
|
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-05-04 17:26:50 +02:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
|
2016-07-03 20:57:00 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public class ClientEvents {
|
2015-05-04 17:26:50 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
private static final String ADVANCED_INFO_TEXT_PRE = TextFormatting.DARK_GRAY + " ";
|
|
|
|
private static final String ADVANCED_INFO_HEADER_PRE = TextFormatting.GRAY + " -";
|
2015-08-01 00:30:56 +02:00
|
|
|
|
2016-07-21 18:35:38 +02:00
|
|
|
private static EnergyDisplay energyDisplay;
|
2016-07-21 13:22:55 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public ClientEvents() {
|
2016-07-03 22:53:12 +02:00
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
|
|
}
|
|
|
|
|
2017-02-13 15:23:28 +01:00
|
|
|
@SubscribeEvent
|
2019-05-02 09:10:29 +02:00
|
|
|
public void onClientTick(ClientTickEvent event) {
|
|
|
|
if (event.phase == Phase.END) {
|
2017-02-13 15:23:28 +01:00
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (mc.world == null) {
|
2017-02-13 15:23:28 +01:00
|
|
|
WorldData.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-01 01:30:50 +02:00
|
|
|
@SubscribeEvent
|
2019-05-02 09:10:29 +02:00
|
|
|
public void onTooltipEvent(ItemTooltipEvent event) {
|
2016-12-31 16:15:56 +01:00
|
|
|
ItemStack stack = event.getItemStack();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(stack)) {
|
2016-12-31 16:15:56 +01:00
|
|
|
//Be da bland
|
2019-05-02 09:10:29 +02:00
|
|
|
if (ConfigBoolValues.MOST_BLAND_PERSON_EVER.isEnabled()) {
|
2016-12-31 16:15:56 +01:00
|
|
|
ResourceLocation regName = stack.getItem().getRegistryName();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (regName != null) {
|
|
|
|
if (regName.toString().toLowerCase(Locale.ROOT).contains(ActuallyAdditions.MODID)) {
|
|
|
|
if (event.getToolTip().size() > 0) {
|
|
|
|
event.getToolTip().set(0, TextFormatting.RESET + TextFormatting.WHITE.toString() + event.getToolTip().get(0));
|
2016-12-31 16:15:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (ItemWingsOfTheBats.THE_BAT_BAT.equalsIgnoreCase(stack.getDisplayName()) && stack.getItem() instanceof ItemSword) {
|
|
|
|
event.getToolTip().set(0, TextFormatting.GOLD + event.getToolTip().get(0));
|
|
|
|
event.getToolTip().add(1, TextFormatting.RED.toString() + TextFormatting.ITALIC + "That's a really bat pun");
|
2016-12-31 16:15:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-13 20:50:32 +02:00
|
|
|
//Advanced Item Info
|
2019-05-02 09:10:29 +02:00
|
|
|
if (event.getFlags().isAdvanced() && StackUtil.isValid(event.getItemStack())) {
|
|
|
|
if (ConfigBoolValues.CTRL_EXTRA_INFO.isEnabled()) {
|
|
|
|
if (GuiScreen.isCtrlKeyDown()) {
|
|
|
|
event.getToolTip().add(TextFormatting.DARK_GRAY + "" + TextFormatting.ITALIC + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".extraInfo.desc") + ":");
|
2015-08-01 00:30:56 +02:00
|
|
|
|
|
|
|
//OreDict Names
|
2016-04-20 21:39:03 +02:00
|
|
|
int[] oreIDs = OreDictionary.getOreIDs(event.getItemStack());
|
2019-05-02 09:10:29 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".oredictName.desc") + ":");
|
|
|
|
if (oreIDs.length > 0) {
|
|
|
|
for (int oreID : oreIDs) {
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE + OreDictionary.getOreName(oreID));
|
2015-08-01 00:30:56 +02:00
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".noOredictNameAvail.desc"));
|
2015-08-01 00:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Code Name
|
2019-05-02 09:10:29 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".codeName.desc") + ":");
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE + Item.REGISTRY.getNameForObject(event.getItemStack().getItem()));
|
2015-08-01 00:30:56 +02:00
|
|
|
|
|
|
|
//Base Item's Unlocalized Name
|
2018-08-04 04:22:20 +02:00
|
|
|
String baseName = event.getItemStack().getItem().getTranslationKey();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (baseName != null) {
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".baseUnlocName.desc") + ":");
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE + baseName);
|
2015-08-02 01:52:12 +02:00
|
|
|
}
|
2015-08-01 00:30:56 +02:00
|
|
|
|
2016-01-22 21:48:11 +01:00
|
|
|
//Metadata
|
2016-04-20 21:39:03 +02:00
|
|
|
int meta = event.getItemStack().getItemDamage();
|
2016-05-07 23:38:50 +02:00
|
|
|
int max = event.getItemStack().getMaxDamage();
|
2019-05-02 09:10:29 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".meta.desc") + ":");
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE + meta + (max > 0 ? "/" + max : ""));
|
2016-01-22 21:48:11 +01:00
|
|
|
|
2015-08-01 00:30:56 +02:00
|
|
|
//Unlocalized Name
|
2018-08-04 04:22:20 +02:00
|
|
|
String metaName = event.getItemStack().getItem().getTranslationKey(event.getItemStack());
|
2019-05-02 09:10:29 +02:00
|
|
|
if (metaName != null && baseName != null && !metaName.equals(baseName)) {
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".unlocName.desc") + ":");
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE + metaName);
|
2015-08-01 00:30:56 +02:00
|
|
|
}
|
2015-08-17 23:59:38 +02:00
|
|
|
|
2016-01-22 19:40:00 +01:00
|
|
|
//NBT
|
2016-04-20 21:39:03 +02:00
|
|
|
NBTTagCompound compound = event.getItemStack().getTagCompound();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (compound != null && !compound.isEmpty()) {
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".nbt.desc") + ":");
|
|
|
|
if (GuiScreen.isShiftKeyDown()) {
|
2016-08-03 17:17:52 +02:00
|
|
|
int limit = ConfigIntValues.CTRL_INFO_NBT_CHAR_LIMIT.getValue();
|
|
|
|
String compoundStrg = compound.toString();
|
|
|
|
int compoundStrgLength = compoundStrg.length();
|
|
|
|
|
|
|
|
String compoundDisplay;
|
2019-05-02 09:10:29 +02:00
|
|
|
if (limit > 0 && compoundStrgLength > limit) {
|
|
|
|
compoundDisplay = compoundStrg.substring(0, limit) + TextFormatting.GRAY + " (" + (compoundStrgLength - limit) + " more characters...)";
|
|
|
|
} else {
|
2016-08-03 17:17:52 +02:00
|
|
|
compoundDisplay = compoundStrg;
|
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE + compoundDisplay);
|
|
|
|
} else {
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE + TextFormatting.ITALIC + "[" + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".pressShift.desc") + "]");
|
2016-01-22 19:40:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-17 23:59:38 +02:00
|
|
|
//Disabling Info
|
2019-05-02 09:10:29 +02:00
|
|
|
event.getToolTip().add(TextFormatting.ITALIC + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".disablingInfo.desc"));
|
2016-01-22 19:40:00 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
|
|
|
if (ConfigBoolValues.CTRL_INFO_FOR_EXTRA_INFO.isEnabled()) {
|
|
|
|
event.getToolTip().add(TextFormatting.DARK_GRAY + "" + TextFormatting.ITALIC + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".ctrlForMoreInfo.desc"));
|
2015-08-02 09:58:36 +02:00
|
|
|
}
|
2015-05-04 17:26:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-03 20:57:00 +02:00
|
|
|
|
|
|
|
@SubscribeEvent
|
2019-05-02 09:10:29 +02:00
|
|
|
public void onGameOverlay(RenderGameOverlayEvent.Post event) {
|
|
|
|
if (event.getType() == RenderGameOverlayEvent.ElementType.ALL && Minecraft.getMinecraft().currentScreen == null) {
|
2016-07-03 20:57:00 +02:00
|
|
|
Minecraft minecraft = Minecraft.getMinecraft();
|
2016-11-26 21:32:27 +01:00
|
|
|
EntityPlayer player = minecraft.player;
|
2016-07-03 20:57:00 +02:00
|
|
|
RayTraceResult posHit = minecraft.objectMouseOver;
|
2017-06-29 18:30:02 +02:00
|
|
|
FontRenderer font = minecraft.fontRenderer;
|
2016-07-03 20:57:00 +02:00
|
|
|
ItemStack stack = player.getHeldItemMainhand();
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(stack)) {
|
|
|
|
if (stack.getItem() instanceof IHudDisplay) {
|
|
|
|
((IHudDisplay) stack.getItem()).displayHud(minecraft, player, stack, posHit, event.getResolution());
|
2016-07-03 20:57:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (posHit != null && posHit.getBlockPos() != null) {
|
2016-11-26 21:32:27 +01:00
|
|
|
Block blockHit = minecraft.world.getBlockState(posHit.getBlockPos()).getBlock();
|
|
|
|
TileEntity tileHit = minecraft.world.getTileEntity(posHit.getBlockPos());
|
2016-07-03 20:57:00 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (blockHit instanceof IHudDisplay) {
|
|
|
|
((IHudDisplay) blockHit).displayHud(minecraft, player, stack, posHit, event.getResolution());
|
2016-07-03 20:57:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (tileHit instanceof TileEntityBase) {
|
|
|
|
TileEntityBase base = (TileEntityBase) tileHit;
|
|
|
|
if (base.isRedstoneToggle()) {
|
|
|
|
String strg = String.format("%s: %s", StringUtil.localize("info." + ActuallyAdditions.MODID + ".redstoneMode.name"), TextFormatting.DARK_RED + StringUtil.localize("info." + ActuallyAdditions.MODID + ".redstoneMode." + (base.isPulseMode ? "pulse" : "deactivation")) + TextFormatting.RESET);
|
|
|
|
font.drawStringWithShadow(strg, event.getResolution().getScaledWidth() / 2 + 5, event.getResolution().getScaledHeight() / 2 + 5, StringUtil.DECIMAL_COLOR_WHITE);
|
2016-07-03 20:57:00 +02:00
|
|
|
|
2016-10-19 18:42:07 +02:00
|
|
|
String expl;
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(stack) && stack.getItem() == ConfigValues.itemRedstoneTorchConfigurator) {
|
|
|
|
expl = TextFormatting.GREEN + StringUtil.localize("info." + ActuallyAdditions.MODID + ".redstoneMode.validItem");
|
|
|
|
} else {
|
|
|
|
expl = TextFormatting.GRAY.toString() + TextFormatting.ITALIC + StringUtil.localizeFormatted("info." + ActuallyAdditions.MODID + ".redstoneMode.invalidItem", StringUtil.localize(ConfigValues.itemRedstoneTorchConfigurator.getTranslationKey() + ".name"));
|
2016-10-19 18:42:07 +02:00
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
font.drawStringWithShadow(expl, event.getResolution().getScaledWidth() / 2 + 5, event.getResolution().getScaledHeight() / 2 + 15, StringUtil.DECIMAL_COLOR_WHITE);
|
2016-07-03 20:57:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (tileHit instanceof IEnergyDisplay) {
|
|
|
|
IEnergyDisplay display = (IEnergyDisplay) tileHit;
|
|
|
|
if (!display.needsHoldShift() || player.isSneaking()) {
|
|
|
|
if (energyDisplay == null) {
|
2016-07-21 18:35:38 +02:00
|
|
|
energyDisplay = new EnergyDisplay(0, 0, null);
|
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
energyDisplay.setData(2, event.getResolution().getScaledHeight() - 96, display.getEnergyStorage(), true, true);
|
2016-07-22 00:58:39 +02:00
|
|
|
|
|
|
|
GlStateManager.pushMatrix();
|
|
|
|
GlStateManager.color(1F, 1F, 1F, 1F);
|
2016-07-21 18:35:38 +02:00
|
|
|
energyDisplay.draw();
|
2016-07-22 00:58:39 +02:00
|
|
|
GlStateManager.popMatrix();
|
2016-07-03 20:57:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-04 17:26:50 +02:00
|
|
|
}
|