2020-07-24 19:43:33 +02:00
|
|
|
package com.simibubi.create.events;
|
2019-09-03 08:34:02 +02:00
|
|
|
|
2020-03-29 06:07:49 +02:00
|
|
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
2021-01-30 11:51:44 +01:00
|
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
2020-12-03 20:41:55 +01:00
|
|
|
import com.simibubi.create.AllFluids;
|
2020-07-24 19:43:33 +02:00
|
|
|
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;
|
2020-10-08 20:13:17 +02:00
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionHandler;
|
2020-08-05 22:10:05 +02:00
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.chassis.ChassisRangeDisplay;
|
2021-02-18 19:43:22 +01:00
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher;
|
2020-10-08 20:13:17 +02:00
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.train.CouplingHandlerClient;
|
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.train.CouplingPhysics;
|
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.train.CouplingRenderer;
|
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController;
|
2020-05-23 14:02:38 +02:00
|
|
|
import com.simibubi.create.content.contraptions.components.turntable.TurntableHandler;
|
2021-03-09 03:45:05 +01:00
|
|
|
import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation;
|
2020-08-05 22:10:05 +02:00
|
|
|
import com.simibubi.create.content.contraptions.relays.belt.item.BeltConnectorHandler;
|
|
|
|
import com.simibubi.create.content.curiosities.tools.ExtendoGripRenderHandler;
|
2020-12-12 12:32:32 +01:00
|
|
|
import com.simibubi.create.content.curiosities.zapper.ZapperItem;
|
2020-08-05 22:10:05 +02:00
|
|
|
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;
|
2021-03-26 00:15:38 +01:00
|
|
|
import com.simibubi.create.content.logistics.block.depot.EjectorTargetHandler;
|
2020-08-05 22:10:05 +02:00
|
|
|
import com.simibubi.create.content.logistics.block.mechanicalArm.ArmInteractionPointHandler;
|
2020-05-23 14:02:38 +02:00
|
|
|
import com.simibubi.create.foundation.config.AllConfigs;
|
2019-12-09 14:58:12 +01:00
|
|
|
import com.simibubi.create.foundation.item.TooltipHelper;
|
2020-12-12 12:32:32 +01:00
|
|
|
import com.simibubi.create.foundation.networking.AllPackets;
|
|
|
|
import com.simibubi.create.foundation.networking.LeftClickPacket;
|
2021-02-16 19:35:26 +01:00
|
|
|
import com.simibubi.create.foundation.ponder.PonderTooltipHandler;
|
2021-03-15 23:58:41 +01:00
|
|
|
import com.simibubi.create.foundation.render.KineticRenderer;
|
2021-02-12 08:36:05 +01:00
|
|
|
import com.simibubi.create.foundation.render.backend.FastRenderDispatcher;
|
2021-02-13 02:30:21 +01:00
|
|
|
import com.simibubi.create.foundation.render.backend.RenderWork;
|
2020-06-03 22:04:05 +02:00
|
|
|
import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer;
|
2020-08-05 22:10:05 +02:00
|
|
|
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;
|
2021-03-13 01:33:01 +01:00
|
|
|
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueHandler;
|
2020-08-05 22:10:05 +02:00
|
|
|
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueRenderer;
|
2019-10-29 19:02:20 +01:00
|
|
|
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
2020-08-05 22:10:05 +02:00
|
|
|
import com.simibubi.create.foundation.utility.ServerSpeedProvider;
|
2020-12-16 17:36:22 +01:00
|
|
|
import com.simibubi.create.foundation.utility.placement.PlacementHelpers;
|
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;
|
2021-02-10 06:18:05 +01:00
|
|
|
import net.minecraft.client.world.ClientWorld;
|
2020-12-03 20:41:55 +01:00
|
|
|
import net.minecraft.fluid.Fluid;
|
|
|
|
import net.minecraft.fluid.IFluidState;
|
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;
|
2021-02-10 06:18:05 +01:00
|
|
|
import net.minecraft.world.IWorld;
|
2020-08-05 22:10:05 +02:00
|
|
|
import net.minecraft.world.World;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
2020-12-03 20:41:55 +01:00
|
|
|
import net.minecraftforge.client.event.EntityViewRenderEvent;
|
2019-09-03 23:03:52 +02:00
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
|
2021-01-24 14:30:05 +01:00
|
|
|
import net.minecraftforge.client.event.RenderTooltipEvent;
|
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;
|
2020-12-12 12:32:32 +01:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
2020-08-05 22:10:05 +02:00
|
|
|
import net.minecraftforge.event.world.WorldEvent;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
|
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
|
|
|
|
2021-03-04 12:53:24 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
@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) {
|
2020-08-05 22:10:05 +02:00
|
|
|
World world = Minecraft.getInstance().world;
|
2019-09-03 08:34:02 +02:00
|
|
|
if (event.phase == Phase.START)
|
|
|
|
return;
|
2019-11-07 11:30:29 +01:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
if (!isGameActive())
|
|
|
|
return;
|
|
|
|
|
2021-01-14 22:59:26 +01:00
|
|
|
AnimationTickHolder.tick();
|
2021-01-27 04:45:13 +01:00
|
|
|
FastRenderDispatcher.tick();
|
2021-03-13 01:33:01 +01:00
|
|
|
ScrollValueHandler.tick();
|
2021-01-04 23:37:44 +01:00
|
|
|
|
2020-08-05 22:10:05 +02:00
|
|
|
CreateClient.schematicSender.tick();
|
|
|
|
CreateClient.schematicAndQuillHandler.tick();
|
|
|
|
CreateClient.schematicHandler.tick();
|
2020-12-03 20:41:55 +01:00
|
|
|
|
2020-10-08 20:13:17 +02:00
|
|
|
ContraptionHandler.tick(world);
|
|
|
|
CapabilityMinecartController.tick(world);
|
|
|
|
CouplingPhysics.tick(world);
|
2020-12-03 20:41:55 +01:00
|
|
|
|
2021-02-16 19:35:26 +01:00
|
|
|
PonderTooltipHandler.tick();
|
2021-03-04 12:53:24 +01:00
|
|
|
//ScreenOpener.tick();
|
2020-08-05 22:10:05 +02:00
|
|
|
ServerSpeedProvider.clientTick();
|
|
|
|
BeltConnectorHandler.tick();
|
|
|
|
FilteringRenderer.tick();
|
|
|
|
LinkRenderer.tick();
|
|
|
|
ScrollValueRenderer.tick();
|
|
|
|
ChassisRangeDisplay.tick();
|
|
|
|
EdgeInteractionRenderer.tick();
|
|
|
|
WorldshaperRenderHandler.tick();
|
|
|
|
BlockzapperRenderHandler.tick();
|
2020-10-08 20:13:17 +02:00
|
|
|
CouplingHandlerClient.tick();
|
|
|
|
CouplingRenderer.tickDebugModeRenders();
|
2020-08-05 22:10:05 +02:00
|
|
|
KineticDebugger.tick();
|
|
|
|
ZapperRenderHandler.tick();
|
|
|
|
ExtendoGripRenderHandler.tick();
|
|
|
|
// CollisionDebugger.tick();
|
|
|
|
ArmInteractionPointHandler.tick();
|
2021-03-26 00:15:38 +01:00
|
|
|
EjectorTargetHandler.tick();
|
2020-12-16 17:36:22 +01:00
|
|
|
PlacementHelpers.tick();
|
2020-12-03 20:41:55 +01:00
|
|
|
CreateClient.outliner.tickOutlines();
|
2021-02-16 00:48:13 +01:00
|
|
|
CreateClient.ghostBlocks.tickGhosts();
|
2021-01-24 06:02:11 +01:00
|
|
|
ContraptionRenderDispatcher.tick();
|
2020-08-05 22:10:05 +02:00
|
|
|
}
|
2020-12-03 20:41:55 +01:00
|
|
|
|
2020-08-05 22:10:05 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onLoadWorld(WorldEvent.Load event) {
|
2021-02-10 06:18:05 +01:00
|
|
|
IWorld world = event.getWorld();
|
|
|
|
if (world.isRemote() && world instanceof ClientWorld) {
|
|
|
|
CreateClient.invalidateRenderers();
|
|
|
|
AnimationTickHolder.reset();
|
2021-03-15 23:58:41 +01:00
|
|
|
KineticRenderer renderer = CreateClient.kineticRenderer.get(world);
|
|
|
|
renderer.invalidate();
|
|
|
|
((ClientWorld) world).loadedTileEntityList.forEach(renderer::add);
|
2021-02-10 06:18:05 +01:00
|
|
|
}
|
2021-03-09 03:45:05 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
i was getting nullPointers when trying to call this during client setup,
|
|
|
|
so i assume minecraft's language manager isn't yet fully loaded at that time.
|
|
|
|
not sure where else to call this tho :S
|
|
|
|
*/
|
|
|
|
IHaveGoggleInformation.numberFormat.update();
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|
|
|
|
|
2021-01-23 21:49:33 +01:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onUnloadWorld(WorldEvent.Unload event) {
|
2021-02-10 06:18:05 +01:00
|
|
|
if (event.getWorld().isRemote()) {
|
2021-03-15 23:58:41 +01:00
|
|
|
CreateClient.invalidateRenderers(event.getWorld());
|
2021-02-10 06:18:05 +01:00
|
|
|
AnimationTickHolder.reset();
|
|
|
|
}
|
2021-01-23 21:49:33 +01:00
|
|
|
}
|
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onRenderWorld(RenderWorldLastEvent event) {
|
2021-01-11 09:29:02 +01:00
|
|
|
Vec3d cameraPos = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView();
|
2021-02-28 01:34:56 +01:00
|
|
|
float pt = AnimationTickHolder.getPartialTicks();
|
2021-01-11 09:29:02 +01:00
|
|
|
|
2020-03-29 06:07:49 +02:00
|
|
|
MatrixStack ms = event.getMatrixStack();
|
2020-04-05 03:54:24 +02:00
|
|
|
ms.push();
|
2021-01-11 09:29:02 +01:00
|
|
|
ms.translate(-cameraPos.getX(), -cameraPos.getY(), -cameraPos.getZ());
|
2020-06-03 22:04:05 +02:00
|
|
|
SuperRenderTypeBuffer buffer = SuperRenderTypeBuffer.getInstance();
|
2020-12-03 20:41:55 +01:00
|
|
|
|
2020-10-08 20:13:17 +02:00
|
|
|
CouplingRenderer.renderAll(ms, buffer);
|
2020-05-28 01:29:26 +02:00
|
|
|
CreateClient.schematicHandler.render(ms, buffer);
|
2021-02-16 00:48:13 +01:00
|
|
|
CreateClient.ghostBlocks.renderAll(ms, buffer);
|
|
|
|
|
2021-02-28 01:34:56 +01:00
|
|
|
CreateClient.outliner.renderOutlines(ms, buffer, pt);
|
2021-01-18 09:31:33 +01:00
|
|
|
// LightVolumeDebugger.render(ms, buffer);
|
2020-04-05 03:54:24 +02:00
|
|
|
buffer.draw();
|
2021-01-30 11:51:44 +01:00
|
|
|
RenderSystem.enableCull();
|
2020-12-03 20:41:55 +01:00
|
|
|
|
2020-06-03 22:04:05 +02:00
|
|
|
ms.pop();
|
2021-01-10 06:59:11 +01:00
|
|
|
|
|
|
|
RenderWork.runAll();
|
2021-01-14 22:59:26 +01:00
|
|
|
FastRenderDispatcher.endFrame();
|
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()
|
2020-12-16 17:36:22 +01:00
|
|
|
.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
|
|
|
}
|
|
|
|
|
2021-01-24 14:30:05 +01:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void getItemTooltipColor(RenderTooltipEvent.Color event) {
|
2021-02-16 19:35:26 +01:00
|
|
|
PonderTooltipHandler.handleTooltipColor(event);
|
2021-01-24 14:30:05 +01:00
|
|
|
}
|
|
|
|
|
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-12-24 16:56:27 +01:00
|
|
|
if (event.getPlayer() == null)
|
2020-03-21 18:32:53 +01:00
|
|
|
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()
|
2020-12-16 17:36:22 +01:00
|
|
|
.getTranslationKey(stack);
|
2019-09-14 18:21:30 +02:00
|
|
|
if (!translationKey.startsWith(itemPrefix) && !translationKey.startsWith(blockPrefix))
|
|
|
|
return;
|
|
|
|
|
2020-12-24 16:56:27 +01:00
|
|
|
if (TooltipHelper.hasTooltip(stack, event.getPlayer())) {
|
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)
|
2020-12-16 17:36:22 +01:00
|
|
|
.addInformation(toolTip);
|
2019-12-09 14:58:12 +01:00
|
|
|
itemTooltip.addAll(0, toolTip);
|
2019-09-14 18:21:30 +02:00
|
|
|
}
|
2021-01-24 14:30:05 +01:00
|
|
|
|
2021-02-16 19:35:26 +01:00
|
|
|
PonderTooltipHandler.addToTooltip(event.getToolTip(), stack);
|
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;
|
|
|
|
TurntableHandler.gameRenderTick();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static boolean isGameActive() {
|
|
|
|
return !(Minecraft.getInstance().world == null || Minecraft.getInstance().player == null);
|
|
|
|
}
|
|
|
|
|
2020-12-03 20:41:55 +01:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void getFogDensity(EntityViewRenderEvent.FogDensity event) {
|
|
|
|
ActiveRenderInfo info = event.getInfo();
|
|
|
|
IFluidState fluidState = info.getFluidState();
|
|
|
|
if (fluidState.isEmpty())
|
|
|
|
return;
|
|
|
|
Fluid fluid = fluidState.getFluid();
|
|
|
|
|
|
|
|
if (fluid.isEquivalentTo(AllFluids.CHOCOLATE.get())) {
|
|
|
|
event.setDensity(5f);
|
|
|
|
event.setCanceled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fluid.isEquivalentTo(AllFluids.HONEY.get())) {
|
|
|
|
event.setDensity(1.5f);
|
|
|
|
event.setCanceled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void getFogColor(EntityViewRenderEvent.FogColors event) {
|
|
|
|
ActiveRenderInfo info = event.getInfo();
|
|
|
|
IFluidState fluidState = info.getFluidState();
|
|
|
|
if (fluidState.isEmpty())
|
|
|
|
return;
|
|
|
|
Fluid fluid = fluidState.getFluid();
|
|
|
|
|
|
|
|
if (fluid.isEquivalentTo(AllFluids.CHOCOLATE.get())) {
|
|
|
|
event.setRed(98 / 256f);
|
|
|
|
event.setGreen(32 / 256f);
|
|
|
|
event.setBlue(32 / 256f);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fluid.isEquivalentTo(AllFluids.HONEY.get())) {
|
|
|
|
event.setRed(234 / 256f);
|
|
|
|
event.setGreen(174 / 256f);
|
|
|
|
event.setBlue(47 / 256f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-12 12:32:32 +01:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void leftClickEmpty(PlayerInteractEvent.LeftClickEmpty event) {
|
|
|
|
ItemStack stack = event.getItemStack();
|
|
|
|
if (stack.getItem() instanceof ZapperItem) {
|
|
|
|
AllPackets.channel.sendToServer(new LeftClickPacket());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|