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

290 lines
11 KiB
Java
Raw Normal View History

package com.simibubi.create.events;
2020-03-29 06:07:49 +02:00
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.AllFluids;
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.ContraptionHandler;
import com.simibubi.create.content.contraptions.components.structureMovement.chassis.ChassisRangeDisplay;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher;
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;
import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation;
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.ZapperItem;
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.depot.EjectorTargetHandler;
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.item.TooltipHelper;
import com.simibubi.create.foundation.networking.AllPackets;
import com.simibubi.create.foundation.networking.LeftClickPacket;
import com.simibubi.create.foundation.ponder.PonderTooltipHandler;
import com.simibubi.create.foundation.ponder.PonderWorld;
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;
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.ScrollValueHandler;
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueRenderer;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.ServerSpeedProvider;
import com.simibubi.create.foundation.utility.placement.PlacementHelpers;
import com.simibubi.create.foundation.utility.worldWrappers.WrappedClientWorld;
import net.minecraft.client.Minecraft;
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;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.fluid.Fluid;
2020-12-05 11:42:14 +01:00
import net.minecraft.fluid.FluidState;
import net.minecraft.item.ItemStack;
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.IWorld;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ClientPlayerNetworkEvent;
import net.minecraftforge.client.event.EntityViewRenderEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
2021-01-24 14:30:05 +01:00
import net.minecraftforge.client.event.RenderTooltipEvent;
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.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import java.util.ArrayList;
import java.util.List;
@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;
if (!isGameActive())
return;
AnimationTickHolder.tick();
FastRenderDispatcher.tick();
ScrollValueHandler.tick();
CreateClient.schematicSender.tick();
CreateClient.schematicAndQuillHandler.tick();
CreateClient.schematicHandler.tick();
ContraptionHandler.tick(world);
CapabilityMinecartController.tick(world);
CouplingPhysics.tick(world);
PonderTooltipHandler.tick();
//ScreenOpener.tick();
ServerSpeedProvider.clientTick();
BeltConnectorHandler.tick();
FilteringRenderer.tick();
LinkRenderer.tick();
ScrollValueRenderer.tick();
ChassisRangeDisplay.tick();
EdgeInteractionRenderer.tick();
WorldshaperRenderHandler.tick();
BlockzapperRenderHandler.tick();
CouplingHandlerClient.tick();
CouplingRenderer.tickDebugModeRenders();
KineticDebugger.tick();
ZapperRenderHandler.tick();
ExtendoGripRenderHandler.tick();
// CollisionDebugger.tick();
ArmInteractionPointHandler.tick();
EjectorTargetHandler.tick();
PlacementHelpers.tick();
CreateClient.outliner.tickOutlines();
CreateClient.ghostBlocks.tickGhosts();
2021-01-24 06:02:11 +01:00
ContraptionRenderDispatcher.tick();
}
@SubscribeEvent
public static void onJoin(ClientPlayerNetworkEvent.LoggedInEvent event) {
CreateClient.checkGraphicsFanciness();
}
@SubscribeEvent
public static void onLoadWorld(WorldEvent.Load event) {
IWorld world = event.getWorld();
if (world.isRemote() && world instanceof ClientWorld && !(world instanceof WrappedClientWorld)) {
CreateClient.invalidateRenderers(world);
AnimationTickHolder.reset();
KineticRenderer renderer = CreateClient.kineticRenderer.get(world);
renderer.invalidate();
((ClientWorld) world).loadedTileEntityList.forEach(renderer::add);
}
/*
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();
}
2021-01-23 21:49:33 +01:00
@SubscribeEvent
public static void onUnloadWorld(WorldEvent.Unload event) {
if (event.getWorld().isRemote()) {
CreateClient.invalidateRenderers(event.getWorld());
AnimationTickHolder.reset();
}
}
@SubscribeEvent
public static void onRenderWorld(RenderWorldLastEvent event) {
Vector3d cameraPos = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView();
float pt = AnimationTickHolder.getPartialTicks();
2020-03-29 06:07:49 +02:00
MatrixStack ms = event.getMatrixStack();
ms.push();
ms.translate(-cameraPos.getX(), -cameraPos.getY(), -cameraPos.getZ());
SuperRenderTypeBuffer buffer = SuperRenderTypeBuffer.getInstance();
CouplingRenderer.renderAll(ms, buffer);
CreateClient.schematicHandler.render(ms, buffer);
CreateClient.ghostBlocks.renderAll(ms, buffer);
CreateClient.outliner.renderOutlines(ms, buffer, pt);
// LightVolumeDebugger.render(ms, buffer);
buffer.draw();
RenderSystem.enableCull();
ms.pop();
RenderWork.runAll();
FastRenderDispatcher.endFrame();
}
@SubscribeEvent
public static void onRenderOverlay(RenderGameOverlayEvent.Post event) {
if (event.getType() != ElementType.HOTBAR)
return;
onRenderHotbar(event.getMatrixStack(), Minecraft.getInstance()
.getBufferBuilders()
.getEntityVertexConsumers(), 0xF000F0, OverlayTexture.DEFAULT_UV, event.getPartialTicks());
}
public static void onRenderHotbar(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay, float partialTicks) {
CreateClient.schematicHandler.renderOverlay(ms, buffer, light, overlay, partialTicks);
}
2021-01-24 14:30:05 +01:00
@SubscribeEvent
public static void getItemTooltipColor(RenderTooltipEvent.Color event) {
PonderTooltipHandler.handleTooltipColor(event);
2021-01-24 14:30:05 +01:00
}
Merge branch 'mc1.15/dev' into mc1.16/dev # Conflicts: # src/generated/resources/.cache/cache # src/generated/resources/assets/create/blockstates/andesite_funnel.json # src/generated/resources/assets/create/blockstates/brass_funnel.json # src/generated/resources/assets/create/lang/unfinished/de_de.json # src/generated/resources/assets/create/lang/unfinished/es_es.json # src/generated/resources/assets/create/lang/unfinished/fr_fr.json # src/generated/resources/assets/create/lang/unfinished/it_it.json # src/generated/resources/assets/create/lang/unfinished/ja_jp.json # src/generated/resources/assets/create/lang/unfinished/ko_kr.json # src/generated/resources/assets/create/lang/unfinished/nl_nl.json # src/generated/resources/assets/create/lang/unfinished/pt_br.json # src/main/java/com/simibubi/create/AllBlocks.java # src/main/java/com/simibubi/create/compat/jei/category/CreateRecipeCategory.java # src/main/java/com/simibubi/create/content/contraptions/components/actors/ContraptionActorData.java # src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java # src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterTileEntity.java # src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AssemblyException.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/IDisplayAssemblyExceptions.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntity.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/LinearChassisBlock.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageBlock.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerBlock.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java # src/main/java/com/simibubi/create/content/contraptions/fluids/actors/SpoutTileEntity.java # src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java # src/main/java/com/simibubi/create/content/contraptions/goggles/IHaveGoggleInformation.java # src/main/java/com/simibubi/create/content/contraptions/particle/RotationIndicatorParticle.java # src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/BeltMovementHandler.java # src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItem.java # src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelFilterSlotPositioning.java # src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelMovementBehaviour.java # src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelTileEntity.java # src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInteractionPoint.java # src/main/java/com/simibubi/create/content/logistics/item/filter/AbstractFilterScreen.java # src/main/java/com/simibubi/create/content/logistics/item/filter/AttributeFilterScreen.java # src/main/java/com/simibubi/create/content/schematics/SchematicWorld.java # src/main/java/com/simibubi/create/content/schematics/block/SchematicTableScreen.java # src/main/java/com/simibubi/create/content/schematics/block/SchematicannonRenderer.java # src/main/java/com/simibubi/create/events/ClientEvents.java # src/main/java/com/simibubi/create/foundation/block/connected/ConnectedTextureBehaviour.java # src/main/java/com/simibubi/create/foundation/collision/CollisionDebugger.java # src/main/java/com/simibubi/create/foundation/collision/OBBCollider.java # src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java # src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java # src/main/java/com/simibubi/create/foundation/gui/AbstractSimiScreen.java # src/main/java/com/simibubi/create/foundation/gui/AllGuiTextures.java # src/main/java/com/simibubi/create/foundation/gui/AllIcons.java # src/main/java/com/simibubi/create/foundation/gui/widgets/SelectionScrollInput.java # src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java # src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java # src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java # src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java # src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java # src/main/java/com/simibubi/create/foundation/render/backend/Backend.java # src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java # src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java # src/main/java/com/simibubi/create/foundation/utility/ColorHelper.java # src/main/java/com/simibubi/create/foundation/utility/Lang.java # src/main/java/com/simibubi/create/foundation/utility/MatrixStacker.java # src/main/java/com/simibubi/create/foundation/utility/TreeCutter.java # src/main/java/com/simibubi/create/foundation/utility/VecHelper.java # src/main/java/com/simibubi/create/foundation/utility/placement/IPlacementHelper.java # src/main/java/com/simibubi/create/foundation/utility/placement/util/PoleHelper.java
2021-03-20 12:58:02 +01:00
@SubscribeEvent
public static void addToItemTooltip(ItemTooltipEvent event) {
if (!AllConfigs.CLIENT.tooltips.get())
return;
2020-12-24 16:56:27 +01:00
if (event.getPlayer() == null)
return;
ItemStack stack = event.getItemStack();
String translationKey = stack.getItem()
.getTranslationKey(stack);
if (!translationKey.startsWith(itemPrefix) && !translationKey.startsWith(blockPrefix))
return;
2020-12-24 16:56:27 +01:00
if (TooltipHelper.hasTooltip(stack, event.getPlayer())) {
List<ITextComponent> itemTooltip = event.getToolTip();
List<ITextComponent> toolTip = new ArrayList<>();
toolTip.add(itemTooltip.remove(0));
TooltipHelper.getTooltip(stack)
.addInformation(toolTip);
itemTooltip.addAll(0, toolTip);
}
PonderTooltipHandler.addToTooltip(event.getToolTip(), stack);
}
@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);
}
@SubscribeEvent
public static void getFogDensity(EntityViewRenderEvent.FogDensity event) {
ActiveRenderInfo info = event.getInfo();
2020-12-05 11:42:14 +01:00
FluidState 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();
2020-12-05 11:42:14 +01:00
FluidState 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);
}
}
@SubscribeEvent
public static void leftClickEmpty(PlayerInteractEvent.LeftClickEmpty event) {
ItemStack stack = event.getItemStack();
if (stack.getItem() instanceof ZapperItem) {
AllPackets.channel.sendToServer(new LeftClickPacket());
}
}
}