3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-03 01:50:07 +01:00

Updated for support with Sponge Vanilla

Dieser Commit ist enthalten in:
Wyatt Childers 2016-03-22 00:24:02 -04:00
Ursprung 7d957081a9
Commit de0da7d3e9
5 geänderte Dateien mit 65 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -5,16 +5,18 @@ buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
maven { url = "http://files.minecraftforge.net/maven" } maven { url = "http://files.minecraftforge.net/maven" }
maven { url = "http://repo.minecrell.net/snapshots" }
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" } maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'net.minecrell:VanillaGradle:2.0.3-SNAPSHOT'
classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT' classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT'
} }
} }
apply plugin: 'net.minecraftforge.gradle.forge' apply plugin: 'net.minecrell.vanilla.server.library'
dependencies { dependencies {
compile project(':worldedit-core') compile project(':worldedit-core')
@ -37,12 +39,11 @@ sourceCompatibility = 1.8
targetCompatibility = 1.8 targetCompatibility = 1.8
version = "6.1.1" version = "6.1.1"
ext.forgeVersion = "11.15.0.1695"
ext.internalVersion = version + ";" + gitCommitHash ext.internalVersion = version + ";" + gitCommitHash
minecraft { minecraft {
version = "1.8.9-${project.forgeVersion}" version = "1.8.9"
mappings = "snapshot_20160111" mappings = "stable_22"
runDir = 'run' runDir = 'run'
replaceIn "com/sk89q/worldedit/sponge/SpongeWorldEdit.java" replaceIn "com/sk89q/worldedit/sponge/SpongeWorldEdit.java"
@ -55,7 +56,6 @@ processResources {
from (sourceSets.main.resources.srcDirs) { from (sourceSets.main.resources.srcDirs) {
expand 'version': project.version, expand 'version': project.version,
'mcVersion': project.minecraft.version, 'mcVersion': project.minecraft.version,
'forgeVersion': project.forgeVersion,
'internalVersion': project.internalVersion 'internalVersion': project.internalVersion
} }
} }

Datei anzeigen

@ -30,7 +30,7 @@ final class SpongeAdapter {
} }
public static World adapt(org.spongepowered.api.world.World world) { public static World adapt(org.spongepowered.api.world.World world) {
return new SpongeForgeWorld(world); return new SpongeNMSWorld(world);
} }
public static Location adapt(org.spongepowered.api.world.Location<org.spongepowered.api.world.World> loc, Vector3d rot) { public static Location adapt(org.spongepowered.api.world.Location<org.spongepowered.api.world.World> loc, Vector3d rot) {

Datei anzeigen

@ -37,6 +37,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt; import net.minecraft.nbt.NBTTagInt;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos; import net.minecraft.util.BlockPos;
import net.minecraft.util.LongHashMap;
import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.chunk.IChunkProvider;
@ -48,12 +49,14 @@ import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World; import org.spongepowered.api.world.World;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
public class SpongeForgeWorld extends SpongeWorld { public class SpongeNMSWorld extends SpongeWorld {
private static final IBlockState JUNGLE_LOG = Blocks.log.getDefaultState().withProperty(BlockOldLog.VARIANT, BlockPlanks.EnumType.JUNGLE); private static final IBlockState JUNGLE_LOG = Blocks.log.getDefaultState().withProperty(BlockOldLog.VARIANT, BlockPlanks.EnumType.JUNGLE);
private static final IBlockState JUNGLE_LEAF = Blocks.leaves.getDefaultState().withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.JUNGLE).withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(false)); private static final IBlockState JUNGLE_LEAF = Blocks.leaves.getDefaultState().withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.JUNGLE).withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(false));
@ -64,7 +67,7 @@ public class SpongeForgeWorld extends SpongeWorld {
* *
* @param world the world * @param world the world
*/ */
public SpongeForgeWorld(World world) { public SpongeNMSWorld(World world) {
super(world); super(world);
} }
@ -118,10 +121,57 @@ public class SpongeForgeWorld extends SpongeWorld {
return false; return false;
} }
private static <T, K> K getFieldValue(Class<T> clazz, T object, String feildName, Class<K> valueClazz) {
try {
Field field = clazz.getDeclaredField(feildName); // Found in the MCP Mappings
field.setAccessible(true);
return valueClazz.cast(field.get(object));
} catch (NoSuchFieldException | IllegalAccessException e) {
System.out.println("Exception while modifying inaccessible variable: " + e.getMessage());
}
throw new IllegalStateException("Invalid variable state");
}
@SuppressWarnings("unchecked")
@Override @Override
public boolean regenerate(Region region, EditSession editSession) { public boolean regenerate(Region region, EditSession editSession) {
BaseBlock[] history = new BaseBlock[256 * (getMaxY() + 1)]; BaseBlock[] history = new BaseBlock[256 * (getMaxY() + 1)];
IChunkProvider provider = ((net.minecraft.world.World) getWorld()).getChunkProvider();
if (!(provider instanceof ChunkProviderServer)) {
return false;
}
ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
IChunkProvider chunkProvider = getFieldValue(
ChunkProviderServer.class,
chunkServer,
"field_73246_d", // serverChunkGenerator
IChunkProvider.class
);
Set droppedChunksSet = getFieldValue(
ChunkProviderServer.class,
chunkServer,
"field_73248_b", // droppedChunksSet,
Set.class
);
LongHashMap id2ChunkMap = getFieldValue(
ChunkProviderServer.class,
chunkServer,
"field_73244_f", // id2ChunkMap
LongHashMap.class
);
List loadedChunks = getFieldValue(
ChunkProviderServer.class,
chunkServer,
"field_73245_g", // loadedChunks
List.class
);
for (Vector2D chunk : region.getChunks()) { for (Vector2D chunk : region.getChunks()) {
Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16); Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
@ -136,13 +186,6 @@ public class SpongeForgeWorld extends SpongeWorld {
} }
try { try {
Set<Vector2D> chunks = region.getChunks(); Set<Vector2D> chunks = region.getChunks();
IChunkProvider provider = ((net.minecraft.world.World) getWorld()).getChunkProvider();
if (!(provider instanceof ChunkProviderServer)) {
return false;
}
ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
IChunkProvider chunkProvider = chunkServer.serverChunkGenerator;
for (Vector2D coord : chunks) { for (Vector2D coord : chunks) {
long pos = ChunkCoordIntPair.chunkXZ2Int(coord.getBlockX(), coord.getBlockZ()); long pos = ChunkCoordIntPair.chunkXZ2Int(coord.getBlockX(), coord.getBlockZ());
Chunk mcChunk; Chunk mcChunk;
@ -150,11 +193,11 @@ public class SpongeForgeWorld extends SpongeWorld {
mcChunk = chunkServer.loadChunk(coord.getBlockX(), coord.getBlockZ()); mcChunk = chunkServer.loadChunk(coord.getBlockX(), coord.getBlockZ());
mcChunk.onChunkUnload(); mcChunk.onChunkUnload();
} }
chunkServer.droppedChunksSet.remove(pos); droppedChunksSet.remove(pos);
chunkServer.id2ChunkMap.remove(pos); id2ChunkMap.remove(pos);
mcChunk = chunkProvider.provideChunk(coord.getBlockX(), coord.getBlockZ()); mcChunk = chunkProvider.provideChunk(coord.getBlockX(), coord.getBlockZ());
chunkServer.id2ChunkMap.add(pos, mcChunk); id2ChunkMap.add(pos, mcChunk);
chunkServer.loadedChunks.add(mcChunk); loadedChunks.add(mcChunk);
if (mcChunk != null) { if (mcChunk != null) {
mcChunk.onChunkLoad(); mcChunk.onChunkLoad();
mcChunk.populateChunk(chunkProvider, chunkProvider, coord.getBlockX(), coord.getBlockZ()); mcChunk.populateChunk(chunkProvider, chunkProvider, coord.getBlockX(), coord.getBlockZ());

Datei anzeigen

@ -84,7 +84,7 @@ class SpongePlatform extends AbstractPlatform implements MultiUserPlatform {
Collection<org.spongepowered.api.world.World> worlds = Sponge.getServer().getWorlds(); Collection<org.spongepowered.api.world.World> worlds = Sponge.getServer().getWorlds();
List<com.sk89q.worldedit.world.World> ret = new ArrayList<>(worlds.size()); List<com.sk89q.worldedit.world.World> ret = new ArrayList<>(worlds.size());
for (org.spongepowered.api.world.World world : worlds) { for (org.spongepowered.api.world.World world : worlds) {
ret.add(new SpongeForgeWorld(world)); ret.add(new SpongeNMSWorld(world));
} }
return ret; return ret;
} }
@ -108,7 +108,7 @@ class SpongePlatform extends AbstractPlatform implements MultiUserPlatform {
} else { } else {
for (org.spongepowered.api.world.World ws : Sponge.getServer().getWorlds()) { for (org.spongepowered.api.world.World ws : Sponge.getServer().getWorlds()) {
if (ws.getName().equals(world.getName())) { if (ws.getName().equals(world.getName())) {
return new SpongeForgeWorld(ws); return new SpongeNMSWorld(ws);
} }
} }

Datei anzeigen

@ -235,7 +235,7 @@ public class SpongeWorldEdit {
*/ */
public SpongeWorld getWorld(World world) { public SpongeWorld getWorld(World world) {
checkNotNull(world); checkNotNull(world);
return new SpongeForgeWorld(world); return new SpongeNMSWorld(world);
} }
/** /**