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
|
|
|
|
2021-02-27 17:22:03 +01:00
|
|
|
import com.mojang.blaze3d.platform.GlStateManager;
|
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;
|
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-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;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2021-02-27 17:22:03 +01:00
|
|
|
import net.minecraft.util.math.BlockRayTraceResult;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
2021-02-27 17:22:03 +01:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
|
|
|
import net.minecraft.util.text.StringTextComponent;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2021-02-27 17:22:03 +01:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
2021-02-27 17:22:03 +01:00
|
|
|
import net.minecraftforge.event.TickEvent;
|
2015-05-04 17:26:50 +02:00
|
|
|
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
2021-02-27 17:22:03 +01:00
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
2015-05-04 17:26:50 +02:00
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public class ClientEvents {
|
2015-05-04 17:26:50 +02:00
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
private static final ITextComponent ADVANCED_INFO_TEXT_PRE = new StringTextComponent(" -").withStyle(TextFormatting.DARK_GRAY);
|
|
|
|
private static final ITextComponent ADVANCED_INFO_HEADER_PRE = new StringTextComponent(" -").withStyle(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
|
|
|
|
2021-02-27 17:22:03 +01:00
|
|
|
// TODO: [port] the fuck?
|
2017-02-13 15:23:28 +01:00
|
|
|
@SubscribeEvent
|
2021-02-27 17:22:03 +01:00
|
|
|
public void onClientTick(TickEvent.ClientTickEvent event) {
|
|
|
|
if (event.phase == TickEvent.Phase.END) {
|
2021-02-26 22:15:48 +01:00
|
|
|
Minecraft mc = Minecraft.getInstance();
|
2017-02-13 15:23:28 +01:00
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
if (mc.level == 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) {
|
2021-02-27 17:35:21 +01:00
|
|
|
// TODO: [port] ADD BACK AS NEEDED
|
|
|
|
|
|
|
|
// ItemStack stack = event.getItemStack();
|
|
|
|
// if (StackUtil.isValid(stack)) {
|
|
|
|
// //Be da bland
|
|
|
|
// if (ConfigBoolValues.MOST_BLAND_PERSON_EVER.isEnabled()) {
|
|
|
|
// ResourceLocation regName = stack.getItem().getRegistryName();
|
|
|
|
// 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));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (ItemWingsOfTheBats.THE_BAT_BAT.equalsIgnoreCase(stack.getDisplayName()) && stack.getItem() instanceof SwordItem) {
|
|
|
|
// 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");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// //Advanced Item Info
|
|
|
|
// if (event.getFlags().isAdvanced() && StackUtil.isValid(event.getItemStack())) {
|
|
|
|
// if (ConfigBoolValues.CTRL_EXTRA_INFO.isEnabled()) {
|
|
|
|
// if (Screen.hasControlDown()) {
|
|
|
|
// event.getToolTip().add(Help.Trans("tooltip.", ".extraInfo.desc").mergeStyle(TextFormatting.DARK_GRAY).mergeStyle(TextFormatting.ITALIC).append(new StringTextComponent(":")));
|
|
|
|
//
|
|
|
|
// // TODO: [port] come back to this and see if we can re-add it
|
|
|
|
// //OreDict Names
|
|
|
|
// // int[] oreIDs = OreDictionary.getOreIDs(event.getItemStack());
|
|
|
|
// // 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));
|
|
|
|
// // }
|
|
|
|
// // } else {
|
|
|
|
// // event.getToolTip().add(ADVANCED_INFO_TEXT_PRE + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".noOredictNameAvail.desc"));
|
|
|
|
// // }
|
|
|
|
//
|
|
|
|
// //Code Name
|
|
|
|
// 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()));
|
|
|
|
//
|
|
|
|
// //Base Item's Unlocalized Name
|
|
|
|
// String baseName = event.getItemStack().getItem().getTranslationKey();
|
|
|
|
// 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);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// //Metadata
|
|
|
|
// int meta = event.getItemStack().getItemDamage();
|
|
|
|
// int max = event.getItemStack().getMaxDamage();
|
|
|
|
// 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
|
|
|
|
// : ""));
|
|
|
|
//
|
|
|
|
// //Unlocalized Name
|
|
|
|
// String metaName = event.getItemStack().getItem().getTranslationKey(event.getItemStack());
|
|
|
|
// 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);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// //NBT
|
|
|
|
// CompoundNBT compound = event.getItemStack().getTagCompound();
|
|
|
|
// if (compound != null && !compound.isEmpty()) {
|
|
|
|
// event.getToolTip().add(ADVANCED_INFO_HEADER_PRE + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".nbt.desc") + ":");
|
|
|
|
// if (Screen.hasShiftDown()) {
|
|
|
|
// int limit = ConfigIntValues.CTRL_INFO_NBT_CHAR_LIMIT.getValue();
|
|
|
|
// String compoundStrg = compound.toString();
|
|
|
|
// int compoundStrgLength = compoundStrg.length();
|
|
|
|
//
|
|
|
|
// String compoundDisplay;
|
|
|
|
// if (limit > 0 && compoundStrgLength > limit) {
|
|
|
|
// compoundDisplay = compoundStrg.substring(0, limit) + TextFormatting.GRAY + " (" + (compoundStrgLength - limit) + " more characters...)";
|
|
|
|
// } else {
|
|
|
|
// compoundDisplay = compoundStrg;
|
|
|
|
// }
|
|
|
|
// 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") + "]");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// //Disabling Info
|
|
|
|
// event.getToolTip().add(TextFormatting.ITALIC + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".disablingInfo.desc"));
|
|
|
|
//
|
|
|
|
// } 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-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) {
|
2021-02-27 17:22:03 +01:00
|
|
|
Minecraft minecraft = Minecraft.getInstance();
|
2021-08-22 17:09:06 +02:00
|
|
|
if (event.getType() == RenderGameOverlayEvent.ElementType.ALL && minecraft.screen == null) {
|
2021-02-26 22:15:48 +01:00
|
|
|
PlayerEntity player = minecraft.player;
|
2021-02-27 17:22:03 +01:00
|
|
|
if (player == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
RayTraceResult posHit = minecraft.hitResult;
|
|
|
|
FontRenderer font = minecraft.font;
|
|
|
|
ItemStack stack = player.getMainHandItem();
|
2016-07-03 20:57:00 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(stack)) {
|
|
|
|
if (stack.getItem() instanceof IHudDisplay) {
|
2021-02-27 21:24:26 +01:00
|
|
|
((IHudDisplay) stack.getItem()).displayHud(event.getMatrixStack(), minecraft, player, stack, posHit, event.getWindow());
|
2016-07-03 20:57:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-27 17:22:03 +01:00
|
|
|
if (posHit != null && posHit.getType() == RayTraceResult.Type.BLOCK) {
|
|
|
|
BlockRayTraceResult rayCast = (BlockRayTraceResult) posHit;
|
2021-08-22 17:09:06 +02:00
|
|
|
Block blockHit = minecraft.level.getBlockState(rayCast.getBlockPos()).getBlock();
|
|
|
|
TileEntity tileHit = minecraft.level.getBlockEntity(rayCast.getBlockPos());
|
2016-07-03 20:57:00 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (blockHit instanceof IHudDisplay) {
|
2021-02-27 21:24:26 +01:00
|
|
|
((IHudDisplay) blockHit).displayHud(event.getMatrixStack(), minecraft, player, stack, posHit, event.getWindow());
|
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()) {
|
2021-02-26 22:15:48 +01:00
|
|
|
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);
|
2021-08-22 17:09:06 +02:00
|
|
|
font.drawShadow(event.getMatrixStack(), strg, event.getWindow().getGuiScaledWidth() / 2f + 5, event.getWindow().getGuiScaledHeight() / 2f + 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 {
|
2021-08-22 17:09:06 +02:00
|
|
|
expl = TextFormatting.GRAY.toString() + TextFormatting.ITALIC + StringUtil.localizeFormatted("info." + ActuallyAdditions.MODID + ".redstoneMode.invalidItem", StringUtil.localize(ConfigValues.itemRedstoneTorchConfigurator.getDescriptionId() + ".name"));
|
2016-10-19 18:42:07 +02:00
|
|
|
}
|
2021-08-22 17:09:06 +02:00
|
|
|
font.drawShadow(event.getMatrixStack(), expl, event.getWindow().getGuiScaledWidth() / 2f + 5, event.getWindow().getGuiScaledHeight() / 2f + 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;
|
2021-08-22 17:09:06 +02:00
|
|
|
if (!display.needsHoldShift() || player.isShiftKeyDown()) {
|
2019-05-02 09:10:29 +02:00
|
|
|
if (energyDisplay == null) {
|
2016-07-21 18:35:38 +02:00
|
|
|
energyDisplay = new EnergyDisplay(0, 0, null);
|
|
|
|
}
|
2021-08-22 17:09:06 +02:00
|
|
|
energyDisplay.setData(2, event.getWindow().getGuiScaledHeight() - 96, display.getEnergyStorage(), true, true);
|
2016-07-22 00:58:39 +02:00
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
GlStateManager._pushMatrix();
|
|
|
|
GlStateManager._color4f(1F, 1F, 1F, 1F);
|
2021-11-14 00:20:29 +01:00
|
|
|
energyDisplay.draw(event.getMatrixStack());
|
2021-08-22 17:09:06 +02:00
|
|
|
GlStateManager._popMatrix();
|
2016-07-03 20:57:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-04 17:26:50 +02:00
|
|
|
}
|