Skip to content

Commit

Permalink
replace distance manager with concurrent hashmap
Browse files Browse the repository at this point in the history
fix #1399
fix #1405
  • Loading branch information
Cheaterpaul committed Aug 24, 2024
1 parent 582364c commit 1d85d82
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/main/java/de/teamlapen/vampirism/GeneralEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.PathfinderMob;
Expand All @@ -34,6 +35,7 @@

import java.lang.reflect.Array;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* Handles all events used in central parts of the mod
Expand Down Expand Up @@ -117,4 +119,12 @@ public void onServerStarted(ServerStartedEvent event) {
LOGGER.warn("LootTables Failed to inject {} loottables", missing);
}
}

@SubscribeEvent
public void onLevelLoad(LevelEvent.Load event) {
if (event.getLevel() instanceof ServerLevel level) {
LOGGER.info("Replacing DistanceManager.chunksToUpdateFutures for level {} with concurrent set.", level.dimension());
level.getChunkSource().chunkMap.getDistanceManager().chunksToUpdateFutures = ConcurrentHashMap.newKeySet();
}
}
}
29 changes: 29 additions & 0 deletions src/main/java/de/teamlapen/vampirism/mixin/GoalSelectorMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package de.teamlapen.vampirism.mixin;

import com.google.common.collect.Sets;
import net.minecraft.world.entity.ai.goal.GoalSelector;
import net.minecraft.world.entity.ai.goal.WrappedGoal;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Supplier;

@Mixin(GoalSelector.class)
public class GoalSelectorMixin {

@Mutable
@Shadow @Final public Set<WrappedGoal> availableGoals;

@Inject(at = @At("TAIL"), method = "<init>")
private void replace(Supplier supplier, CallbackInfo ci) {
availableGoals = ConcurrentHashMap.newKeySet();
}
}
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,5 @@ public net.minecraft.client.model.PlayerModel f_103373_ # cloak
public net.minecraft.client.gui.screens.achievement.StatsScreen$GeneralStatisticsList
public net.minecraft.client.gui.screens.achievement.StatsScreen$GeneralStatisticsList$Entry
public net.minecraft.client.gui.components.AbstractSelectionList$Entry
public net.minecraft.world.inventory.ItemCombinerMenuSlotDefinition <init>(Ljava/util/List;Lnet/minecraft/world/inventory/ItemCombinerMenuSlotDefinition$SlotDefinition;)V # ItemCombinerMenuSlotDefinition
public net.minecraft.world.inventory.ItemCombinerMenuSlotDefinition <init>(Ljava/util/List;Lnet/minecraft/world/inventory/ItemCombinerMenuSlotDefinition$SlotDefinition;)V # ItemCombinerMenuSlotDefinition
public-f net.minecraft.server.level.DistanceManager f_140765_ # chunksToUpdateFutures
1 change: 1 addition & 0 deletions src/main/resources/vampirism.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"BeaconBlockEntityMixin",
"CrossbowItemMixin",
"EntitySubPredicateTypesAccessor",
"GoalSelectorMixin",
"IngredientAccessor",
"ItemMixin",
"LivingEntityAccessor",
Expand Down

0 comments on commit 1d85d82

Please sign in to comment.