mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Updated for support with Sponge Vanilla
This commit is contained in:
parent
7d957081a9
commit
de0da7d3e9
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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<org.spongepowered.api.world.World> loc, Vector3d rot) {
|
||||
|
@ -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 <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
|
||||
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<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) {
|
||||
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());
|
@ -84,7 +84,7 @@ class SpongePlatform extends AbstractPlatform implements MultiUserPlatform {
|
||||
Collection<org.spongepowered.api.world.World> worlds = Sponge.getServer().getWorlds();
|
||||
List<com.sk89q.worldedit.world.World> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,7 +235,7 @@ public class SpongeWorldEdit {
|
||||
*/
|
||||
public SpongeWorld getWorld(World world) {
|
||||
checkNotNull(world);
|
||||
return new SpongeForgeWorld(world);
|
||||
return new SpongeNMSWorld(world);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user