From 04dab97460d3418b20d56d290a15318861bf5d3a Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 14 Apr 2016 18:07:51 +1000 Subject: [PATCH] Added regen for forge (#23) --- .../com/boydti/fawe/object/RunnableVal.java | 18 +++++++ .../com/boydti/fawe/object/RunnableVal2.java | 20 +++++++ .../com/boydti/fawe/object/RunnableVal3.java | 22 ++++++++ .../com/boydti/fawe/util/TaskManager.java | 2 +- .../boydti/fawe/wrappers/WorldWrapper.java | 2 +- .../java/com/sk89q/worldedit/EditSession.java | 2 +- forge/build.gradle | 1 + .../fawe/forge/v1_8/SpongeQueue_1_8.java | 53 +++++++++++++++++-- 8 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 core/src/main/java/com/boydti/fawe/object/RunnableVal.java create mode 100644 core/src/main/java/com/boydti/fawe/object/RunnableVal2.java create mode 100644 core/src/main/java/com/boydti/fawe/object/RunnableVal3.java diff --git a/core/src/main/java/com/boydti/fawe/object/RunnableVal.java b/core/src/main/java/com/boydti/fawe/object/RunnableVal.java new file mode 100644 index 00000000..f1aec1ac --- /dev/null +++ b/core/src/main/java/com/boydti/fawe/object/RunnableVal.java @@ -0,0 +1,18 @@ +package com.boydti.fawe.object; + +public abstract class RunnableVal implements Runnable { + public T value; + + public RunnableVal() {} + + public RunnableVal(T value) { + this.value = value; + } + + @Override + public void run() { + run(this.value); + } + + public abstract void run(T value); +} diff --git a/core/src/main/java/com/boydti/fawe/object/RunnableVal2.java b/core/src/main/java/com/boydti/fawe/object/RunnableVal2.java new file mode 100644 index 00000000..46cc6218 --- /dev/null +++ b/core/src/main/java/com/boydti/fawe/object/RunnableVal2.java @@ -0,0 +1,20 @@ +package com.boydti.fawe.object; + +public abstract class RunnableVal2 implements Runnable { + public T value1; + public U value2; + + public RunnableVal2() {} + + public RunnableVal2(T value1, U value2) { + this.value1 = value1; + this.value2 = value2; + } + + @Override + public void run() { + run(this.value1, this.value2); + } + + public abstract void run(T value1, U value2); +} diff --git a/core/src/main/java/com/boydti/fawe/object/RunnableVal3.java b/core/src/main/java/com/boydti/fawe/object/RunnableVal3.java new file mode 100644 index 00000000..a63b4e1f --- /dev/null +++ b/core/src/main/java/com/boydti/fawe/object/RunnableVal3.java @@ -0,0 +1,22 @@ +package com.boydti.fawe.object; + +public abstract class RunnableVal3 implements Runnable { + public T value1; + public U value2; + public V value3; + + public RunnableVal3() {} + + public RunnableVal3(T value1, U value2, V value3) { + this.value1 = value1; + this.value2 = value2; + this.value3 = value3; + } + + @Override + public void run() { + run(value1, value2, value3); + } + + public abstract void run(T value1, U value2, V value3); +} diff --git a/core/src/main/java/com/boydti/fawe/util/TaskManager.java b/core/src/main/java/com/boydti/fawe/util/TaskManager.java index 242bac99..8bd55f09 100644 --- a/core/src/main/java/com/boydti/fawe/util/TaskManager.java +++ b/core/src/main/java/com/boydti/fawe/util/TaskManager.java @@ -1,6 +1,6 @@ package com.boydti.fawe.util; -import com.intellectualcrafters.plot.object.RunnableVal; +import com.boydti.fawe.object.RunnableVal; import java.util.Collection; import java.util.Iterator; diff --git a/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java b/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java index 71019531..b8acaa1b 100644 --- a/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java +++ b/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java @@ -1,10 +1,10 @@ package com.boydti.fawe.wrappers; import com.boydti.fawe.FaweCache; +import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.changeset.FaweChangeSet; import com.boydti.fawe.util.FaweQueue; import com.boydti.fawe.util.TaskManager; -import com.intellectualcrafters.plot.object.RunnableVal; import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; diff --git a/core/src/main/java/com/sk89q/worldedit/EditSession.java b/core/src/main/java/com/sk89q/worldedit/EditSession.java index cbdab74b..5c3d9d68 100644 --- a/core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -28,6 +28,7 @@ import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.NullChangeSet; import com.boydti.fawe.object.RegionWrapper; +import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.changeset.DiskStorageHistory; import com.boydti.fawe.object.changeset.FaweChangeSet; import com.boydti.fawe.object.changeset.MemoryOptimizedHistory; @@ -43,7 +44,6 @@ import com.boydti.fawe.util.SetQueue; import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.WEManager; import com.boydti.fawe.wrappers.WorldWrapper; -import com.intellectualcrafters.plot.object.RunnableVal; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.BlockType; diff --git a/forge/build.gradle b/forge/build.gradle index f670fa4a..a36e21ac 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -54,6 +54,7 @@ processResources { 'mcVersion': project.minecraft.version } } + shadowJar { dependencies { include(dependency(':core')) diff --git a/forge/src/main/java/com/boydti/fawe/forge/v1_8/SpongeQueue_1_8.java b/forge/src/main/java/com/boydti/fawe/forge/v1_8/SpongeQueue_1_8.java index cf42bd33..964e24e2 100644 --- a/forge/src/main/java/com/boydti/fawe/forge/v1_8/SpongeQueue_1_8.java +++ b/forge/src/main/java/com/boydti/fawe/forge/v1_8/SpongeQueue_1_8.java @@ -9,9 +9,11 @@ import com.boydti.fawe.object.IntegerPair; import com.boydti.fawe.object.PseudoRandom; import com.boydti.fawe.util.TaskManager; import com.flowpowered.math.vector.Vector3i; +import java.lang.reflect.Field; import java.util.ArrayDeque; import java.util.Collection; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -23,7 +25,11 @@ import net.minecraft.network.play.server.S21PacketChunkData; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.ClassInheritanceMultiMap; +import net.minecraft.util.LongHashMap; +import net.minecraft.world.ChunkCoordIntPair; +import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.chunk.storage.ExtendedBlockStorage; +import net.minecraft.world.gen.ChunkProviderServer; import org.spongepowered.api.Sponge; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.world.Chunk; @@ -274,9 +280,6 @@ public class SpongeQueue_1_8 extends SpongeQueue_0 { if (!spongeChunk.loadChunk(false)) { return false; } - } else { - spongeChunk.unloadChunk(); - spongeChunk.loadChunk(false); } nmsChunk.generateSkylightMap(); if (bc.getTotalRelight() == 0 && !fixAll) { @@ -347,6 +350,50 @@ public class SpongeQueue_1_8 extends SpongeQueue_0 { return false; } + @Override + public boolean regenerateChunk(int x, int z) { + if (spongeWorld == null) { + spongeWorld = Sponge.getServer().getWorld(world).get(); + } + try { + net.minecraft.world.World nmsWorld = (net.minecraft.world.World) spongeWorld; + IChunkProvider provider = nmsWorld.getChunkProvider(); + if (!(provider instanceof ChunkProviderServer)) { + return false; + } + ChunkProviderServer chunkServer = (ChunkProviderServer) provider; + Field chunkProviderField = chunkServer.getClass().getDeclaredField("field_73246_d"); + chunkProviderField.setAccessible(true); + IChunkProvider chunkProvider = (IChunkProvider) chunkProviderField.get(chunkServer); + long pos = ChunkCoordIntPair.chunkXZ2Int(x, z); + net.minecraft.world.chunk.Chunk mcChunk; + if (chunkServer.chunkExists(x, z)) { + mcChunk = chunkServer.loadChunk(x, z); + mcChunk.onChunkUnload(); + } + Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b"); + droppedChunksSetField.setAccessible(true); + Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer); + droppedChunksSet.remove(pos); + Field id2ChunkMapField = chunkServer.getClass().getDeclaredField("field_73244_f"); + id2ChunkMapField.setAccessible(true); + LongHashMap id2ChunkMap = (LongHashMap) id2ChunkMapField.get(chunkServer); + id2ChunkMap.remove(pos); + mcChunk = chunkProvider.provideChunk(x, z); + id2ChunkMap.add(pos, mcChunk); + List loadedChunks = chunkServer.func_152380_a(); + loadedChunks.add(mcChunk); + if (mcChunk != null) { + mcChunk.onChunkLoad(); + mcChunk.populateChunk(chunkProvider, chunkProvider, x, z); + } + return true; + } catch (Throwable e) { + e.printStackTrace(); + } + return false; + } + public boolean isSurrounded(ExtendedBlockStorage[] sections, int x, int y, int z) { return isSolid(getId(sections, x, y + 1, z)) && isSolid(getId(sections, x + 1, y - 1, z))