Skip to content

Commit

Permalink
Fixes most IP issues. Chunks in other visible dimensions aren't reloa…
Browse files Browse the repository at this point in the history
…ded when conditions change, but most everything else works well enough as far as I can tell.
  • Loading branch information
Haven-King committed Feb 27, 2021
1 parent aba43ef commit 4c0800e
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 6 deletions.
17 changes: 17 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ group = project.maven_group

repositories {
mavenLocal()
mavenCentral()
maven {
url 'http://maven.fabricmc.net/'
name 'Fabric'
}
maven {
name = 'JitPack'
url = 'https://jitpack.io'
}

jcenter()
}

dependencies {
Expand All @@ -20,8 +31,14 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
compileOnly "com.google.code.findbugs:jsr305:3.0.2"

modCompileOnly "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modRuntime "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modCompileOnly "me.jellysquid.mods:lithium:0.6.3-SNAPSHOT"
modCompileOnly "me.jellysquid.mods:lithium-api:0.6.3-SNAPSHOT"

modCompileOnly "com.qouteall:imm_ptl_core:0.80"
modCompileOnly "com.qouteall:immersive-portals:0.80"
}

processResources {
Expand Down
7 changes: 5 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ yarn_mappings = 1.16.5+build.4
loader_version = 0.11.1

# Mod Properties
mod_version = 1.0.0
mod_version = 1.0.1
maven_group = dev.hephaestus
archives_base_name = FibLib
archives_base_name = FibLib

# Dependencies
fabric_version = 0.31.0+1.16
14 changes: 14 additions & 0 deletions src/main/java/dev/hephaestus/fiblib/mixin/CDSMAccessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.hephaestus.fiblib.mixin;

import com.qouteall.immersive_portals.chunk_loading.ChunkDataSyncManager;
import com.qouteall.immersive_portals.chunk_loading.DimensionalChunkPos;
import com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(ChunkDataSyncManager.class)
public interface CDSMAccessor {
@Invoker
void invokeSendChunkDataPacketNow(ServerPlayerEntity player, DimensionalChunkPos pos, IEThreadedAnvilChunkStorage tacs);
}
4 changes: 4 additions & 0 deletions src/main/java/dev/hephaestus/fiblib/mixin/ChunkReloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(ThreadedAnvilChunkStorage.class)
public interface ChunkReloader {
@Invoker("handlePlayerAddedOrRemoved")
void reloadChunks(ServerPlayerEntity playerEntity, boolean added);

@Accessor
int getWatchDistance();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.mojang.datafixers.DataFixer;
import com.qouteall.immersive_portals.Global;
import com.qouteall.immersive_portals.chunk_loading.DimensionalChunkPos;
import com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage;
import dev.hephaestus.fiblib.api.BlockFib;
import dev.hephaestus.fiblib.impl.LookupTable;
import dev.hephaestus.fiblib.api.BlockFibRegistry;
import dev.hephaestus.fiblib.impl.LookupTable;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.BlockState;
import net.minecraft.resource.DataPackSettings;
import net.minecraft.resource.ResourcePackManager;
Expand All @@ -16,6 +20,7 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
import net.minecraft.util.UserCache;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.profiler.Profiler;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.world.SaveProperties;
Expand Down Expand Up @@ -79,7 +84,28 @@ public void tickFibber(BooleanSupplier shouldKeepTicking, CallbackInfo ci) {
ThreadedAnvilChunkStorage TACS = ((TACSAccessor) player.getServerWorld().getChunkManager())
.getThreadedAnvilChunkStorage();

((ChunkReloader) TACS).reloadChunks(player, true);

if (FabricLoader.getInstance().isModLoaded("immersive_portals")) {
CDSMAccessor cdsm = (CDSMAccessor) Global.chunkDataSyncManager;


double scale = player.world.getDimension().getCoordinateScale();
int i = MathHelper.floor(player.getX() * scale) >> 4;
int j = MathHelper.floor(player.getZ() * scale) >> 4;
int watchDistance = ((ChunkReloader) TACS).getWatchDistance();



for(int k = i - watchDistance; k <= i + watchDistance; ++k) {
for(int l = j - watchDistance; l <= j + watchDistance; ++l) {
DimensionalChunkPos chunkPos = new DimensionalChunkPos(player.world.getRegistryKey(), k, l);
cdsm.invokeSendChunkDataPacketNow(player, chunkPos, (IEThreadedAnvilChunkStorage) TACS);
}
}
} else {

((ChunkReloader) TACS).reloadChunks(player, true);
}
}

updated.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ public String getRefMapperConfig() {

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
FabricLoader loader = FabricLoader.getInstance();
if (targetClassName.startsWith("me.jellysquid.mods.lithium")) {
return FabricLoader.getInstance().isModLoaded("lithium");
return loader.isModLoaded("lithium");
}

if (loader.isModLoaded("immersive_portals")) {
return !mixinClassName.endsWith("MixinThreadedAnvilChunkStorage");
} else if (mixinClassName.startsWith("com.qouteall")) {
return false;
}

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dev.hephaestus.fiblib.mixin.packets.chunkdata;

import com.qouteall.immersive_portals.chunk_loading.ChunkDataSyncManager;
import com.qouteall.immersive_portals.chunk_loading.DimensionalChunkPos;
import com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage;
import dev.hephaestus.fiblib.impl.FibLib;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value = ChunkDataSyncManager.class, remap = false)
public class MixinChunkDataSyncManager {
@Inject(method = "sendChunkDataPacketNow", at = @At("HEAD"))
private void setPlayer(ServerPlayerEntity player, DimensionalChunkPos chunkPos, IEThreadedAnvilChunkStorage ieStorage, CallbackInfo ci) {
FibLib.PLAYER.set(player);
}
}
4 changes: 3 additions & 1 deletion src/main/resources/fiblib.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
"plugin": "dev.hephaestus.fiblib.mixin.VolatileMixinPlugin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinMinecraftServer",
"CDSMAccessor",
"ChunkReloader",
"MixinMinecraftServer",
"MixinServerPlayNetworkHandler",
"TACSAccessor",
"packets.MixinBlockUpdateS2CPacket",
"packets.MixinPlayerActionResponseS2CPacket",
"packets.chunkdata.MixinArrayPalette",
"packets.chunkdata.MixinBiMapPalette",
"packets.chunkdata.MixinChunkDataS2CPacket",
"packets.chunkdata.MixinChunkDataSyncManager",
"packets.chunkdata.MixinChunkDeltaUpdateS2CPacket",
"packets.chunkdata.MixinChunkHolder",
"packets.chunkdata.MixinChunkSection",
Expand Down

0 comments on commit 4c0800e

Please sign in to comment.