Create/src/main/java/com/simibubi/create/events/ClientEvents.java

177 lines
6.9 KiB
Java
Raw Normal View History

package com.simibubi.create.events;
import java.util.ArrayList;
import java.util.List;
2020-03-29 06:07:49 +02:00
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.Create;
import com.simibubi.create.CreateClient;
2020-05-23 14:02:38 +02:00
import com.simibubi.create.content.contraptions.KineticDebugger;
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionCollider;
import com.simibubi.create.content.contraptions.components.structureMovement.chassis.ChassisRangeDisplay;
import com.simibubi.create.content.contraptions.components.structureMovement.train.ClientMinecartCouplingHandler;
import com.simibubi.create.content.contraptions.components.structureMovement.train.MinecartCouplingHandler;
2020-05-23 14:02:38 +02:00
import com.simibubi.create.content.contraptions.components.turntable.TurntableHandler;
import com.simibubi.create.content.contraptions.relays.belt.item.BeltConnectorHandler;
import com.simibubi.create.content.curiosities.tools.ExtendoGripRenderHandler;
import com.simibubi.create.content.curiosities.zapper.ZapperRenderHandler;
import com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperRenderHandler;
import com.simibubi.create.content.curiosities.zapper.terrainzapper.WorldshaperRenderHandler;
import com.simibubi.create.content.logistics.block.mechanicalArm.ArmInteractionPointHandler;
2020-05-23 14:02:38 +02:00
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.gui.ScreenOpener;
import com.simibubi.create.foundation.item.TooltipHelper;
import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer;
import com.simibubi.create.foundation.tileEntity.behaviour.edgeInteraction.EdgeInteractionRenderer;
import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer;
import com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkRenderer;
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueRenderer;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.ServerSpeedProvider;
import net.minecraft.client.Minecraft;
2020-10-04 01:59:51 +02:00
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.renderer.ActiveRenderInfo;
2020-03-29 06:07:49 +02:00
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.texture.OverlayTexture;
2020-10-04 01:59:51 +02:00
import net.minecraft.entity.Pose;
import net.minecraft.item.ItemStack;
2020-10-04 01:59:51 +02:00
import net.minecraft.util.math.AxisAlignedBB;
2020-09-22 17:44:22 +02:00
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.event.TickEvent.ClientTickEvent;
import net.minecraftforge.event.TickEvent.Phase;
import net.minecraftforge.event.TickEvent.RenderTickEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
@EventBusSubscriber(value = Dist.CLIENT)
public class ClientEvents {
private static final String itemPrefix = "item." + Create.ID;
private static final String blockPrefix = "block." + Create.ID;
@SubscribeEvent
public static void onTick(ClientTickEvent event) {
World world = Minecraft.getInstance().world;
if (event.phase == Phase.START)
return;
AnimationTickHolder.tick();
2020-10-04 01:59:51 +02:00
if (!isGameActive())
return;
2020-10-04 01:59:51 +02:00
ClientPlayerEntity player = Minecraft.getInstance().player;
AxisAlignedBB bb = player.getBoundingBox(Pose.CROUCHING).shrink(1.0E-7D);
// Stream<VoxelShape> blockCollisions = world.getBlockCollisions(player, bb);
// Debug.debugChat(blockCollisions.count() + "");
// blockCollisions.forEach(vs -> Debug.debugChat(vs.toString()));
// Debug.debugChat("" + blockCollisions.allMatch(VoxelShape::isEmpty));
CreateClient.schematicSender.tick();
CreateClient.schematicAndQuillHandler.tick();
CreateClient.schematicHandler.tick();
ContraptionCollider.runCollisions(world);
MinecartCouplingHandler.tick(world);
ScreenOpener.tick();
ServerSpeedProvider.clientTick();
BeltConnectorHandler.tick();
FilteringRenderer.tick();
LinkRenderer.tick();
ScrollValueRenderer.tick();
ChassisRangeDisplay.tick();
EdgeInteractionRenderer.tick();
WorldshaperRenderHandler.tick();
BlockzapperRenderHandler.tick();
ClientMinecartCouplingHandler.tick();
KineticDebugger.tick();
ZapperRenderHandler.tick();
ExtendoGripRenderHandler.tick();
// CollisionDebugger.tick();
ArmInteractionPointHandler.tick();
CreateClient.outliner.tickOutlines();
}
@SubscribeEvent
public static void onLoadWorld(WorldEvent.Load event) {
CreateClient.bufferCache.invalidate();
}
@SubscribeEvent
public static void onRenderWorld(RenderWorldLastEvent event) {
2020-03-29 06:07:49 +02:00
MatrixStack ms = event.getMatrixStack();
ActiveRenderInfo info = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
2020-09-22 17:44:22 +02:00
Vector3d view = info.getProjectedView();
ms.push();
ms.translate(-view.getX(), -view.getY(), -view.getZ());
SuperRenderTypeBuffer buffer = SuperRenderTypeBuffer.getInstance();
MinecartCouplingHandler.render(ms, buffer);
CreateClient.schematicHandler.render(ms, buffer);
CreateClient.outliner.renderOutlines(ms, buffer);
// CollisionDebugger.render(ms, buffer);
buffer.draw();
ms.pop();
}
@SubscribeEvent
public static void onRenderOverlay(RenderGameOverlayEvent.Post event) {
if (event.getType() != ElementType.HOTBAR)
return;
onRenderHotbar(new MatrixStack(), Minecraft.getInstance()
.getBufferBuilders()
.getEntityVertexConsumers(), 0xF000F0, OverlayTexture.DEFAULT_UV);
}
public static void onRenderHotbar(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {
CreateClient.schematicHandler.renderOverlay(ms, buffer, light, overlay);
}
@SubscribeEvent
public static void addToItemTooltip(ItemTooltipEvent event) {
if (!AllConfigs.CLIENT.tooltips.get())
return;
if (Minecraft.getInstance().player == null)
return;
ItemStack stack = event.getItemStack();
String translationKey = stack.getItem()
.getTranslationKey(stack);
if (!translationKey.startsWith(itemPrefix) && !translationKey.startsWith(blockPrefix))
return;
if (TooltipHelper.hasTooltip(stack)) {
List<ITextComponent> itemTooltip = event.getToolTip();
List<ITextComponent> toolTip = new ArrayList<>();
toolTip.add(itemTooltip.remove(0));
TooltipHelper.getTooltip(stack)
.addInformation(toolTip);
itemTooltip.addAll(0, toolTip);
}
}
@SubscribeEvent
public static void onRenderTick(RenderTickEvent event) {
if (!isGameActive())
return;
TurntableHandler.gameRenderTick();
}
protected static boolean isGameActive() {
return !(Minecraft.getInstance().world == null || Minecraft.getInstance().player == null);
}
}