Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work on compatibility with porting lib on Fabric #58

Draft
wants to merge 1 commit into
base: mc/1.21.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public final class FabricHooks implements PlatformHooks {

public interface OnExplosionDetonate {
void onExplosion(final Level world, final Explosion explosion, final List<Entity> possiblyAffecting, final double diameter);
public void onExplosion(final Level world, final Explosion explosion, final List<Entity> possiblyAffecting, final double diameter);
}

public static final Event<OnExplosionDetonate> ON_EXPLOSION_DETONATE = EventFactory.createArrayBacked(
Expand All @@ -41,6 +41,32 @@ public interface OnExplosionDetonate {
}
);

public interface OnChunkWatch {
public void onChunkWatch(final ServerLevel world, final LevelChunk chunk, final ServerPlayer player);
}

public static final Event<OnChunkWatch> ON_CHUNK_WATCH = EventFactory.createArrayBacked(
OnChunkWatch.class,
listeners -> (final ServerLevel world, final LevelChunk chunk, final ServerPlayer player) -> {
for (int i = 0; i < listeners.length; i++) {
listeners[i].onChunkWatch(world, chunk, player);
}
}
);

public interface OnChunkUnwatch {
public void onChunkUnwatch(final ServerLevel world, final ChunkPos chunk, final ServerPlayer player);
}

public static final Event<OnChunkUnwatch> ON_CHUNK_UNWATCH = EventFactory.createArrayBacked(
OnChunkUnwatch.class,
listeners -> (final ServerLevel world, final ChunkPos chunk, final ServerPlayer player) -> {
for (int i = 0; i < listeners.length; i++) {
listeners[i].onChunkUnwatch(world, chunk, player);
}
}
);

@Override
public String getBrand() {
return "Moonrise";
Expand Down Expand Up @@ -110,12 +136,12 @@ public void chunkSyncSave(final ServerLevel world, final ChunkAccess chunk, fina

@Override
public void onChunkWatch(final ServerLevel world, final LevelChunk chunk, final ServerPlayer player) {

ON_CHUNK_WATCH.invoker().onChunkWatch(world, chunk, player);
}

@Override
public void onChunkUnWatch(final ServerLevel world, final ChunkPos chunk, final ServerPlayer player) {

ON_CHUNK_UNWATCH.invoker().onChunkUnwatch(world, chunk, player);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ca.spottedleaf.moonrise.fabric.mixin.chunk_system;

import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(Level.class)
abstract class FabricLevelMixin {
/**
* @reason Allow block updates in non-ticking chunks, as new chunk system sends non-ticking chunks to clients
* @author Spottedleaf
*/
@Redirect(
method = "setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;II)Z",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/level/FullChunkStatus;isOrAfter(Lnet/minecraft/server/level/FullChunkStatus;)Z"
)
)
private boolean sendUpdatesForFullChunks(final FullChunkStatus instance,
final FullChunkStatus fullChunkStatus) {

return instance.isOrAfter(FullChunkStatus.FULL);
}
}
1 change: 1 addition & 0 deletions fabric/src/main/resources/moonrise-fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"package": "ca.spottedleaf.moonrise.fabric.mixin",
"mixins": [
"chunk_system.FabricDistanceManagerMixin",
"chunk_system.FabricLevelMixin",
"chunk_system.FabricMinecraftServerMixin",
"chunk_system.FabricServerLevelMixin",
"collisions.EntityMixin"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ca.spottedleaf.moonrise.neoforge.mixin.chunk_system;

import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(Level.class)
abstract class NeoForgeLevelMixin {
/**
* @reason Allow block updates in non-ticking chunks, as new chunk system sends non-ticking chunks to clients
* @author Spottedleaf
*/
@Redirect(
method = {
// "setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;II)Z",
// NeoForge splits logic from the original method into this one
"markAndNotifyBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/chunk/LevelChunk;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;II)V"
},
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/level/FullChunkStatus;isOrAfter(Lnet/minecraft/server/level/FullChunkStatus;)Z"
)
)
private boolean sendUpdatesForFullChunks(final FullChunkStatus instance,
final FullChunkStatus fullChunkStatus) {

return instance.isOrAfter(FullChunkStatus.FULL);
}
}
1 change: 1 addition & 0 deletions neoforge/src/main/resources/moonrise-neoforge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"package": "ca.spottedleaf.moonrise.neoforge.mixin",
"mixins": [
"chunk_system.NeoForgeDistanceManagerMixin",
"chunk_system.NeoForgeLevelMixin",
"chunk_system.NeoForgeMinecraftServerMixin",
"chunk_system.NeoForgeServerLevelMixin",
"collisions.EntityMixin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import ca.spottedleaf.moonrise.patches.chunk_system.level.entity.dfl.DefaultEntityLookup;
import ca.spottedleaf.moonrise.patches.chunk_system.world.ChunkSystemEntityGetter;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
Expand All @@ -28,7 +27,6 @@
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -303,27 +301,6 @@ public BlockPos getHeightmapPos(Heightmap.Types types, BlockPos blockPos) {
return new BlockPos(blockPos.getX(), this.getHeight(types, blockPos.getX(), blockPos.getZ()), blockPos.getZ());
}

/**
* @reason Allow block updates in non-ticking chunks, as new chunk system sends non-ticking chunks to clients
* @author Spottedleaf
*/
@Redirect(
method = {
"setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;II)Z",
// NeoForge splits logic from the original method into this one
"markAndNotifyBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/chunk/LevelChunk;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;II)V"
},
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/level/FullChunkStatus;isOrAfter(Lnet/minecraft/server/level/FullChunkStatus;)Z"
)
)
private boolean sendUpdatesForFullChunks(final FullChunkStatus instance,
final FullChunkStatus fullChunkStatus) {

return instance.isOrAfter(FullChunkStatus.FULL);
}

// TODO: Thread.currentThread() != this.thread to TickThread?


Expand Down