Skip to content

Commit

Permalink
Port to Minecraft 1.8.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Grayray75 committed Aug 23, 2023
1 parent 1637e21 commit c3fffc2
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 87 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ modrinth {

projectId = "fLCmgUPa"
versionNumber = "${project.mod_version}"
versionName = "Phosphor-Legacy v${project.mod_version} (1.12.2)"
versionType = "release"
versionName = "Phosphor-Legacy v${project.mod_version} (1.8.9)"
versionType = "beta"
changelog = "Initial release"

uploadFile = remapJar
gameVersions = ["1.12.2"]
gameVersions = ["1.8.9"]
loaders = ["fabric"]
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# https://grayray75.github.io/LegacyFabric-Versions/
minecraft_version=1.12.2
minecraft_version=1.8.9
yarn_mappings_build=524
loader_version=0.14.22

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ChunkDataS2CPacket.class)
public abstract class ChunkDataS2CPacketMixin {
/**
* Injects a callback into SPacketChunkData#calculateChunkSize(Chunk, booolean, int) to force light updates to be
* processed before creating the client payload. We use this method rather than the constructor as it is not valid
* to inject elsewhere other than the RETURN of a ctor, which is too late for our needs.
* Injects a callback into the constructor of ChunkDataS2CPacketMixin to force light updates to be
* processed before creating the client payload.
*
* @author JellySquid
*/
@Inject(method = "method_12656", at = @At("HEAD"))
private void onCalculateChunkSize(Chunk chunkIn, boolean hasSkyLight, int changedSectionFilter, CallbackInfoReturnable<Integer> cir) {
((ILightingEngineProvider) chunkIn).getLightingEngine().processLightUpdates();
@Inject(method = "createExtraData", at = @At("HEAD"))
private static void onCalculateChunkSize(Chunk chunk, boolean load, boolean notNether, int i, CallbackInfoReturnable<ChunkDataS2CPacket.ExtraData> cir) {
((ILightingEngineProvider) chunk).getLightingEngine().processLightUpdates();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private void method_3917(int x, int y, int z) {
if (j != i) {
this.heightmap[z << 4 | x] = j;

if (this.world.dimension.isOverworld()) {
if (!this.world.dimension.isNether()) {
LightingHooks.relightSkylightColumn(this.world, (Chunk) (Object) this, x, z, i, j);
}

Expand Down Expand Up @@ -335,7 +335,7 @@ public int getCachedLightFor(LightType lightType, BlockPos pos) {

ChunkSection section = this.chunkSections[j >> 4];

if (section == Chunk.EMPTY) {
if (section == null) {
if (this.hasDirectSunlight(pos)) {
return lightType.defaultValue;
}
Expand All @@ -346,8 +346,12 @@ public int getCachedLightFor(LightType lightType, BlockPos pos) {
else if (lightType == LightType.SKY) {
// In Minecraft there is no dimension.hasSkyLight() function, I guess it was added by forge
// Because this checks if the dimension can see the sky, I guess it looks for the nether and end?
//
// 1.8.9 Note: isOverworld() doesn't exist here so i'm using !isNether()
// It should be noted that isNether() is named wrong it should be hasNoSky (MCP) or so
//
//if (!this.world.dimension.hasSkyLight()) {
if (!this.world.dimension.isOverworld()) {
if (this.world.dimension.isNether()) {
return 0;
}
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.jellysquid.mods.phosphor.mixins.common;

import net.minecraft.util.collection.LongObjectStorage;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ClientChunkProvider;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(ClientChunkProvider.class)
public interface ClientChunkProviderAccessor {
@Accessor("chunkStorage")
LongObjectStorage<Chunk> getChunkStorage();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.jellysquid.mods.phosphor.mixins.common;

import net.minecraft.util.collection.LongObjectStorage;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ServerChunkProvider;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(ServerChunkProvider.class)
public interface ServerChunkProviderAccessor {
@Accessor("chunkMap")
LongObjectStorage<Chunk> getChunkStorage();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import me.jellysquid.mods.phosphor.api.ILightingEngineProvider;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ProgressListener;
import net.minecraft.util.collection.LongObjectStorage;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ServerChunkProvider;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
Expand All @@ -15,20 +19,18 @@
@Mixin(ServerChunkProvider.class)
public abstract class ServerChunkProviderMixin {
@Shadow
@Final
private ServerWorld world;

@Shadow
@Final
private Set<Long> chunksToUnload;

/**
* Injects a callback into the start of saveChunks(boolean) to force all light updates to be processed before saving.
*
* @author JellySquid
*/
@Inject(method = "method_12776", at = @At("HEAD"))
private void onSaveChunks(boolean all, CallbackInfoReturnable<Boolean> cir) {
@Inject(method = "saveChunks", at = @At("HEAD"))
private void onSaveChunks(boolean saveEntities, ProgressListener progressListener, CallbackInfoReturnable<Boolean> cir) {
((ILightingEngineProvider) this.world).getLightingEngine().processLightUpdates();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package me.jellysquid.mods.phosphor.mod.world;

import me.jellysquid.mods.phosphor.mixins.common.ClientChunkProviderAccessor;
import me.jellysquid.mods.phosphor.mixins.common.ServerChunkProviderAccessor;
import net.minecraft.util.collection.LongObjectStorage;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkProvider;
import net.minecraft.world.chunk.ClientChunkProvider;
import net.minecraft.world.chunk.ServerChunkProvider;

public class ChunkHelper {
public static Chunk getLoadedChunk(ChunkProvider chunkProvider, int x, int z) {
if (chunkProvider instanceof ServerChunkProvider) {
LongObjectStorage<Chunk> chunkStorage = ((ServerChunkProviderAccessor) chunkProvider).getChunkStorage();
return chunkStorage.get(ChunkPos.getIdFromCoords(x, z));
}
if (chunkProvider instanceof ClientChunkProvider) {
LongObjectStorage<Chunk> chunkStorage = ((ClientChunkProviderAccessor) chunkProvider).getChunkStorage();
return chunkStorage.get(ChunkPos.getIdFromCoords(x, z));
}

// Fallback for other providers, hopefully this doesn't break...
return chunkProvider.getChunk(x, z);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public WorldChunkSlice(World world, int x, int z) {

for (int xDiff = -radius; xDiff <= radius; xDiff++) {
for (int zDiff = -radius; zDiff <= radius; zDiff++) {
this.chunks[((xDiff + radius) * DIAMETER) + (zDiff + radius)] = world.getChunkProvider().getLoadedChunk(x + xDiff, z + zDiff);
this.chunks[((xDiff + radius) * DIAMETER) + (zDiff + radius)] = ChunkHelper.getLoadedChunk(world.getChunkProvider(),x + xDiff, z + zDiff);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.jellysquid.mods.phosphor.mixins.DirectionAccessor;
import me.jellysquid.mods.phosphor.mod.PhosphorMod;
import me.jellysquid.mods.phosphor.mod.collections.PooledLongQueue;
import me.jellysquid.mods.phosphor.mod.world.ChunkHelper;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.BlockState;
Expand Down Expand Up @@ -425,7 +426,7 @@ private static int getCachedLightFor(Chunk chunk, ChunkSection section, BlockPos
int j = pos.getY();
int k = pos.getZ() & 15;

if (section == Chunk.EMPTY) {
if (section == null) {
if (lightType == LightType.SKY && chunk.hasDirectSunlight(pos)) {
return lightType.defaultValue;
}
Expand All @@ -434,7 +435,7 @@ private static int getCachedLightFor(Chunk chunk, ChunkSection section, BlockPos
}
}
else if (lightType == LightType.SKY) {
if (!chunk.getWorld().dimension.isOverworld()) {
if (chunk.getWorld().dimension.isNether()) {
return 0;
}
else {
Expand Down Expand Up @@ -596,15 +597,15 @@ private int getCursorLuminosity(final BlockState state, final LightType lightTyp
}
}

return MathHelper.clamp(state.getLuminance(), 0, MAX_LIGHT);
return MathHelper.clamp(state.getBlock().getLightLevel(), 0, MAX_LIGHT);
}

private int getPosOpacity(final BlockPos pos, final BlockState state) {
return MathHelper.clamp(state.getOpacity(), 1, MAX_LIGHT);
return MathHelper.clamp(state.getBlock().getOpacity(), 1, MAX_LIGHT);
}

private Chunk getChunk(final BlockPos pos) {
return this.world.getChunkProvider().getLoadedChunk(pos.getX() >> 4, pos.getZ() >> 4);
return ChunkHelper.getLoadedChunk(this.world.getChunkProvider(),pos.getX() >> 4, pos.getZ() >> 4);
}

private static class NeighborInfo {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.jellysquid.mods.phosphor.mod.world.lighting;

import me.jellysquid.mods.phosphor.mixins.ChunkSectionAccessor;
import me.jellysquid.mods.phosphor.mixins.PaletteContainerAccessor;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
Expand All @@ -21,15 +20,11 @@ public static BlockState posToState(final BlockPos pos, final ChunkSection secti
final int y = pos.getY();
final int z = pos.getZ();

if (section != Chunk.EMPTY) {
int i = ((PaletteContainerAccessor) ((ChunkSectionAccessor) section).getData()).getStorage().get((y & 15) << 8 | (z & 15) << 4 | x & 15);
if (section != null) {
BlockState state = Block.BLOCK_STATES.fromId(section.getBlockStates()[(y & 15) << 8 | (z & 15) << 4 | x & 15]);

if (i != 0) {
BlockState state = ((PaletteContainerAccessor) ((ChunkSectionAccessor) section).getData()).getPalette().getStateForId(i);

if (state != null) {
return state;
}
if (state != null) {
return state;
}
}

Expand Down
Loading

0 comments on commit c3fffc2

Please sign in to comment.