Skip to content

Commit

Permalink
Fixes mixin transform error when Immersive Portals is not present.
Browse files Browse the repository at this point in the history
  • Loading branch information
Haven-King committed Feb 27, 2021
1 parent 4c0800e commit 88f6e5a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
40 changes: 40 additions & 0 deletions src/main/java/dev/hephaestus/fiblib/impl/FibLib.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package dev.hephaestus.fiblib.impl;

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.mixin.CDSMAccessor;
import dev.hephaestus.fiblib.mixin.ChunkReloader;
import dev.hephaestus.fiblib.mixin.TACSAccessor;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -30,4 +40,34 @@ public static void debug(String msg) {
public static void debug(String format, Object... args) {
if (DEBUG) LOGGER.info(String.format("[%s] %s", MOD_NAME, String.format(format, args)));
}

public static void resendChunks(ServerPlayerEntity player) {
ThreadedAnvilChunkStorage TACS = ((TACSAccessor) player.getServerWorld().getChunkManager())
.getThreadedAnvilChunkStorage();


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

if (world != null) {
RegistryKey<World> worldRegistryKey = world.getRegistryKey();

double scale = 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(worldRegistryKey, k, l);
cdsm.invokeSendChunkDataPacketNow(player, chunkPos, (IEThreadedAnvilChunkStorage) TACS);
}
}
}
} else {

((ChunkReloader) TACS).reloadChunks(player, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage;
import dev.hephaestus.fiblib.api.BlockFib;
import dev.hephaestus.fiblib.api.BlockFibRegistry;
import dev.hephaestus.fiblib.impl.FibLib;
import dev.hephaestus.fiblib.impl.LookupTable;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.BlockState;
Expand Down Expand Up @@ -81,31 +82,7 @@ public void tickFibber(BooleanSupplier shouldKeepTicking, CallbackInfo ci) {

if (!updated.isEmpty()) {
for (ServerPlayerEntity player : updated) {
ThreadedAnvilChunkStorage TACS = ((TACSAccessor) player.getServerWorld().getChunkManager())
.getThreadedAnvilChunkStorage();


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);
}
FibLib.resendChunks(player);
}

updated.clear();
Expand Down

0 comments on commit 88f6e5a

Please sign in to comment.