Skip to content

Commit

Permalink
fix: server crash related to capability stuff due to distribution dif…
Browse files Browse the repository at this point in the history
…ferences
  • Loading branch information
TheBv committed Feb 20, 2024
1 parent 7caadd8 commit 91a8438
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.CapabilityToken;
Expand Down Expand Up @@ -91,6 +92,7 @@ public static void syncEntityData(final Entity entity) {
}
}

@OnlyIn(Dist.CLIENT)
public static @Nullable Player getLocalPlayer() {
if (FMLEnvironment.dist == Dist.CLIENT) {
return Minecraft.getInstance().player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public static LazyOptional<EntityData> getCapability(final Entity entity) {
public static void removeCachedEntry(final Entity entity) {
if (entity instanceof LivingEntity) {
int key = entity.getId();

if (entity.getLevel().isClientSide()) {
if (entity == CapabilityHandler.getLocalPlayer()) {
// Can trigger on death or when player leaves the game (this is when we want to actually clear)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.RenderLevelStageEvent;

public class WorldEventContext {
Expand All @@ -31,6 +33,7 @@ private WorldEventContext()
*/
int clientRenderDist;

@OnlyIn(Dist.CLIENT)
public void renderWorldLastEvent(final RenderLevelStageEvent event)
{
bufferSource = WorldRenderMacros.getBufferSource();
Expand Down

2 comments on commit 91a8438

@SiverDX
Copy link
Contributor

@SiverDX SiverDX commented on 91a8438 Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't use @OnlyIn, it's for internal (neo) forge (and vanilla) use

the issue is that @ModEventBusSubscriber scans the whole class - just use the existing PROXY call (like in 1.20) or move the getLocalPlayer method outside of CapabilityHandler class

@TheBv
Copy link
Collaborator Author

@TheBv TheBv commented on 91a8438 Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen what Alex did and will swap it out.

Please sign in to comment.