Fix RemoveBlockGoal permaloading chunks, remove START ticket entirely

This commit is contained in:
embeddedt 2023-04-29 17:33:10 -04:00
parent 609da0f545
commit fe0b82e6da
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
5 changed files with 38 additions and 11 deletions

View File

@ -75,6 +75,7 @@ public class ModernFixEarlyConfig {
this.addMixinRule("perf.dynamic_structure_manager", true);
this.addMixinRule("bugfix.mc218112", true);
this.addMixinRule("bugfix.chunk_deadlock", true);
this.addMixinRule("bugfix.remove_block_chunkloading", true);
this.addMixinRule("bugfix.paper_chunk_patches", true);
this.addMixinRule("bugfix.chunk_deadlock.valhesia", modPresent("valhelsia_structures"));
this.addMixinRule("bugfix.tf_cme_on_load", modPresent("twilightforest"));

View File

@ -0,0 +1,33 @@
package org.embeddedt.modernfix.mixin.bugfix.remove_block_chunkloading;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.goal.RemoveBlockGoal;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.event.ForgeEventFactory;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(RemoveBlockGoal.class)
public class RemoveBlockGoalMixin {
@Shadow @Final private Mob removerMob;
@Redirect(method = "canUse", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/common/ForgeHooks;canEntityDestroy(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/LivingEntity;)Z"))
private boolean fireGriefingEvent(Level level, BlockPos pos, LivingEntity entity) {
return ForgeEventFactory.getMobGriefingEvent(level, entity);
}
@Redirect(method = "isValidTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;is(Lnet/minecraft/world/level/block/Block;)Z"))
private boolean checkBlockValidDestroyTarget(BlockState state, Block desiredBlock, LevelReader level, BlockPos pos) {
if(!(state.canEntityDestroy(level, pos, this.removerMob) && ForgeEventFactory.onEntityDestroyBlock(this.removerMob, pos, state)))
return false;
return state.is(desiredBlock);
}
}

View File

@ -6,6 +6,7 @@ import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.TicketType;
import net.minecraft.util.Unit;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.ChunkStatus;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@ -14,9 +15,8 @@ import org.spongepowered.asm.mixin.injection.Redirect;
public class MinecraftServerMixin {
@Redirect(method = "prepareLevels", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerChunkCache;addRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
private void addSpawnChunkTicket(ServerChunkCache cache, TicketType<?> type, ChunkPos pos, int distance, Object o) {
DistanceManager manager = ((ServerChunkCacheAccessor)cache).getDistanceManager();
/* make one chunk load */
manager.addTicket(TicketType.START, pos, 44, Unit.INSTANCE);
// load first chunk
cache.getChunk(pos.x, pos.z, ChunkStatus.FULL, true);
}
@Redirect(method = "prepareLevels", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerChunkCache;getTickingGenerated()I"), require = 0)

View File

@ -1,10 +1,8 @@
package org.embeddedt.modernfix.mixin.perf.remove_spawn_chunks;
import net.minecraft.server.level.DistanceManager;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.TicketType;
import net.minecraft.util.Unit;
import net.minecraft.world.level.ChunkPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@ -14,15 +12,9 @@ import org.spongepowered.asm.mixin.injection.Redirect;
public class ServerLevelMixin {
@Redirect(method = "setDefaultSpawnPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerChunkCache;removeRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
private void removeTicket(ServerChunkCache cache, TicketType<?> type, ChunkPos pos, int distance, Object o) {
DistanceManager manager = ((ServerChunkCacheAccessor)cache).getDistanceManager();
/* make one chunk load */
manager.removeTicket(TicketType.START, pos, 44, Unit.INSTANCE);
}
@Redirect(method = "setDefaultSpawnPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerChunkCache;addRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
private void addTicket(ServerChunkCache cache, TicketType<?> type, ChunkPos pos, int distance, Object o) {
DistanceManager manager = ((ServerChunkCacheAccessor)cache).getDistanceManager();
/* make one chunk load */
manager.addTicket(TicketType.START, pos, 44, Unit.INSTANCE);
}
}

View File

@ -20,6 +20,7 @@
"bugfix.refinedstorage.te_bug.FluidExternalStorageMixin",
"bugfix.refinedstorage.te_bug.ItemExternalStorageCacheMixin",
"bugfix.refinedstorage.te_bug.ItemExternalStorageMixin",
"bugfix.remove_block_chunkloading.RemoveBlockGoalMixin",
"bugfix.chunk_deadlock.ServerChunkCacheMixin",
"bugfix.chunk_deadlock.valhesia.BlockStateBaseMixin",
"perf.dedicated_reload_executor.MinecraftServerMixin",