diff --git a/worldedit-sponge/build.gradle b/worldedit-sponge/build.gradle index 8aff6e572..8668cee0a 100644 --- a/worldedit-sponge/build.gradle +++ b/worldedit-sponge/build.gradle @@ -5,16 +5,18 @@ buildscript { repositories { mavenCentral() maven { url = "http://files.minecraftforge.net/maven" } + maven { url = "http://repo.minecrell.net/snapshots" } maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" } jcenter() } dependencies { + classpath 'net.minecrell:VanillaGradle:2.0.3-SNAPSHOT' classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT' } } -apply plugin: 'net.minecraftforge.gradle.forge' +apply plugin: 'net.minecrell.vanilla.server.library' dependencies { compile project(':worldedit-core') @@ -37,12 +39,11 @@ sourceCompatibility = 1.8 targetCompatibility = 1.8 version = "6.1.1" -ext.forgeVersion = "11.15.0.1695" ext.internalVersion = version + ";" + gitCommitHash minecraft { - version = "1.8.9-${project.forgeVersion}" - mappings = "snapshot_20160111" + version = "1.8.9" + mappings = "stable_22" runDir = 'run' replaceIn "com/sk89q/worldedit/sponge/SpongeWorldEdit.java" @@ -55,7 +56,6 @@ processResources { from (sourceSets.main.resources.srcDirs) { expand 'version': project.version, 'mcVersion': project.minecraft.version, - 'forgeVersion': project.forgeVersion, 'internalVersion': project.internalVersion } } diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeAdapter.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeAdapter.java index 92a81d380..ab4bceedb 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeAdapter.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeAdapter.java @@ -30,7 +30,7 @@ final class SpongeAdapter { } 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 loc, Vector3d rot) { diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeForgeWorld.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeNMSWorld.java similarity index 82% rename from worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeForgeWorld.java rename to worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeNMSWorld.java index 09d0264bc..2a2a04ac8 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeForgeWorld.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeNMSWorld.java @@ -37,6 +37,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagInt; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; +import net.minecraft.util.LongHashMap; import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.IChunkProvider; @@ -48,12 +49,14 @@ import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; import javax.annotation.Nullable; +import java.lang.reflect.Field; +import java.util.List; import java.util.Set; import java.util.logging.Level; 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_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 */ - public SpongeForgeWorld(World world) { + public SpongeNMSWorld(World world) { super(world); } @@ -118,10 +121,57 @@ public class SpongeForgeWorld extends SpongeWorld { return false; } + private static K getFieldValue(Class clazz, T object, String feildName, Class 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 public boolean regenerate(Region region, EditSession editSession) { 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()) { Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16); @@ -136,13 +186,6 @@ public class SpongeForgeWorld extends SpongeWorld { } try { Set 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) { long pos = ChunkCoordIntPair.chunkXZ2Int(coord.getBlockX(), coord.getBlockZ()); Chunk mcChunk; @@ -150,11 +193,11 @@ public class SpongeForgeWorld extends SpongeWorld { mcChunk = chunkServer.loadChunk(coord.getBlockX(), coord.getBlockZ()); mcChunk.onChunkUnload(); } - chunkServer.droppedChunksSet.remove(pos); - chunkServer.id2ChunkMap.remove(pos); + droppedChunksSet.remove(pos); + id2ChunkMap.remove(pos); mcChunk = chunkProvider.provideChunk(coord.getBlockX(), coord.getBlockZ()); - chunkServer.id2ChunkMap.add(pos, mcChunk); - chunkServer.loadedChunks.add(mcChunk); + id2ChunkMap.add(pos, mcChunk); + loadedChunks.add(mcChunk); if (mcChunk != null) { mcChunk.onChunkLoad(); mcChunk.populateChunk(chunkProvider, chunkProvider, coord.getBlockX(), coord.getBlockZ()); diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlatform.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlatform.java index f390138f7..4b006660e 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlatform.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlatform.java @@ -84,7 +84,7 @@ class SpongePlatform extends AbstractPlatform implements MultiUserPlatform { Collection worlds = Sponge.getServer().getWorlds(); List ret = new ArrayList<>(worlds.size()); for (org.spongepowered.api.world.World world : worlds) { - ret.add(new SpongeForgeWorld(world)); + ret.add(new SpongeNMSWorld(world)); } return ret; } @@ -108,7 +108,7 @@ class SpongePlatform extends AbstractPlatform implements MultiUserPlatform { } else { for (org.spongepowered.api.world.World ws : Sponge.getServer().getWorlds()) { if (ws.getName().equals(world.getName())) { - return new SpongeForgeWorld(ws); + return new SpongeNMSWorld(ws); } } diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java index 8e8c7668a..d6882cb7f 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java @@ -235,7 +235,7 @@ public class SpongeWorldEdit { */ public SpongeWorld getWorld(World world) { checkNotNull(world); - return new SpongeForgeWorld(world); + return new SpongeNMSWorld(world); } /**