-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reimplement things on latest upstream
- Loading branch information
Showing
20 changed files
with
269 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
common/src/main/java/org/popcraft/chunky/iterator/WrappingChunkedChunkIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.popcraft.chunky.iterator; | ||
|
||
import org.popcraft.chunky.Selection; | ||
import org.popcraft.chunky.util.ChunkCoordinate; | ||
|
||
import java.util.LinkedList; | ||
import java.util.Queue; | ||
|
||
public class WrappingChunkedChunkIterator implements ChunkIterator { | ||
|
||
private static final int CHUNK_SIZE = 8; | ||
private final ChunkIterator delegatingIterator; | ||
private final Queue<ChunkCoordinate> queue = new LinkedList<>(); | ||
private final int centerChunkX; | ||
private final int centerChunkZ; | ||
|
||
public WrappingChunkedChunkIterator(Selection selection, long count) { | ||
this.centerChunkX = selection.centerChunkX(); | ||
this.centerChunkZ = selection.centerChunkZ(); | ||
delegatingIterator = ChunkIteratorFactory.getChunkIterator(new Selection( | ||
selection.world(), | ||
0, | ||
0, | ||
Math.ceil(selection.radiusX() / (double) CHUNK_SIZE), | ||
Math.ceil(selection.radiusZ() / (double) CHUNK_SIZE), | ||
selection.pattern(), | ||
selection.shape() | ||
), (long) Math.ceil(count / (double) (CHUNK_SIZE * CHUNK_SIZE))); | ||
System.out.println(String.format("WrappingChunkedIterator: %s", this.name())); | ||
} | ||
|
||
@Override | ||
public long total() { | ||
return delegatingIterator.total() * CHUNK_SIZE * CHUNK_SIZE; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return String.format("chunked_%s", delegatingIterator.name()); | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return !queue.isEmpty() || delegatingIterator.hasNext(); | ||
} | ||
|
||
private void fillQueue() { | ||
final ChunkCoordinate areaCoordinate = delegatingIterator.next(); | ||
for (int x = 0; x < CHUNK_SIZE; x ++) | ||
for (int z = 0; z < CHUNK_SIZE; z ++) | ||
queue.add(new ChunkCoordinate(areaCoordinate.x * CHUNK_SIZE + x + centerChunkX, areaCoordinate.z * CHUNK_SIZE + z + centerChunkZ)); | ||
} | ||
|
||
@Override | ||
public synchronized ChunkCoordinate next() { | ||
if (queue.isEmpty()) fillQueue(); | ||
assert !queue.isEmpty(); | ||
return queue.poll(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
fabric/src/main/java/org/popcraft/chunky/events/SchedulingUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.popcraft.chunky.events; | ||
|
||
import java.util.concurrent.ConcurrentLinkedQueue; | ||
import java.util.concurrent.Executor; | ||
|
||
public class SchedulingUtil { | ||
|
||
private static final ConcurrentLinkedQueue<Runnable> tickEnd = new ConcurrentLinkedQueue<>(); | ||
public static final Executor tickEndExecutor = tickEnd::add; | ||
|
||
public static void invokeTickEnd() { | ||
Runnable runnable; | ||
while ((runnable = tickEnd.poll()) != null) { | ||
try { | ||
runnable.run(); | ||
} catch (Throwable t) { | ||
t.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
private SchedulingUtil() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
fabric/src/main/java/org/popcraft/chunky/mixin/events/MixinCommandManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.popcraft.chunky.mixin.events; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.command.CommandManager; | ||
import net.minecraft.server.command.ServerCommandSource; | ||
import org.popcraft.chunky.ChunkyFabric; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(CommandManager.class) | ||
public class MixinCommandManager { | ||
|
||
@Shadow @Final private CommandDispatcher<ServerCommandSource> dispatcher; | ||
|
||
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/CommandDispatcher;findAmbiguities(Lcom/mojang/brigadier/AmbiguityConsumer;)V", shift = At.Shift.BEFORE)) | ||
private void onCommandRegister(CallbackInfo ci) { | ||
try { | ||
ChunkyFabric.COMMAND_REGISTER.accept(this.dispatcher); | ||
} catch (Throwable t) { | ||
t.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.