2018-10-13 20:35:18 +02:00
|
|
|
package de.ellpeck.naturesaura.events;
|
|
|
|
|
2020-09-22 03:17:02 +02:00
|
|
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
2020-01-21 21:04:44 +01:00
|
|
|
import com.mojang.blaze3d.platform.GlStateManager;
|
2020-01-28 18:08:56 +01:00
|
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
2019-01-27 13:57:34 +01:00
|
|
|
import de.ellpeck.naturesaura.Helper;
|
2018-12-04 13:38:46 +01:00
|
|
|
import de.ellpeck.naturesaura.ModConfig;
|
2018-10-13 20:35:18 +02:00
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
2018-11-12 22:04:40 +01:00
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
2018-11-11 13:26:19 +01:00
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
|
|
|
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
|
2018-11-12 01:29:33 +01:00
|
|
|
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
2019-01-28 15:43:21 +01:00
|
|
|
import de.ellpeck.naturesaura.api.render.IVisualizable;
|
2020-05-05 19:43:27 +02:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.*;
|
2020-01-25 19:18:45 +01:00
|
|
|
import de.ellpeck.naturesaura.enchant.ModEnchantment;
|
2020-05-05 19:43:27 +02:00
|
|
|
import de.ellpeck.naturesaura.items.ItemAuraBottle;
|
2020-01-26 01:41:49 +01:00
|
|
|
import de.ellpeck.naturesaura.items.ItemAuraCache;
|
|
|
|
import de.ellpeck.naturesaura.items.ItemRangeVisualizer;
|
2020-01-26 19:26:50 +01:00
|
|
|
import de.ellpeck.naturesaura.items.ModItems;
|
2020-01-22 23:21:52 +01:00
|
|
|
import de.ellpeck.naturesaura.packet.PacketAuraChunk;
|
2018-10-13 20:35:18 +02:00
|
|
|
import de.ellpeck.naturesaura.particles.ParticleHandler;
|
2020-02-21 18:15:37 +01:00
|
|
|
import net.minecraft.block.*;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraft.client.MainWindow;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.client.gui.AbstractGui;
|
|
|
|
import net.minecraft.client.gui.screen.ChatScreen;
|
2020-01-29 14:32:32 +01:00
|
|
|
import net.minecraft.client.renderer.ActiveRenderInfo;
|
2018-10-18 19:08:15 +02:00
|
|
|
import net.minecraft.client.resources.I18n;
|
2020-01-25 19:18:45 +01:00
|
|
|
import net.minecraft.enchantment.Enchantment;
|
|
|
|
import net.minecraft.enchantment.EnchantmentHelper;
|
2019-01-28 15:43:21 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
2018-10-14 17:46:00 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraft.item.Items;
|
2018-10-14 17:46:00 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2020-09-22 03:17:02 +02:00
|
|
|
import net.minecraft.util.IReorderingProcessor;
|
|
|
|
import net.minecraft.util.RegistryKey;
|
2018-10-18 19:08:15 +02:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2019-02-09 21:55:40 +01:00
|
|
|
import net.minecraft.util.Tuple;
|
2020-01-29 14:32:32 +01:00
|
|
|
import net.minecraft.util.math.*;
|
2020-09-22 03:17:02 +02:00
|
|
|
import net.minecraft.util.math.vector.Vector3d;
|
2020-01-25 19:18:45 +01:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
|
|
|
import net.minecraft.util.text.StringTextComponent;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2020-09-22 03:17:02 +02:00
|
|
|
import net.minecraft.util.text.TranslationTextComponent;
|
2019-01-28 15:43:21 +01:00
|
|
|
import net.minecraft.world.World;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.world.biome.BiomeColors;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraft.world.gen.Heightmap;
|
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
2018-10-14 17:46:00 +02:00
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
2019-01-28 17:12:50 +01:00
|
|
|
import net.minecraftforge.common.IPlantable;
|
2019-01-26 00:34:05 +01:00
|
|
|
import net.minecraftforge.energy.EnergyStorage;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraftforge.event.TickEvent;
|
2020-01-25 19:18:45 +01:00
|
|
|
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
2020-03-11 23:14:42 +01:00
|
|
|
import net.minecraftforge.fml.ModList;
|
2018-10-21 12:51:13 +02:00
|
|
|
import org.apache.commons.lang3.mutable.MutableInt;
|
2018-12-04 13:38:46 +01:00
|
|
|
import org.lwjgl.opengl.GL11;
|
2018-10-13 20:35:18 +02:00
|
|
|
|
2019-01-29 16:01:10 +01:00
|
|
|
import java.text.NumberFormat;
|
2020-05-05 19:43:27 +02:00
|
|
|
import java.util.*;
|
2018-10-13 20:35:18 +02:00
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2018-10-13 20:35:18 +02:00
|
|
|
public class ClientEvents {
|
|
|
|
|
2018-10-20 21:19:08 +02:00
|
|
|
public static final ResourceLocation OVERLAYS = new ResourceLocation(NaturesAura.MOD_ID, "textures/gui/overlays.png");
|
2019-03-01 20:51:43 +01:00
|
|
|
public static final ResourceLocation BOOK_GUI = new ResourceLocation(NaturesAura.MOD_ID, "textures/gui/book.png");
|
2020-02-07 15:22:30 +01:00
|
|
|
public static final List<PacketAuraChunk> PENDING_AURA_CHUNKS = new ArrayList<>();
|
2019-02-25 17:15:39 +01:00
|
|
|
private static final ItemStack ITEM_FRAME = new ItemStack(Items.ITEM_FRAME);
|
2020-02-21 18:15:37 +01:00
|
|
|
private static final ItemStack DISPENSER = new ItemStack(Blocks.DISPENSER);
|
2019-02-09 21:55:40 +01:00
|
|
|
private static final Map<ResourceLocation, Tuple<ItemStack, Boolean>> SHOWING_EFFECTS = new HashMap<>();
|
|
|
|
private static ItemStack heldCache = ItemStack.EMPTY;
|
|
|
|
private static ItemStack heldEye = ItemStack.EMPTY;
|
|
|
|
private static ItemStack heldOcular = ItemStack.EMPTY;
|
2018-10-18 19:08:15 +02:00
|
|
|
|
2018-10-13 20:35:18 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public void onDebugRender(RenderGameOverlayEvent.Text event) {
|
2020-01-21 21:04:44 +01:00
|
|
|
Minecraft mc = Minecraft.getInstance();
|
2020-01-24 17:05:41 +01:00
|
|
|
if (mc.gameSettings.showDebugInfo && ModConfig.instance.debugText.get()) {
|
2018-10-13 20:35:18 +02:00
|
|
|
String prefix = TextFormatting.GREEN + "[" + NaturesAura.MOD_NAME + "]" + TextFormatting.RESET + " ";
|
|
|
|
List<String> left = event.getLeft();
|
2020-01-21 21:04:44 +01:00
|
|
|
if (mc.player.isCreative()) {
|
2020-12-04 14:15:34 +01:00
|
|
|
left.add("");
|
2018-11-11 13:26:19 +01:00
|
|
|
MutableInt amount = new MutableInt(IAuraChunk.DEFAULT_AURA);
|
2018-10-26 20:25:21 +02:00
|
|
|
MutableInt spots = new MutableInt();
|
2018-12-04 13:38:46 +01:00
|
|
|
IAuraChunk.getSpotsInArea(mc.world, mc.player.getPosition(), 35, (blockPos, drainSpot) -> {
|
2018-10-26 20:25:21 +02:00
|
|
|
spots.increment();
|
2018-12-02 01:36:41 +01:00
|
|
|
amount.add(drainSpot);
|
2018-12-04 13:38:46 +01:00
|
|
|
});
|
2019-01-29 16:01:10 +01:00
|
|
|
NumberFormat format = NumberFormat.getInstance();
|
2019-02-19 17:23:03 +01:00
|
|
|
left.add(prefix + "A: " + format.format(amount.intValue()) + " (S: " + spots.intValue() + ")");
|
|
|
|
left.add(prefix + "AT: " + IAuraType.forWorld(mc.world).getName());
|
2018-10-26 20:25:21 +02:00
|
|
|
}
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
2020-01-21 21:04:44 +01:00
|
|
|
public void onClientTick(TickEvent.ClientTickEvent event) {
|
2020-01-22 23:21:52 +01:00
|
|
|
if (event.phase != TickEvent.Phase.END) {
|
2019-02-09 21:55:40 +01:00
|
|
|
heldCache = ItemStack.EMPTY;
|
|
|
|
heldEye = ItemStack.EMPTY;
|
|
|
|
heldOcular = ItemStack.EMPTY;
|
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
Minecraft mc = Minecraft.getInstance();
|
2019-01-28 15:43:21 +01:00
|
|
|
if (mc.world == null) {
|
2020-01-26 01:41:49 +01:00
|
|
|
ItemRangeVisualizer.clear();
|
2020-01-22 23:21:52 +01:00
|
|
|
PENDING_AURA_CHUNKS.clear();
|
|
|
|
} else {
|
|
|
|
PENDING_AURA_CHUNKS.removeIf(next -> next.tryHandle(mc.world));
|
|
|
|
|
|
|
|
if (!mc.isGamePaused()) {
|
|
|
|
if (mc.world.getGameTime() % 20 == 0) {
|
2020-01-24 17:05:41 +01:00
|
|
|
int amount = MathHelper.floor(190 * ModConfig.instance.excessParticleAmount.get());
|
2020-01-22 23:21:52 +01:00
|
|
|
for (int i = 0; i < amount; i++) {
|
2020-01-28 18:08:56 +01:00
|
|
|
int x = MathHelper.floor(mc.player.getPosX()) + mc.world.rand.nextInt(64) - 32;
|
|
|
|
int z = MathHelper.floor(mc.player.getPosZ()) + mc.world.rand.nextInt(64) - 32;
|
2020-01-22 23:21:52 +01:00
|
|
|
BlockPos pos = new BlockPos(x, mc.world.getHeight(Heightmap.Type.WORLD_SURFACE, x, z) - 1, z);
|
|
|
|
BlockState state = mc.world.getBlockState(pos);
|
|
|
|
Block block = state.getBlock();
|
2020-10-13 23:37:58 +02:00
|
|
|
if (block instanceof IGrowable || block instanceof IPlantable || block instanceof LeavesBlock || block instanceof MyceliumBlock) {
|
2020-01-22 23:21:52 +01:00
|
|
|
int excess = IAuraChunk.triangulateAuraInArea(mc.world, pos, 45) - IAuraChunk.DEFAULT_AURA;
|
|
|
|
if (excess > 0) {
|
|
|
|
int chance = Math.max(10, 50 - excess / 25000);
|
|
|
|
if (mc.world.rand.nextInt(chance) <= 0)
|
|
|
|
NaturesAuraAPI.instance().spawnMagicParticle(
|
|
|
|
pos.getX() + mc.world.rand.nextFloat(),
|
|
|
|
pos.getY() + 0.5F,
|
|
|
|
pos.getZ() + mc.world.rand.nextFloat(),
|
|
|
|
mc.world.rand.nextGaussian() * 0.01F,
|
|
|
|
mc.world.rand.nextFloat() * 0.025F,
|
|
|
|
mc.world.rand.nextGaussian() * 0.01F,
|
2020-10-13 23:37:58 +02:00
|
|
|
block instanceof MyceliumBlock ? 0x875ca1 : BiomeColors.getGrassColor(mc.world, pos),
|
2020-01-22 23:21:52 +01:00
|
|
|
Math.min(2F, 1F + mc.world.rand.nextFloat() * (excess / 30000F)),
|
|
|
|
Math.min(300, 100 + mc.world.rand.nextInt(excess / 3000 + 1)),
|
|
|
|
0F, false, true);
|
|
|
|
}
|
2019-01-28 17:12:50 +01:00
|
|
|
}
|
2019-01-28 16:56:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 23:21:52 +01:00
|
|
|
if (Helper.isHoldingItem(mc.player, ModItems.RANGE_VISUALIZER) && mc.world.getGameTime() % 5 == 0) {
|
|
|
|
NaturesAuraAPI.IInternalHooks inst = NaturesAuraAPI.instance();
|
|
|
|
inst.setParticleSpawnRange(512);
|
|
|
|
inst.setParticleDepth(false);
|
2020-09-22 15:38:58 +02:00
|
|
|
for (BlockPos pos : ItemRangeVisualizer.VISUALIZED_RAILS.get(mc.world.func_234923_W_().func_240901_a_())) {
|
2020-01-22 23:21:52 +01:00
|
|
|
NaturesAuraAPI.instance().spawnMagicParticle(
|
|
|
|
pos.getX() + mc.world.rand.nextFloat(),
|
|
|
|
pos.getY() + mc.world.rand.nextFloat(),
|
|
|
|
pos.getZ() + mc.world.rand.nextFloat(),
|
|
|
|
0F, 0F, 0F, 0xe0faff, mc.world.rand.nextFloat() * 5 + 1, 100, 0F, false, true);
|
|
|
|
}
|
|
|
|
inst.setParticleDepth(true);
|
|
|
|
inst.setParticleSpawnRange(32);
|
2019-03-20 20:51:24 +01:00
|
|
|
}
|
|
|
|
|
2020-01-26 19:26:50 +01:00
|
|
|
heldCache = Helper.getEquippedItem(s -> s.getItem() instanceof ItemAuraCache, mc.player);
|
|
|
|
heldEye = Helper.getEquippedItem(s -> s.getItem() == ModItems.EYE, mc.player);
|
|
|
|
heldOcular = Helper.getEquippedItem(s -> s.getItem() == ModItems.EYE_IMPROVED, mc.player);
|
2019-03-20 20:51:24 +01:00
|
|
|
|
2020-01-22 23:21:52 +01:00
|
|
|
if (!heldOcular.isEmpty() && mc.world.getGameTime() % 20 == 0) {
|
|
|
|
SHOWING_EFFECTS.clear();
|
|
|
|
Helper.getAuraChunksInArea(mc.world, mc.player.getPosition(), 100,
|
|
|
|
chunk -> chunk.getActiveEffectIcons(mc.player, SHOWING_EFFECTS));
|
|
|
|
}
|
2019-03-20 20:51:24 +01:00
|
|
|
}
|
2019-01-28 15:43:21 +01:00
|
|
|
}
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-14 17:46:00 +02:00
|
|
|
|
2018-12-04 13:38:46 +01:00
|
|
|
@SubscribeEvent
|
|
|
|
public void onWorldRender(RenderWorldLastEvent event) {
|
2020-01-21 21:04:44 +01:00
|
|
|
Minecraft mc = Minecraft.getInstance();
|
2020-01-30 20:35:25 +01:00
|
|
|
|
2020-01-29 14:32:32 +01:00
|
|
|
RenderSystem.pushMatrix();
|
2020-09-22 03:17:02 +02:00
|
|
|
RenderSystem.multMatrix(event.getMatrixStack().getLast().getMatrix());
|
2020-01-29 14:32:32 +01:00
|
|
|
|
|
|
|
ActiveRenderInfo info = mc.gameRenderer.getActiveRenderInfo();
|
2020-09-22 03:17:02 +02:00
|
|
|
Vector3d view = info.getProjectedView();
|
2020-01-29 14:32:32 +01:00
|
|
|
GL11.glTranslated(-view.getX(), -view.getY(), -view.getZ());
|
2019-01-27 13:57:34 +01:00
|
|
|
|
2020-01-24 17:05:41 +01:00
|
|
|
if (mc.gameSettings.showDebugInfo && mc.player.isCreative() && ModConfig.instance.debugWorld.get()) {
|
2019-01-27 13:57:34 +01:00
|
|
|
Map<BlockPos, Integer> spots = new HashMap<>();
|
2018-12-04 13:38:46 +01:00
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
|
|
|
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
|
|
|
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
|
|
|
GL11.glEnable(GL11.GL_BLEND);
|
|
|
|
GL11.glBegin(GL11.GL_QUADS);
|
|
|
|
IAuraChunk.getSpotsInArea(mc.world, mc.player.getPosition(), 64, (pos, spot) -> {
|
|
|
|
spots.put(pos, spot);
|
|
|
|
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.color4f(spot > 0 ? 0F : 1F, spot > 0 ? 1F : 0F, 0F, 0.35F);
|
2019-01-27 13:57:34 +01:00
|
|
|
Helper.renderWeirdBox(pos.getX(), pos.getY(), pos.getZ(), 1, 1, 1);
|
2018-12-04 13:38:46 +01:00
|
|
|
});
|
|
|
|
GL11.glEnd();
|
|
|
|
GL11.glPopAttrib();
|
|
|
|
|
|
|
|
float scale = 0.03F;
|
2019-01-29 16:01:10 +01:00
|
|
|
NumberFormat format = NumberFormat.getInstance();
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.scalef(scale, scale, scale);
|
2018-12-04 13:38:46 +01:00
|
|
|
for (Map.Entry<BlockPos, Integer> spot : spots.entrySet()) {
|
|
|
|
BlockPos pos = spot.getKey();
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.pushMatrix();
|
2020-01-29 18:18:41 +01:00
|
|
|
RenderSystem.translated((pos.getX() + 0.1) / scale, (pos.getY() + 1.001) / scale, (pos.getZ() + 0.1) / scale);
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.rotatef(90F, 1F, 0F, 0F);
|
|
|
|
RenderSystem.scalef(0.65F, 0.65F, 0.65F);
|
2020-09-28 17:32:13 +02:00
|
|
|
mc.fontRenderer.drawString(new MatrixStack(), format.format(spot.getValue()), 0, 0, 0);
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.popMatrix();
|
2018-12-04 13:38:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
2019-01-27 13:57:34 +01:00
|
|
|
|
2019-03-20 20:51:24 +01:00
|
|
|
if (Helper.isHoldingItem(mc.player, ModItems.RANGE_VISUALIZER)) {
|
2020-09-22 03:17:02 +02:00
|
|
|
RegistryKey<World> dim = mc.world.func_234923_W_();
|
2019-03-20 20:51:24 +01:00
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glDisable(GL11.GL_CULL_FACE);
|
|
|
|
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
|
|
|
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
|
|
|
GL11.glEnable(GL11.GL_BLEND);
|
|
|
|
GL11.glBegin(GL11.GL_QUADS);
|
2020-09-22 15:38:58 +02:00
|
|
|
for (BlockPos pos : ItemRangeVisualizer.VISUALIZED_BLOCKS.get(dim.func_240901_a_())) {
|
2019-03-20 20:51:24 +01:00
|
|
|
if (!mc.world.isBlockLoaded(pos))
|
|
|
|
continue;
|
2019-10-20 22:30:49 +02:00
|
|
|
BlockState state = mc.world.getBlockState(pos);
|
2019-03-20 20:51:24 +01:00
|
|
|
Block block = state.getBlock();
|
|
|
|
if (!(block instanceof IVisualizable))
|
|
|
|
continue;
|
|
|
|
this.renderVisualize((IVisualizable) block, mc.world, pos);
|
|
|
|
}
|
2020-09-22 15:38:58 +02:00
|
|
|
for (Entity entity : ItemRangeVisualizer.VISUALIZED_ENTITIES.get(dim.func_240901_a_())) {
|
2020-01-21 21:04:44 +01:00
|
|
|
if (!entity.isAlive() || !(entity instanceof IVisualizable))
|
2019-03-20 20:51:24 +01:00
|
|
|
continue;
|
|
|
|
this.renderVisualize((IVisualizable) entity, mc.world, entity.getPosition());
|
2019-01-27 13:57:34 +01:00
|
|
|
}
|
2019-03-20 20:51:24 +01:00
|
|
|
GL11.glEnd();
|
|
|
|
GL11.glPopAttrib();
|
|
|
|
GL11.glEnable(GL11.GL_CULL_FACE);
|
|
|
|
GL11.glPopMatrix();
|
2019-01-27 13:57:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GL11.glPopMatrix();
|
2018-12-04 13:38:46 +01:00
|
|
|
}
|
|
|
|
|
2020-01-22 23:21:52 +01:00
|
|
|
private void renderVisualize(IVisualizable visualize, World
|
|
|
|
world, BlockPos pos) {
|
2019-01-28 15:43:21 +01:00
|
|
|
AxisAlignedBB box = visualize.getVisualizationBounds(world, pos);
|
|
|
|
if (box == null)
|
|
|
|
return;
|
|
|
|
box = box.grow(0.05F);
|
|
|
|
int color = visualize.getVisualizationColor(world, pos);
|
2020-01-29 18:18:41 +01:00
|
|
|
RenderSystem.color4f((color >> 16 & 255) / 255F, (color >> 8 & 255) / 255F, (color & 255) / 255F, 0.5F);
|
2019-01-28 15:43:21 +01:00
|
|
|
Helper.renderWeirdBox(box.minX, box.minY, box.minZ, box.maxX - box.minX, box.maxY - box.minY, box.maxZ - box.minZ);
|
|
|
|
}
|
|
|
|
|
2018-10-14 17:46:00 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public void onOverlayRender(RenderGameOverlayEvent.Post event) {
|
2020-01-21 21:04:44 +01:00
|
|
|
Minecraft mc = Minecraft.getInstance();
|
2020-09-22 03:17:02 +02:00
|
|
|
MatrixStack stack = event.getMatrixStack();
|
2018-10-20 21:19:08 +02:00
|
|
|
if (event.getType() == ElementType.ALL) {
|
2020-01-21 21:04:44 +01:00
|
|
|
MainWindow res = event.getWindow();
|
2018-10-14 17:46:00 +02:00
|
|
|
if (mc.player != null) {
|
2019-02-09 21:55:40 +01:00
|
|
|
if (!heldCache.isEmpty()) {
|
2020-01-21 21:04:44 +01:00
|
|
|
IAuraContainer container = heldCache.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null);
|
2018-11-02 21:10:53 +01:00
|
|
|
int width = MathHelper.ceil(container.getStoredAura() / (float) container.getMaxAura() * 80);
|
2020-03-11 23:32:37 +01:00
|
|
|
|
|
|
|
int conf = ModConfig.instance.cacheBarLocation.get();
|
|
|
|
int x = res.getScaledWidth() / 2 + (conf == 0 ? -173 - (mc.player.getHeldItemOffhand().isEmpty() ? 0 : 29) : 93);
|
2018-11-02 21:10:53 +01:00
|
|
|
int y = res.getScaledHeight() - 8;
|
|
|
|
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.pushMatrix();
|
2018-11-02 21:10:53 +01:00
|
|
|
|
|
|
|
int color = container.getAuraColor();
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.color4f((color >> 16 & 255) / 255F, (color >> 8 & 255) / 255F, (color & 255) / 255F, 1);
|
2018-11-02 21:10:53 +01:00
|
|
|
mc.getTextureManager().bindTexture(OVERLAYS);
|
|
|
|
if (width < 80)
|
2020-09-22 03:17:02 +02:00
|
|
|
AbstractGui.blit(stack, x + width, y, width, 0, 80 - width, 6, 256, 256);
|
2018-11-02 21:10:53 +01:00
|
|
|
if (width > 0)
|
2020-09-22 03:17:02 +02:00
|
|
|
AbstractGui.blit(stack, x, y, 0, 6, width, 6, 256, 256);
|
2018-11-02 21:10:53 +01:00
|
|
|
|
|
|
|
float scale = 0.75F;
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.scalef(scale, scale, scale);
|
2020-09-22 03:17:02 +02:00
|
|
|
String s = heldCache.getDisplayName().getString();
|
|
|
|
mc.fontRenderer.drawStringWithShadow(stack, s, conf == 1 ? x / scale : (x + 80) / scale - mc.fontRenderer.getStringWidth(s), (y - 7) / scale, color);
|
2018-11-02 21:10:53 +01:00
|
|
|
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.color4f(1F, 1F, 1F, 1);
|
|
|
|
RenderSystem.popMatrix();
|
2018-11-02 21:10:53 +01:00
|
|
|
}
|
2018-10-20 21:19:08 +02:00
|
|
|
|
2019-02-09 21:55:40 +01:00
|
|
|
if (!heldEye.isEmpty() || !heldOcular.isEmpty()) {
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.pushMatrix();
|
2018-11-02 21:10:53 +01:00
|
|
|
mc.getTextureManager().bindTexture(OVERLAYS);
|
|
|
|
|
2020-01-24 17:05:41 +01:00
|
|
|
int conf = ModConfig.instance.auraBarLocation.get();
|
2019-10-20 22:30:49 +02:00
|
|
|
if (!mc.gameSettings.showDebugInfo && (conf != 2 || !(mc.currentScreen instanceof ChatScreen))) {
|
2020-02-26 11:07:53 +01:00
|
|
|
int color = IAuraType.forWorld(mc.world).getColor();
|
|
|
|
RenderSystem.color4f((color >> 16 & 0xFF) / 255F, (color >> 8 & 0xFF) / 255F, (color & 0xFF) / 255F, 1);
|
2018-12-02 18:33:04 +01:00
|
|
|
|
2018-12-05 11:21:08 +01:00
|
|
|
int totalAmount = IAuraChunk.triangulateAuraInArea(mc.world, mc.player.getPosition(), 35);
|
|
|
|
float totalPercentage = totalAmount / (IAuraChunk.DEFAULT_AURA * 2F);
|
2019-02-05 11:49:14 +01:00
|
|
|
String text = I18n.format("info." + NaturesAura.MOD_ID + ".aura_in_area");
|
|
|
|
float textScale = 0.75F;
|
|
|
|
|
|
|
|
int startX = conf % 2 == 0 ? 3 : res.getScaledWidth() - 3 - 6;
|
2019-02-09 21:55:40 +01:00
|
|
|
int startY = conf < 2 ? 10 : (!heldOcular.isEmpty() && (totalPercentage > 1F || totalPercentage < 0) ? -26 : 0) + res.getScaledHeight() - 60;
|
2019-02-05 11:49:14 +01:00
|
|
|
float plusOffX = conf % 2 == 0 ? 7 : -1 - 6;
|
|
|
|
float textX = conf % 2 == 0 ? 3 : res.getScaledWidth() - 3 - mc.fontRenderer.getStringWidth(text) * textScale;
|
|
|
|
float textY = conf < 2 ? 3 : res.getScaledHeight() - 3 - 6;
|
2018-12-02 18:33:04 +01:00
|
|
|
|
2018-11-04 12:43:22 +01:00
|
|
|
int tHeight = MathHelper.ceil(MathHelper.clamp(totalPercentage, 0F, 1F) * 50);
|
2019-02-09 21:55:40 +01:00
|
|
|
int y = !heldOcular.isEmpty() && totalPercentage > 1F ? startY + 26 : startY;
|
2018-11-04 12:43:22 +01:00
|
|
|
if (tHeight < 50)
|
2020-09-22 03:17:02 +02:00
|
|
|
AbstractGui.blit(stack, startX, y, 6, 12, 6, 50 - tHeight, 256, 256);
|
2018-11-04 12:43:22 +01:00
|
|
|
if (tHeight > 0)
|
2020-09-22 03:17:02 +02:00
|
|
|
AbstractGui.blit(stack, startX, y + 50 - tHeight, 0, 12 + 50 - tHeight, 6, tHeight, 256, 256);
|
2018-12-25 19:38:25 +01:00
|
|
|
|
2019-02-09 21:55:40 +01:00
|
|
|
if (!heldOcular.isEmpty()) {
|
2018-12-25 19:38:25 +01:00
|
|
|
int topHeight = MathHelper.ceil(MathHelper.clamp((totalPercentage - 1F) * 2F, 0F, 1F) * 25);
|
2018-12-26 12:10:41 +01:00
|
|
|
if (topHeight > 0) {
|
|
|
|
if (topHeight < 25)
|
2020-09-22 03:17:02 +02:00
|
|
|
AbstractGui.blit(stack, startX, startY, 18, 12, 6, 25 - topHeight, 256, 256);
|
|
|
|
AbstractGui.blit(stack, startX, startY + 25 - topHeight, 12, 12 + 25 - topHeight, 6, topHeight, 256, 256);
|
2018-12-26 12:10:41 +01:00
|
|
|
}
|
2019-02-05 11:49:14 +01:00
|
|
|
int bottomHeight = MathHelper.floor(MathHelper.clamp((totalPercentage + 1F) * 2F - 1F, 0F, 1F) * 25);
|
2018-12-26 12:10:41 +01:00
|
|
|
if (bottomHeight < 25) {
|
2020-09-22 03:17:02 +02:00
|
|
|
AbstractGui.blit(stack, startX, startY + 51, 18, 12, 6, 25 - bottomHeight, 256, 256);
|
2018-12-26 12:10:41 +01:00
|
|
|
if (bottomHeight > 0)
|
2020-09-22 03:17:02 +02:00
|
|
|
AbstractGui.blit(stack, startX, startY + 51 + 25 - bottomHeight, 12, 12 + 25 - bottomHeight, 6, bottomHeight, 256, 256);
|
2018-12-26 12:10:41 +01:00
|
|
|
}
|
2018-12-25 19:38:25 +01:00
|
|
|
}
|
2018-11-04 12:43:22 +01:00
|
|
|
|
2019-02-09 21:55:40 +01:00
|
|
|
if (totalPercentage > (heldOcular.isEmpty() ? 1F : 1.5F))
|
2020-09-22 03:17:02 +02:00
|
|
|
mc.fontRenderer.drawStringWithShadow(stack, "+", startX + plusOffX, startY - 0.5F, color);
|
2019-02-09 21:55:40 +01:00
|
|
|
if (totalPercentage < (heldOcular.isEmpty() ? 0F : -0.5F))
|
2020-09-22 03:17:02 +02:00
|
|
|
mc.fontRenderer.drawStringWithShadow(stack, "-", startX + plusOffX, startY - 0.5F + (heldOcular.isEmpty() ? 44 : 70), color);
|
2018-11-04 12:43:22 +01:00
|
|
|
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.pushMatrix();
|
|
|
|
RenderSystem.scalef(textScale, textScale, textScale);
|
2020-09-22 03:17:02 +02:00
|
|
|
mc.fontRenderer.drawStringWithShadow(stack, text, textX / textScale, textY / textScale, color);
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.popMatrix();
|
2019-02-09 21:55:40 +01:00
|
|
|
|
|
|
|
if (!heldOcular.isEmpty()) {
|
|
|
|
float scale = 0.75F;
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.pushMatrix();
|
|
|
|
RenderSystem.scalef(scale, scale, scale);
|
2019-02-10 17:15:05 +01:00
|
|
|
int stackX = conf % 2 == 0 ? 10 : res.getScaledWidth() - 22;
|
|
|
|
int stackY = conf < 2 ? 15 : res.getScaledHeight() - 55;
|
2019-02-09 21:55:40 +01:00
|
|
|
for (Tuple<ItemStack, Boolean> effect : SHOWING_EFFECTS.values()) {
|
2019-02-10 17:15:05 +01:00
|
|
|
int theX = (int) (stackX / scale);
|
2019-02-09 21:55:40 +01:00
|
|
|
int theY = (int) (stackY / scale);
|
2020-09-22 03:17:02 +02:00
|
|
|
ItemStack itemStack = effect.getA();
|
|
|
|
Helper.renderItemInGui(itemStack, theX, theY, 1F);
|
2020-01-21 21:04:44 +01:00
|
|
|
if (effect.getB()) {
|
|
|
|
GlStateManager.disableDepthTest();
|
2019-02-09 21:55:40 +01:00
|
|
|
mc.getTextureManager().bindTexture(OVERLAYS);
|
2020-09-22 03:17:02 +02:00
|
|
|
AbstractGui.blit(stack, theX, theY, 240, 0, 16, 16, 256, 256);
|
2020-01-21 21:04:44 +01:00
|
|
|
GlStateManager.enableDepthTest();
|
2019-02-09 21:55:40 +01:00
|
|
|
}
|
|
|
|
stackY += 8;
|
|
|
|
}
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.popMatrix();
|
2019-02-09 21:55:40 +01:00
|
|
|
}
|
2018-11-04 12:43:22 +01:00
|
|
|
}
|
2018-11-02 21:10:53 +01:00
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
if (mc.objectMouseOver instanceof BlockRayTraceResult) {
|
|
|
|
BlockPos pos = ((BlockRayTraceResult) mc.objectMouseOver).getPos();
|
2018-11-02 21:10:53 +01:00
|
|
|
if (pos != null) {
|
|
|
|
TileEntity tile = mc.world.getTileEntity(pos);
|
2020-01-21 21:04:44 +01:00
|
|
|
IAuraContainer container;
|
2020-02-21 18:15:37 +01:00
|
|
|
int x = res.getScaledWidth() / 2;
|
|
|
|
int y = res.getScaledHeight() / 2;
|
2020-01-21 21:04:44 +01:00
|
|
|
if (tile != null && (container = tile.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null)) != null) {
|
2019-10-20 22:30:49 +02:00
|
|
|
BlockState state = mc.world.getBlockState(pos);
|
2018-11-02 21:10:53 +01:00
|
|
|
ItemStack blockStack = state.getBlock().getPickBlock(state, mc.objectMouseOver, mc.world, pos, mc.player);
|
2020-09-22 15:38:58 +02:00
|
|
|
this.drawContainerInfo(stack, container.getStoredAura(), container.getMaxAura(), container.getAuraColor(),
|
2020-09-22 03:17:02 +02:00
|
|
|
mc, res, 35, blockStack.getDisplayName().getString(), null);
|
2018-11-02 21:10:53 +01:00
|
|
|
|
|
|
|
if (tile instanceof TileEntityNatureAltar) {
|
2020-10-19 21:26:32 +02:00
|
|
|
ItemStack tileStack = ((TileEntityNatureAltar) tile).getItemHandler().getStackInSlot(0);
|
2020-01-21 21:04:44 +01:00
|
|
|
if (!tileStack.isEmpty()) {
|
|
|
|
IAuraContainer stackCont = tileStack.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null);
|
|
|
|
if (stackCont != null) {
|
2020-09-22 15:38:58 +02:00
|
|
|
this.drawContainerInfo(stack, stackCont.getStoredAura(), stackCont.getMaxAura(), stackCont.getAuraColor(),
|
2020-09-22 03:17:02 +02:00
|
|
|
mc, res, 55, tileStack.getDisplayName().getString(), null);
|
2020-01-21 21:04:44 +01:00
|
|
|
}
|
2018-11-02 21:10:53 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-26 00:34:05 +01:00
|
|
|
} else if (tile instanceof TileEntityRFConverter) {
|
|
|
|
EnergyStorage storage = ((TileEntityRFConverter) tile).storage;
|
2020-09-22 15:38:58 +02:00
|
|
|
this.drawContainerInfo(stack, storage.getEnergyStored(), storage.getMaxEnergyStored(), 0xcc4916,
|
2019-01-26 00:34:05 +01:00
|
|
|
mc, res, 35, I18n.format("tile.naturesaura.rf_converter.name"),
|
|
|
|
storage.getEnergyStored() + " / " + storage.getMaxEnergyStored() + " RF");
|
2019-01-30 16:03:41 +01:00
|
|
|
} else if (tile instanceof TileEntityGratedChute) {
|
2019-02-25 17:15:39 +01:00
|
|
|
TileEntityGratedChute chute = (TileEntityGratedChute) tile;
|
2020-10-19 21:26:32 +02:00
|
|
|
ItemStack itemStack = chute.getItemHandler().getStackInSlot(0);
|
2019-01-30 16:03:41 +01:00
|
|
|
|
2020-09-22 03:17:02 +02:00
|
|
|
if (itemStack.isEmpty())
|
|
|
|
mc.fontRenderer.drawStringWithShadow(stack,
|
2019-01-30 16:03:41 +01:00
|
|
|
TextFormatting.GRAY.toString() + TextFormatting.ITALIC + I18n.format("info.naturesaura.empty"),
|
2020-01-21 21:04:44 +01:00
|
|
|
x + 5, y - 11, 0xFFFFFF);
|
2019-01-30 16:03:41 +01:00
|
|
|
else
|
2020-09-22 03:17:02 +02:00
|
|
|
Helper.renderItemInGui(itemStack, x + 2, y - 18, 1F);
|
2019-02-25 17:15:39 +01:00
|
|
|
|
|
|
|
Helper.renderItemInGui(ITEM_FRAME, x - 24, y - 24, 1F);
|
|
|
|
mc.getTextureManager().bindTexture(OVERLAYS);
|
|
|
|
int u = chute.isBlacklist ? 240 : 224;
|
2020-01-21 21:04:44 +01:00
|
|
|
GlStateManager.disableDepthTest();
|
2020-09-22 03:17:02 +02:00
|
|
|
AbstractGui.blit(stack, x - 18, y - 18, u, 0, 16, 16, 256, 256);
|
2020-01-21 21:04:44 +01:00
|
|
|
GlStateManager.enableDepthTest();
|
2020-02-21 18:15:37 +01:00
|
|
|
} else if (tile instanceof TileEntityItemDistributor) {
|
|
|
|
TileEntityItemDistributor distributor = (TileEntityItemDistributor) tile;
|
|
|
|
Helper.renderItemInGui(DISPENSER, x - 24, y - 24, 1F);
|
|
|
|
mc.getTextureManager().bindTexture(OVERLAYS);
|
|
|
|
int u = !distributor.isRandomMode ? 240 : 224;
|
|
|
|
GlStateManager.disableDepthTest();
|
2020-09-22 03:17:02 +02:00
|
|
|
AbstractGui.blit(stack, x - 18, y - 18, u, 0, 16, 16, 256, 256);
|
2020-02-21 18:15:37 +01:00
|
|
|
GlStateManager.enableDepthTest();
|
2020-05-05 19:43:27 +02:00
|
|
|
} else if (tile instanceof TileEntityAuraTimer) {
|
|
|
|
TileEntityAuraTimer timer = (TileEntityAuraTimer) tile;
|
2020-10-19 21:26:32 +02:00
|
|
|
ItemStack itemStack = timer.getItemHandler().getStackInSlot(0);
|
2020-09-22 03:17:02 +02:00
|
|
|
if (!itemStack.isEmpty()) {
|
|
|
|
Helper.renderItemInGui(itemStack, x - 20, y - 20, 1);
|
2020-09-22 15:38:58 +02:00
|
|
|
mc.fontRenderer.drawStringWithShadow(stack, TextFormatting.GRAY + this.createTimeString(timer.getTotalTime()), x + 5, y - 11, 0xFFFFFF);
|
|
|
|
mc.fontRenderer.drawStringWithShadow(stack, TextFormatting.GRAY + I18n.format("info.naturesaura.remaining", this.createTimeString(timer.getTimeLeft())), x + 5, y + 3, 0xFFFFFF);
|
2020-05-05 19:43:27 +02:00
|
|
|
}
|
2018-11-02 21:10:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-20 21:19:08 +02:00
|
|
|
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.color4f(1F, 1F, 1F, 1);
|
|
|
|
RenderSystem.popMatrix();
|
2018-10-14 17:46:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-20 21:19:08 +02:00
|
|
|
|
2020-05-05 19:43:27 +02:00
|
|
|
private String createTimeString(int totalTicks) {
|
|
|
|
int ticks = totalTicks % 20;
|
|
|
|
int seconds = totalTicks / 20 % 60;
|
|
|
|
int minutes = totalTicks / 20 / 60 % 60;
|
|
|
|
int hours = totalTicks / 20 / 60 / 60;
|
|
|
|
return String.format("%02d:%02d:%02d.%02d", hours, minutes, seconds, ticks);
|
|
|
|
}
|
|
|
|
|
2020-09-22 03:17:02 +02:00
|
|
|
private void drawContainerInfo(MatrixStack stack, int stored, int max, int color, Minecraft mc, MainWindow res, int yOffset, String name, String textBelow) {
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.color3f((color >> 16 & 255) / 255F, (color >> 8 & 255) / 255F, (color & 255) / 255F);
|
2018-10-20 21:19:08 +02:00
|
|
|
|
|
|
|
int x = res.getScaledWidth() / 2 - 40;
|
|
|
|
int y = res.getScaledHeight() / 2 + yOffset;
|
2019-01-26 00:34:05 +01:00
|
|
|
int width = MathHelper.ceil(stored / (float) max * 80);
|
2018-10-20 21:19:08 +02:00
|
|
|
|
|
|
|
mc.getTextureManager().bindTexture(OVERLAYS);
|
|
|
|
if (width < 80)
|
2020-09-22 15:38:58 +02:00
|
|
|
AbstractGui.blit(stack, x + width, y, width, 0, 80 - width, 6, 256, 256);
|
2018-10-20 21:19:08 +02:00
|
|
|
if (width > 0)
|
2020-09-22 15:38:58 +02:00
|
|
|
AbstractGui.blit(stack, x, y, 0, 6, width, 6, 256, 256);
|
2018-10-20 21:19:08 +02:00
|
|
|
|
2020-09-22 15:38:58 +02:00
|
|
|
mc.fontRenderer.drawStringWithShadow(stack, name, x + 40 - mc.fontRenderer.getStringWidth(name) / 2F, y - 9, color);
|
2019-01-26 00:34:05 +01:00
|
|
|
|
|
|
|
if (textBelow != null)
|
2020-09-22 15:38:58 +02:00
|
|
|
mc.fontRenderer.drawStringWithShadow(stack, textBelow, x + 40 - mc.fontRenderer.getStringWidth(textBelow) / 2F, y + 7, color);
|
2018-10-20 21:19:08 +02:00
|
|
|
}
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|