2019-09-03 08:34:02 +02:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
2019-09-14 18:21:30 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2020-03-29 06:07:49 +02:00
|
|
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
2020-05-23 14:02:38 +02:00
|
|
|
import com.simibubi.create.content.contraptions.KineticDebugger;
|
|
|
|
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
|
|
|
import com.simibubi.create.content.contraptions.components.turntable.TurntableHandler;
|
|
|
|
import com.simibubi.create.foundation.config.AllConfigs;
|
2019-09-03 08:34:02 +02:00
|
|
|
import com.simibubi.create.foundation.gui.ScreenOpener;
|
2019-12-09 14:58:12 +01:00
|
|
|
import com.simibubi.create.foundation.item.TooltipHelper;
|
2020-06-03 22:04:05 +02:00
|
|
|
import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer;
|
2020-05-23 14:02:38 +02:00
|
|
|
import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringHandler;
|
|
|
|
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueHandler;
|
2019-10-29 19:02:20 +01:00
|
|
|
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
2019-09-03 08:34:02 +02:00
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
2020-04-05 03:54:24 +02:00
|
|
|
import net.minecraft.client.renderer.ActiveRenderInfo;
|
2020-03-29 06:07:49 +02:00
|
|
|
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
2020-03-29 20:21:22 +02:00
|
|
|
import net.minecraft.client.renderer.texture.OverlayTexture;
|
2019-09-14 18:21:30 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2020-04-05 03:54:24 +02:00
|
|
|
import net.minecraft.util.math.Vec3d;
|
2019-09-14 18:21:30 +02:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.client.event.InputEvent.KeyInputEvent;
|
|
|
|
import net.minecraftforge.client.event.InputEvent.MouseInputEvent;
|
2019-09-03 23:03:52 +02:00
|
|
|
import net.minecraftforge.client.event.InputEvent.MouseScrollEvent;
|
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
|
2019-09-03 23:03:52 +02:00
|
|
|
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.event.TickEvent.ClientTickEvent;
|
|
|
|
import net.minecraftforge.event.TickEvent.Phase;
|
|
|
|
import net.minecraftforge.event.TickEvent.RenderTickEvent;
|
2019-09-14 18:21:30 +02:00
|
|
|
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
|
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
|
|
|
|
|
|
|
@EventBusSubscriber(value = Dist.CLIENT)
|
|
|
|
public class ClientEvents {
|
|
|
|
|
2019-09-14 18:21:30 +02:00
|
|
|
private static final String itemPrefix = "item." + Create.ID;
|
|
|
|
private static final String blockPrefix = "block." + Create.ID;
|
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onTick(ClientTickEvent event) {
|
|
|
|
if (event.phase == Phase.START)
|
|
|
|
return;
|
2019-11-07 11:30:29 +01:00
|
|
|
|
2019-09-22 20:23:26 +02:00
|
|
|
AnimationTickHolder.tick();
|
2019-11-07 11:30:29 +01:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
if (!isGameActive())
|
|
|
|
return;
|
|
|
|
|
2019-11-07 11:30:29 +01:00
|
|
|
if (!KineticDebugger.isActive() && KineticTileEntityRenderer.rainbowMode) {
|
|
|
|
KineticTileEntityRenderer.rainbowMode = false;
|
2019-11-23 22:17:37 +01:00
|
|
|
CreateClient.bufferCache.invalidate();
|
2019-11-07 11:30:29 +01:00
|
|
|
}
|
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
ScreenOpener.tick();
|
|
|
|
CreateClient.gameTick();
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onRenderWorld(RenderWorldLastEvent event) {
|
2020-03-29 06:07:49 +02:00
|
|
|
MatrixStack ms = event.getMatrixStack();
|
2020-04-05 03:54:24 +02:00
|
|
|
ActiveRenderInfo info = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
|
|
|
|
Vec3d view = info.getProjectedView();
|
2020-05-15 17:13:38 +02:00
|
|
|
|
2020-04-05 03:54:24 +02:00
|
|
|
ms.push();
|
|
|
|
ms.translate(-view.getX(), -view.getY(), -view.getZ());
|
2020-06-03 22:04:05 +02:00
|
|
|
|
|
|
|
SuperRenderTypeBuffer buffer = SuperRenderTypeBuffer.getInstance();
|
2020-05-28 01:29:26 +02:00
|
|
|
CreateClient.schematicHandler.render(ms, buffer);
|
2020-05-15 17:13:38 +02:00
|
|
|
CreateClient.outliner.renderOutlines(ms, buffer);
|
2020-04-05 03:54:24 +02:00
|
|
|
buffer.draw();
|
2020-06-03 22:04:05 +02:00
|
|
|
|
|
|
|
ms.pop();
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onRenderOverlay(RenderGameOverlayEvent.Post event) {
|
|
|
|
if (event.getType() != ElementType.HOTBAR)
|
|
|
|
return;
|
|
|
|
|
2020-05-15 17:13:38 +02:00
|
|
|
onRenderHotbar(new MatrixStack(), Minecraft.getInstance()
|
|
|
|
.getBufferBuilders()
|
|
|
|
.getEntityVertexConsumers(), 0xF000F0, OverlayTexture.DEFAULT_UV);
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|
|
|
|
|
2020-03-29 20:21:22 +02:00
|
|
|
public static void onRenderHotbar(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {
|
|
|
|
CreateClient.schematicHandler.renderOverlay(ms, buffer, light, overlay);
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onKeyInput(KeyInputEvent event) {
|
|
|
|
int key = event.getKey();
|
|
|
|
boolean pressed = !(event.getAction() == 0);
|
|
|
|
|
|
|
|
if (Minecraft.getInstance().currentScreen != null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CreateClient.schematicHandler.onKeyInput(key, pressed);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
2019-09-03 23:03:52 +02:00
|
|
|
public static void onMouseScrolled(MouseScrollEvent event) {
|
|
|
|
if (Minecraft.getInstance().currentScreen != null)
|
2019-09-03 08:34:02 +02:00
|
|
|
return;
|
2019-09-07 13:12:12 +02:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
double delta = event.getScrollDelta();
|
|
|
|
boolean cancelled = CreateClient.schematicHandler.mouseScrolled(delta)
|
2020-05-15 17:13:38 +02:00
|
|
|
|| CreateClient.schematicAndQuillHandler.mouseScrolled(delta) || FilteringHandler.onScroll(delta)
|
|
|
|
|| ScrollValueHandler.onScroll(delta);
|
2019-09-03 08:34:02 +02:00
|
|
|
event.setCanceled(cancelled);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onMouseInput(MouseInputEvent event) {
|
|
|
|
if (Minecraft.getInstance().currentScreen != null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int button = event.getButton();
|
|
|
|
boolean pressed = !(event.getAction() == 0);
|
|
|
|
|
|
|
|
CreateClient.schematicHandler.onMouseInput(button, pressed);
|
|
|
|
CreateClient.schematicAndQuillHandler.onMouseInput(button, pressed);
|
|
|
|
}
|
|
|
|
|
2019-09-14 18:21:30 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void addToItemTooltip(ItemTooltipEvent event) {
|
2020-02-07 19:25:38 +01:00
|
|
|
if (!AllConfigs.CLIENT.tooltips.get())
|
2019-09-18 11:16:57 +02:00
|
|
|
return;
|
2020-03-21 18:32:53 +01:00
|
|
|
if (Minecraft.getInstance().player == null)
|
|
|
|
return;
|
2019-11-07 11:30:29 +01:00
|
|
|
|
2019-09-14 18:21:30 +02:00
|
|
|
ItemStack stack = event.getItemStack();
|
2020-05-15 17:13:38 +02:00
|
|
|
String translationKey = stack.getItem()
|
|
|
|
.getTranslationKey(stack);
|
2019-09-14 18:21:30 +02:00
|
|
|
if (!translationKey.startsWith(itemPrefix) && !translationKey.startsWith(blockPrefix))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (TooltipHelper.hasTooltip(stack)) {
|
2019-12-09 14:58:12 +01:00
|
|
|
List<ITextComponent> itemTooltip = event.getToolTip();
|
2019-09-14 18:21:30 +02:00
|
|
|
List<ITextComponent> toolTip = new ArrayList<>();
|
2019-12-09 14:58:12 +01:00
|
|
|
toolTip.add(itemTooltip.remove(0));
|
2020-05-15 17:13:38 +02:00
|
|
|
TooltipHelper.getTooltip(stack)
|
|
|
|
.addInformation(toolTip);
|
2019-12-09 14:58:12 +01:00
|
|
|
itemTooltip.addAll(0, toolTip);
|
2019-09-14 18:21:30 +02:00
|
|
|
}
|
2020-02-18 15:08:45 +01:00
|
|
|
|
2019-09-14 18:21:30 +02:00
|
|
|
}
|
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onRenderTick(RenderTickEvent event) {
|
|
|
|
if (!isGameActive())
|
|
|
|
return;
|
2019-09-07 13:12:12 +02:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
TurntableHandler.gameRenderTick();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static boolean isGameActive() {
|
|
|
|
return !(Minecraft.getInstance().world == null || Minecraft.getInstance().player == null);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|