Added regen for forge (#23)

This commit is contained in:
Jesse Boyd 2016-04-14 18:07:51 +10:00
parent fff311a99f
commit 04dab97460
8 changed files with 114 additions and 6 deletions

View File

@ -0,0 +1,18 @@
package com.boydti.fawe.object;
public abstract class RunnableVal<T> 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);
}

View File

@ -0,0 +1,20 @@
package com.boydti.fawe.object;
public abstract class RunnableVal2<T, U> 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);
}

View File

@ -0,0 +1,22 @@
package com.boydti.fawe.object;
public abstract class RunnableVal3<T, U, V> 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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -54,6 +54,7 @@ processResources {
'mcVersion': project.minecraft.version
}
}
shadowJar {
dependencies {
include(dependency(':core'))

View File

@ -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<net.minecraft.world.chunk.Chunk> id2ChunkMap = (LongHashMap<net.minecraft.world.chunk.Chunk>) id2ChunkMapField.get(chunkServer);
id2ChunkMap.remove(pos);
mcChunk = chunkProvider.provideChunk(x, z);
id2ChunkMap.add(pos, mcChunk);
List<net.minecraft.world.chunk.Chunk> 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))