Skip to content

Commit

Permalink
Update to Minecraft 1.17
Browse files Browse the repository at this point in the history
  • Loading branch information
Johni0702 committed Jun 12, 2021
1 parent 0bfbb53 commit d9a0d28
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 2.0.0-SNAPSHOT
- Update to Minecraft 1.17

### 1.2.0
- Support for Sodium 0.2.0
- Add option to disable loading of block entities in fake chunks, active by default
Expand Down
4 changes: 1 addition & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ curseforge {
})
addGameVersion("Fabric")
addGameVersion(minecraftVersion)
addGameVersion("Java 8")
addGameVersion("Java 9")
addGameVersion("Java 10")
addGameVersion("Java 16")
})
options(closureOf<com.matthewprenger.cursegradle.Options> {
javaVersionAutoDetect = false
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ org.gradle.jvmargs=-Xmx2G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraftVersion=1.16.5
minecraftVersion=1.17
yarnMappings=1.17+build.9
loaderVersion=0.11.2
loaderVersion=0.11.3

# Mod Properties
modVersion = 1.2.0
modVersion = 2.0.0-SNAPSHOT
mavenGroup = de.johni0702.minecraft
archivesBaseName = bobby
github.owner = johni0702
Expand All @@ -19,9 +19,9 @@ org.gradle.jvmargs=-Xmx2G
# modrinth.token = ***

# Dependencies
confabricateVersion = 2.0.3
clothConfigVersion = 4.11.14
modMenuVersion = 1.16.8
confabricateVersion = 2.1.0
clothConfigVersion = 5.0.34
modMenuVersion = 2.0.2
# We are compiling against Sodium 0.1.0 but only support 0.2.0 because the current next branch lacks a maven
# publication. To actually develop with Sodium, throw the 0.2.0 version into your mods folder.
sodiumVersion = mc1.16.3-0.1.0
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/de/johni0702/minecraft/bobby/FakeChunkManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourcePackManager;
import net.minecraft.resource.ResourcePackSource;
import net.minecraft.resource.ResourceType;
import net.minecraft.resource.ServerResourceManager;
import net.minecraft.resource.VanillaDataPackProvider;
import net.minecraft.server.MinecraftServer;
Expand Down Expand Up @@ -144,8 +145,9 @@ public void update(BooleanSupplier shouldKeepTicking) {
int oldCenterX = this.centerX;
int oldCenterZ = this.centerZ;
int oldViewDistance = this.viewDistance;
int newCenterX = player.chunkX;
int newCenterZ = player.chunkZ;
ChunkPos playerChunkPos = player.getChunkPos();
int newCenterX = playerChunkPos.x;
int newCenterZ = playerChunkPos.z;
int newViewDistance = client.options.viewDistance;
if (oldCenterX != newCenterX || oldCenterZ != newCenterZ || oldViewDistance != newViewDistance) {
// Firstly check which chunks can be unloaded / cancelled
Expand Down Expand Up @@ -285,9 +287,9 @@ public void load(int x, int z, NbtCompound tag, FakeChunkStorage storage) {
protected void load(int x, int z, WorldChunk chunk) {
fakeChunks.put(ChunkPos.toLong(x, z), chunk);

world.resetChunkColor(x, z);
world.resetChunkColor(new ChunkPos(x, z));

for (int i = 0; i < 16; i++) {
for (int i = world.getBottomSectionCoord(); i < world.getTopSectionCoord(); i++) {
world.scheduleBlockRenders(x, i, z);
}

Expand All @@ -313,9 +315,6 @@ public boolean unload(int x, int z, boolean willBeReplaced) {
}
}

world.blockEntities.removeAll(chunk.getBlockEntities().values());
world.tickingBlockEntities.removeAll(chunk.getBlockEntities().values());

IChunkStatusListener listener = clientChunkManagerExt.bobby_getListener();
if (listener != null) {
listener.onChunkRemoved(x, z);
Expand Down Expand Up @@ -355,9 +354,11 @@ private static BiomeSource getBiomeSource(LevelStorage.Session session) throws E
// How difficult could this possibly be? Oh, right, datapacks are a thing
// Mostly puzzled this together from how MinecraftClient starts the integrated server.
try (ResourcePackManager resourcePackManager = new ResourcePackManager(
ResourceType.SERVER_DATA,
new VanillaDataPackProvider(),
new FileResourcePackProvider(session.getDirectory(WorldSavePath.DATAPACKS).toFile(), ResourcePackSource.PACK_SOURCE_WORLD)
)) {
DynamicRegistryManager.Impl registryTracker = DynamicRegistryManager.create();
DataPackSettings dataPackSettings = MinecraftServer.loadDataPacks(resourcePackManager, MinecraftClient.loadDataPackSettings(session), false);
// We need our own executor, cause the MC one already has lots of packets in it
Thread thread = Thread.currentThread();
Expand All @@ -379,6 +380,7 @@ protected Thread getThread() {
};
CompletableFuture<ServerResourceManager> completableFuture = ServerResourceManager.reload(
resourcePackManager.createResourcePacks(),
registryTracker,
CommandManager.RegistrationEnvironment.INTEGRATED,
2,
Util.getMainWorkerExecutor(),
Expand All @@ -387,7 +389,6 @@ protected Thread getThread() {
executor.runTasks(completableFuture::isDone);
ServerResourceManager serverResourceManager = completableFuture.get();
ResourceManager resourceManager = serverResourceManager.getResourceManager();
DynamicRegistryManager.Impl registryTracker = DynamicRegistryManager.create();
SaveProperties saveProperties = MinecraftClient.createSaveProperties(session, registryTracker, resourceManager, dataPackSettings);
return saveProperties.getGeneratorOptions().getChunkGenerator().getBiomeSource();
}
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/de/johni0702/minecraft/bobby/FakeChunkStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ public NbtCompound serialize(Chunk chunk, LightingProvider lightingProvider) {

BiomeArray biomeArray;
if (level.contains("Biomes", 11)) {
biomeArray = new BiomeArray(world.getRegistryManager().get(Registry.BIOME_KEY), level.getIntArray("Biomes"));
biomeArray = new BiomeArray(world.getRegistryManager().get(Registry.BIOME_KEY), world, level.getIntArray("Biomes"));
} else if (biomeSource != null) {
biomeArray = new BiomeArray(world.getRegistryManager().get(Registry.BIOME_KEY), chunkPos, biomeSource);
biomeArray = new BiomeArray(world.getRegistryManager().get(Registry.BIOME_KEY), world, chunkPos, biomeSource);
} else {
LOGGER.error("Chunk file at {} has neither Biomes key nor biomeSource.", pos);
return null;
}
NbtList sectionsTag = level.getList("Sections", 10);
ChunkSection[] chunkSections = new ChunkSection[16];
ChunkSection[] chunkSections = new ChunkSection[world.countVerticalSections()];
ChunkNibbleArray[] blockLight = new ChunkNibbleArray[chunkSections.length];
ChunkNibbleArray[] skyLight = new ChunkNibbleArray[chunkSections.length];

Expand All @@ -200,16 +200,16 @@ public NbtCompound serialize(Chunk chunk, LightingProvider lightingProvider) {
sectionTag.getLongArray("BlockStates"));
chunkSection.calculateCounts();
if (!chunkSection.isEmpty()) {
chunkSections[y] = chunkSection;
chunkSections[world.sectionCoordToIndex(y)] = chunkSection;
}
}

if (sectionTag.contains("BlockLight", 7)) {
blockLight[y] = new ChunkNibbleArray(sectionTag.getByteArray("BlockLight"));
blockLight[world.sectionCoordToIndex(y)] = new ChunkNibbleArray(sectionTag.getByteArray("BlockLight"));
}

if (sectionTag.contains("SkyLight", 7)) {
skyLight[y] = new ChunkNibbleArray(sectionTag.getByteArray("SkyLight"));
skyLight[world.sectionCoordToIndex(y)] = new ChunkNibbleArray(sectionTag.getByteArray("SkyLight"));
}
}

Expand Down Expand Up @@ -279,12 +279,13 @@ public NbtCompound serialize(Chunk chunk, LightingProvider lightingProvider) {
ChunkLightProviderExt blockLightProvider = (ChunkLightProviderExt) lightingProvider.getBlockLightProvider();
ChunkLightProviderExt skyLightProvider = (ChunkLightProviderExt) lightingProvider.getSkyLightProvider();

for (int y = 0; y < chunkSections.length; y++) {
for (int i = 0; i < chunkSections.length; i++) {
int y = world.sectionIndexToCoord(i);
if (blockLightProvider != null) {
blockLightProvider.bobby_addSectionData(ChunkSectionPos.from(pos, y).asLong(), blockLight[y]);
blockLightProvider.bobby_addSectionData(ChunkSectionPos.from(pos, y).asLong(), blockLight[i]);
}
if (skyLightProvider != null && hasSkyLight) {
skyLightProvider.bobby_addSectionData(ChunkSectionPos.from(pos, y).asLong(), skyLight[y]);
skyLightProvider.bobby_addSectionData(ChunkSectionPos.from(pos, y).asLong(), skyLight[i]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.BitSet;

@Mixin(ClientChunkManager.class)
public abstract class ClientChunkManagerMixin implements IClientChunkManager, ClientChunkManagerExt {
@Shadow @Final private WorldChunk emptyChunk;
Expand Down Expand Up @@ -80,7 +82,7 @@ private void bobbyGetChunk(int x, int z, ChunkStatus chunkStatus, boolean orEmpt
}

@Inject(method = "loadChunkFromPacket", at = @At("HEAD"))
private void bobbyUnloadFakeChunk(int x, int z, BiomeArray biomes, PacketByteBuf buf, NbtCompound tag, int verticalStripBitmask, boolean complete, CallbackInfoReturnable<WorldChunk> cir) {
private void bobbyUnloadFakeChunk(int x, int z, BiomeArray biomes, PacketByteBuf buf, NbtCompound nbt, BitSet bitSet, CallbackInfoReturnable<WorldChunk> cir) {
if (bobbyChunkManager == null) {
return;
}
Expand All @@ -98,7 +100,7 @@ private void bobbyUnloadFakeChunk(int x, int z, BiomeArray biomes, PacketByteBuf
}

@Inject(method = "loadChunkFromPacket", at = @At("RETURN"))
private void bobbyFakeChunkReplaced(int x, int z, BiomeArray biomes, PacketByteBuf buf, NbtCompound tag, int verticalStripBitmask, boolean complete, CallbackInfoReturnable<WorldChunk> cir) {
private void bobbyFakeChunkReplaced(int x, int z, BiomeArray biomes, PacketByteBuf buf, NbtCompound nbt, BitSet bitSet, CallbackInfoReturnable<WorldChunk> cir) {
IChunkStatusListener listener = bobby_restoreListener();
if (listener != null) {
// However, if we failed to load the chunk from the packet for whatever reason,
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/bobby.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"required": true,
"minVersion": "0.8",
"package": "de.johni0702.minecraft.bobby.mixin",
"compatibilityLevel": "JAVA_8",
"compatibilityLevel": "JAVA_16",
"plugin": "de.johni0702.minecraft.bobby.MixinConfigPlugin",
"client": [
"BiomeAccessAccessor",
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
],

"depends": {
"fabricloader": ">=0.7.4",
"minecraft": "1.16.x"
"fabricloader": ">=0.11.3",
"minecraft": "1.17.x"
},
"suggests": {
"cloth-config2": "^${clothConfigVersion}",
Expand Down

0 comments on commit d9a0d28

Please sign in to comment.