Skip to content

Commit

Permalink
avoid nearby colony lookup on each frame (#9972)
Browse files Browse the repository at this point in the history
Avoid nearby colony lookup on each frame
  • Loading branch information
someaddons authored Jun 9, 2024
1 parent cadb39a commit 758292b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.MultiBufferSource.BufferSource;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;

import net.minecraftforge.client.event.RenderLevelStageEvent;
Expand Down Expand Up @@ -51,7 +52,6 @@ public void renderWorldLastEvent(final RenderLevelStageEvent event)
clientLevel = Minecraft.getInstance().level;
clientPlayer = Minecraft.getInstance().player;
mainHandItem = clientPlayer.getMainHandItem();
nearestColony = IColonyManager.getInstance().getClosestColonyView(clientLevel, clientPlayer.blockPosition());
clientRenderDist = Minecraft.getInstance().options.renderDistance().get();

final Vec3 cameraPos = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition();
Expand Down Expand Up @@ -85,4 +85,14 @@ boolean hasNearestColony()
{
return nearestColony != null;
}

/**
* Checks for a nearby colony
*
* @param level
*/
public void checkNearbyColony(final Level level)
{
nearestColony = IColonyManager.getInstance().getClosestColonyView(level, clientPlayer.blockPosition());
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/minecolonies/core/event/ClientEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.minecolonies.api.colony.buildings.registry.BuildingEntry;
import com.minecolonies.api.research.IGlobalResearch;
import com.minecolonies.api.util.InventoryUtils;
import com.minecolonies.api.util.constant.ColonyConstants;
import com.minecolonies.api.util.constant.Constants;
import com.minecolonies.api.util.constant.TranslationConstants;
import com.minecolonies.core.client.gui.WindowBuildingBrowser;
Expand Down Expand Up @@ -44,6 +45,7 @@
import net.minecraftforge.client.event.RenderLevelStageEvent;
import net.minecraftforge.client.event.sound.PlaySoundEvent;
import net.minecraftforge.common.util.Lazy;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.EventPriority;
Expand Down Expand Up @@ -77,6 +79,15 @@ public static void renderWorldLastEvent(@NotNull final RenderLevelStageEvent eve
WorldEventContext.INSTANCE.renderWorldLastEvent(event);
}

@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onwWorldTick(@NotNull final TickEvent.LevelTickEvent event)
{
if (event.level.isClientSide && event.phase == TickEvent.Phase.END && ColonyConstants.rand.nextInt(20) == 0)
{
WorldEventContext.INSTANCE.checkNearbyColony(event.level);
}
}

@SubscribeEvent
public static void onPlayerLogout(@NotNull final ClientPlayerNetworkEvent.LoggingOut event)
{
Expand Down

0 comments on commit 758292b

Please # to comment.