Merge branch 'feature/forge1.8'

This commit is contained in:
Kenzie Togami 2016-03-19 09:42:50 -07:00
commit 219d2da0ff
33 changed files with 1078 additions and 1278 deletions

View File

@ -10,7 +10,7 @@ jdk:
- openjdk6 - openjdk6
# Caching for Gradle files, prevents hitting Maven too much. # Caching for Gradle files, prevents hitting Maven too much.
before_cache: before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock - find $HOME/.gradle/ -name '*.lock' -print -exec rm -f {} \;
cache: cache:
directories: directories:
- $HOME/.gradle/caches/ - $HOME/.gradle/caches/

View File

@ -26,9 +26,9 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.0' classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1' classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1'
classpath 'org.ajoberstar:gradle-git:0.12.0' classpath 'org.ajoberstar:gradle-git:1.4.2'
} }
} }
@ -36,14 +36,19 @@ if (!project.hasProperty("artifactory_contextUrl")) ext.artifactory_contextUrl =
if (!project.hasProperty("artifactory_user")) ext.artifactory_user = "guest" if (!project.hasProperty("artifactory_user")) ext.artifactory_user = "guest"
if (!project.hasProperty("artifactory_password")) ext.artifactory_password = "" if (!project.hasProperty("artifactory_password")) ext.artifactory_password = ""
if (!project.hasProperty("gitCommitHash")) { if (!project.hasProperty("gitCommitHash") && !JavaVersion.current().isJava6()) {
try { try {
def repo = Grgit.open(project.file('.')) def Grgit = Class.forName("org.ajoberstar.grgit.Grgit");
def Grgit_open = Grgit.getDeclaredMethod("open", File.class)
def repo = Grgit_open.invoke(null, project.file('.'))
ext.gitCommitHash = repo.head().abbreviatedId ext.gitCommitHash = repo.head().abbreviatedId
} catch (Exception e) { } catch (Exception e) {
ext.gitCommitHash = "no_git_id" println "Error getting commit hash: " + e.getMessage()
} }
} }
if (!project.hasProperty("gitCommitHash")) {
ext.gitCommitHash = "no_git_id"
}
subprojects { subprojects {
apply plugin: 'java' apply plugin: 'java'
@ -75,11 +80,6 @@ subprojects {
} }
} }
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) { task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc' classifier = 'javadoc'
from javadoc.destinationDir from javadoc.destinationDir
@ -87,13 +87,23 @@ subprojects {
artifacts { artifacts {
archives jar archives jar
archives sourcesJar
archives javadocJar archives javadocJar
} }
if (!name.equals('worldedit-forge')) {
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
build.dependsOn(sourcesJar)
}
build.dependsOn(checkstyleMain) build.dependsOn(checkstyleMain)
build.dependsOn(checkstyleTest) build.dependsOn(checkstyleTest)
build.dependsOn(sourcesJar)
build.dependsOn(javadocJar) build.dependsOn(javadocJar)
shadowJar { shadowJar {

View File

@ -48,13 +48,14 @@
</subpackage> </subpackage>
<subpackage name="forge"> <subpackage name="forge">
<allow pkg="codechicken.multipart"/>
<allow pkg="cpw"/> <allow pkg="cpw"/>
<allow pkg="net.minecraft"/> <allow pkg="net.minecraft"/>
<allow pkg="net.minecraftforge"/> <allow pkg="net.minecraftforge"/>
<allow pkg="com.mojang.authlib"/> <allow pkg="com.mojang.authlib"/>
<allow pkg="org.apache.logging.log4j"/> <allow pkg="org.apache.logging.log4j"/>
<allow pkg="org.lwjgl"/> <allow pkg="org.lwjgl"/>
<allow pkg="io.netty.buffer"/>
<allow pkg="org.spongepowered.api" />
</subpackage> </subpackage>
</subpackage> </subpackage>
</import-control> </import-control>

Binary file not shown.

View File

@ -1,6 +1,6 @@
#Mon Apr 07 22:45:51 PDT 2014 #Mon Feb 22 17:40:44 PST 2016
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.0-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-bin.zip

10
gradlew vendored
View File

@ -42,11 +42,6 @@ case "`uname`" in
;; ;;
esac esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME # Attempt to set APP_HOME
# Resolve links: $0 may be a link # Resolve links: $0 may be a link
PRG="$0" PRG="$0"
@ -61,9 +56,9 @@ while [ -h "$PRG" ] ; do
fi fi
done done
SAVED="`pwd`" SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&- cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`" APP_HOME="`pwd -P`"
cd "$SAVED" >&- cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
@ -114,6 +109,7 @@ fi
if $cygwin ; then if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"` APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath # We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`

180
gradlew.bat vendored
View File

@ -1,90 +1,90 @@
@if "%DEBUG%" == "" @echo off @if "%DEBUG%" == "" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@rem Gradle startup script for Windows @rem Gradle startup script for Windows
@rem @rem
@rem ########################################################################## @rem ##########################################################################
@rem Set local scope for the variables with windows NT shell @rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS= set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0 set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=. if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@rem Find java.exe @rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init if "%ERRORLEVEL%" == "0" goto init
echo. echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo. echo.
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation. echo location of your Java installation.
goto fail goto fail
:findJavaFromJavaHome :findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=% set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init if exist "%JAVA_EXE%" goto init
echo. echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo. echo.
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation. echo location of your Java installation.
goto fail goto fail
:init :init
@rem Get command-line arguments, handling Windowz variants @rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args :win9xME_args
@rem Slurp the command line arguments. @rem Slurp the command line arguments.
set CMD_LINE_ARGS= set CMD_LINE_ARGS=
set _SKIP=2 set _SKIP=2
:win9xME_args_slurp :win9xME_args_slurp
if "x%~1" == "x" goto execute if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%* set CMD_LINE_ARGS=%*
goto execute goto execute
:4NT_args :4NT_args
@rem Get arguments from the 4NT Shell from JP Software @rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$ set CMD_LINE_ARGS=%$
:execute :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd if "%ERRORLEVEL%"=="0" goto mainEnd
:fail :fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code! rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1 exit /b 1
:mainEnd :mainEnd
if "%OS%"=="Windows_NT" endlocal if "%OS%"=="Windows_NT" endlocal
:omega :omega

View File

@ -7,28 +7,33 @@ buildscript {
} }
dependencies { dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT' classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT'
} }
} }
apply plugin: 'forge' apply plugin: 'net.minecraftforge.gradle.forge'
repositories {
maven {
name 'forge'
url 'http://files.minecraftforge.net/maven/'
}
}
dependencies { dependencies {
compile project(':worldedit-core') compile project(':worldedit-core')
compile group: 'codechicken', name: 'ForgeMultipart', version: '1.7.10-1.2.0.345', classifier: 'dev' compile 'org.spongepowered:spongeapi:3.1.0-SNAPSHOT'
testCompile group: 'org.mockito', name: 'mockito-core', version: '1.9.0-rc1' testCompile group: 'org.mockito', name: 'mockito-core', version: '1.9.0-rc1'
} }
repositories {
maven {
name = "Sponge"
url = "https://repo.spongepowered.org/maven"
}
}
version = "6.1.1"
ext.forgeVersion = "11.15.1.1760"
ext.internalVersion = version + ";" + gitCommitHash
minecraft { minecraft {
ext.forgeVersion = "10.13.4.1614-1.7.10" version = "1.8.9-${project.forgeVersion}"
version = "1.7.10-$forgeVersion" mappings = "snapshot_20160111"
runDir = 'run'
replaceIn "com/sk89q/worldedit/forge/ForgeWorldEdit.java" replaceIn "com/sk89q/worldedit/forge/ForgeWorldEdit.java"
replace "%VERSION%", project.version replace "%VERSION%", project.version
@ -39,8 +44,8 @@ project.archivesBaseName = "${project.archivesBaseName}-mc${minecraft.version}"
processResources { 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.minecraft.forgeVersion, 'forgeVersion': project.forgeVersion,
'internalVersion': project.internalVersion 'internalVersion': project.internalVersion
include 'mcmod.info' include 'mcmod.info'
} }
@ -53,7 +58,8 @@ processResources {
jar { jar {
manifest { manifest {
attributes("Class-Path": "truezip.jar WorldEdit/truezip.jar js.jar WorldEdit/js.jar", attributes("Class-Path": "truezip.jar WorldEdit/truezip.jar js.jar WorldEdit/js.jar",
"WorldEdit-Version": version) "WorldEdit-Version": version,
"FMLAT": "worldedit_at.cfg")
} }
} }
@ -63,8 +69,10 @@ shadowJar {
} }
} }
reobf.reobf(shadowJar) { spec -> reobf {
spec.classpath = sourceSets.main.compileClasspath; shadowJar {
mappingType = 'SEARGE'
}
} }
task deobfJar(type: Jar) { task deobfJar(type: Jar) {
@ -75,5 +83,3 @@ task deobfJar(type: Jar) {
artifacts { artifacts {
archives deobfJar archives deobfJar
} }
build.dependsOn(shadowJar)

View File

@ -19,14 +19,14 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import cpw.mods.fml.common.FMLCommonHandler; import net.minecraftforge.common.MinecraftForge;
public class ClientProxy extends CommonProxy { public class ClientProxy extends CommonProxy {
@Override @Override
public void registerHandlers() { public void registerHandlers() {
super.registerHandlers(); super.registerHandlers();
FMLCommonHandler.instance().bus().register(new KeyHandler()); MinecraftForge.EVENT_BUS.register(new KeyHandler());
} }
} }

View File

@ -19,18 +19,14 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.google.common.base.Joiner;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
import com.sk89q.worldedit.util.command.CommandMapping; import com.sk89q.worldedit.util.command.CommandMapping;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.command.CommandBase; import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommand; import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender; import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
public class CommandWrapper extends CommandBase { public class CommandWrapper extends CommandBase {
private CommandMapping command; private CommandMapping command;
@ -52,17 +48,6 @@ public class CommandWrapper extends CommandBase {
@Override @Override
public void processCommand(ICommandSender var1, String[] var2) {} public void processCommand(ICommandSender var1, String[] var2) {}
@Override
public List addTabCompletionOptions(ICommandSender sender, String[] arguments) {
if (sender instanceof EntityPlayerMP) {
CommandSuggestionEvent event = new CommandSuggestionEvent(ForgeWorldEdit.inst.wrap((EntityPlayerMP) sender), command.getPrimaryAlias() + " " + Joiner.on(" ").join(arguments));
WorldEdit.getInstance().getEventBus().post(event);
return event.getSuggestions();
} else {
return super.addTabCompletionOptions(sender, arguments);
}
}
@Override @Override
public String getCommandUsage(ICommandSender icommandsender) { public String getCommandUsage(ICommandSender icommandsender) {
return "/" + command.getPrimaryAlias() + " " + command.getDescription().getUsage(); return "/" + command.getPrimaryAlias() + " " + command.getDescription().getUsage();
@ -79,7 +64,7 @@ public class CommandWrapper extends CommandBase {
} }
@Override @Override
public int compareTo(@Nullable Object o) { public int compareTo(@Nullable ICommand o) {
if (o == null) { if (o == null) {
return 0; return 0;
} else if (o instanceof ICommand) { } else if (o instanceof ICommand) {

View File

@ -19,8 +19,9 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import com.sk89q.worldedit.forge.gui.GuiHandler; import com.sk89q.worldedit.forge.gui.GuiHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
public class CommonProxy { public class CommonProxy {

View File

@ -20,10 +20,9 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import net.minecraft.util.BlockPos;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
import net.minecraftforge.common.util.ForgeDirection;
final class ForgeAdapter { final class ForgeAdapter {
@ -38,15 +37,16 @@ final class ForgeAdapter {
return new Vector(vector.xCoord, vector.yCoord, vector.zCoord); return new Vector(vector.xCoord, vector.yCoord, vector.zCoord);
} }
public static int adapt(Direction face) { public static Vector adapt(BlockPos pos) {
switch (face) { return new Vector(pos.getX(), pos.getY(), pos.getZ());
case NORTH: return ForgeDirection.NORTH.ordinal();
case SOUTH: return ForgeDirection.SOUTH.ordinal();
case WEST: return ForgeDirection.WEST.ordinal();
case EAST: return ForgeDirection.EAST.ordinal();
case UP: return ForgeDirection.UP.ordinal();
case DOWN: return ForgeDirection.DOWN.ordinal();
default: return ForgeDirection.UNKNOWN.ordinal();
}
} }
public static Vec3 toVec3(Vector vector) {
return new Vec3(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
}
public static BlockPos toBlockPos(Vector vector) {
return new BlockPos(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
}
} }

View File

@ -1,45 +1,45 @@
/* /*
* WorldEdit, a Minecraft world manipulation toolkit * WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com> * Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors * Copyright (C) WorldEdit team and contributors
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the * under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or * Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.util.PropertiesConfiguration; import com.sk89q.worldedit.util.PropertiesConfiguration;
import java.io.File; import java.io.File;
public class ForgeConfiguration extends PropertiesConfiguration { public class ForgeConfiguration extends PropertiesConfiguration {
public boolean creativeEnable = false; public boolean creativeEnable = false;
public boolean cheatMode = false; public boolean cheatMode = false;
public ForgeConfiguration(ForgeWorldEdit mod) { public ForgeConfiguration(ForgeWorldEdit mod) {
super(new File(mod.getWorkingDir() + File.separator + "worldedit.properties")); super(new File(mod.getWorkingDir() + File.separator + "worldedit.properties"));
} }
@Override @Override
protected void loadExtra() { protected void loadExtra() {
creativeEnable = getBool("use-in-creative", false); creativeEnable = getBool("use-in-creative", false);
cheatMode = getBool("cheat-mode", false); cheatMode = getBool("cheat-mode", false);
} }
@Override @Override
public File getWorkingDirectory() { public File getWorkingDirectory() {
return ForgeWorldEdit.inst.getWorkingDir(); return ForgeWorldEdit.inst.getWorkingDir();
} }
} }

View File

@ -36,6 +36,7 @@ import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.entity.item.EntityXPOrb; import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.monster.EntityGolem; import net.minecraft.entity.monster.EntityGolem;
import net.minecraft.entity.passive.EntityAmbientCreature; import net.minecraft.entity.passive.EntityAmbientCreature;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntityTameable; import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.passive.IAnimals; import net.minecraft.entity.passive.IAnimals;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -108,7 +109,7 @@ public class ForgeEntityType implements EntityType {
@Override @Override
public boolean isAnimal() { public boolean isAnimal() {
return entity instanceof IAnimals; return entity instanceof EntityAnimal;
} }
@Override @Override
@ -133,7 +134,7 @@ public class ForgeEntityType implements EntityType {
@Override @Override
public boolean isTagged() { public boolean isTagged() {
return entity instanceof EntityLiving && ((EntityLiving) entity).hasCustomNameTag(); return entity instanceof EntityLiving && ((EntityLiving) entity).hasCustomName();
} }
@Override @Override

View File

@ -1,53 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.world.registry.ItemRegistry;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
public class ForgeItemRegistry implements ItemRegistry {
@Nullable
@Override
public BaseItem createFromId(String id) {
Item item = (Item) Item.itemRegistry.getObject(id);
if (item != null) {
return new BaseItem(Item.getIdFromItem(item), (short) item.getDamage(new ItemStack(item, 1)));
} else {
return null;
}
}
@Nullable
@Override
public BaseItem createFromId(int id) {
Item item = (Item) Item.itemRegistry.getObjectById(id);
if (item != null) {
return new BaseItem(Item.getIdFromItem(item), (short) item.getDamage(new ItemStack(item, 1)));
} else {
return null;
}
}
}

View File

@ -19,10 +19,11 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.command.ICommand; import net.minecraft.command.ICommand;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.world.WorldSettings.GameType; import net.minecraft.world.WorldSettings.GameType;
import net.minecraftforge.fml.common.FMLCommonHandler;
import org.spongepowered.api.entity.living.player.Player;
public interface ForgePermissionsProvider { public interface ForgePermissionsProvider {
@ -42,11 +43,24 @@ public interface ForgePermissionsProvider {
public boolean hasPermission(EntityPlayerMP player, String permission) { public boolean hasPermission(EntityPlayerMP player, String permission) {
ForgeConfiguration configuration = platform.getConfiguration(); ForgeConfiguration configuration = platform.getConfiguration();
return configuration.cheatMode || return configuration.cheatMode ||
FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().func_152596_g(player.getGameProfile()) || FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().canSendCommands(player.getGameProfile()) ||
(configuration.creativeEnable && player.theItemInWorldManager.getGameType() == GameType.CREATIVE); (configuration.creativeEnable && player.theItemInWorldManager.getGameType() == GameType.CREATIVE);
} }
@Override @Override
public void registerPermission(ICommand command, String permission) {} public void registerPermission(ICommand command, String permission) {}
} }
public static class SpongePermissionsProvider implements ForgePermissionsProvider {
@Override
public boolean hasPermission(EntityPlayerMP player, String permission) {
return ((Player) player).hasPermission(permission);
}
@Override
public void registerPermission(ICommand command, String permission) {
}
}
} }

View File

@ -28,7 +28,7 @@ import com.sk89q.worldedit.extension.platform.Preference;
import com.sk89q.worldedit.util.command.CommandMapping; import com.sk89q.worldedit.util.command.CommandMapping;
import com.sk89q.worldedit.util.command.Dispatcher; import com.sk89q.worldedit.util.command.Dispatcher;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.command.ServerCommandManager; import net.minecraft.command.ServerCommandManager;
import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityList;
@ -38,8 +38,10 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.ServerConfigurationManager; import net.minecraft.server.management.ServerConfigurationManager;
import net.minecraft.world.WorldServer; import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.common.FMLCommonHandler;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -121,7 +123,7 @@ class ForgePlatform extends AbstractPlatform implements MultiUserPlatform {
if (player instanceof ForgePlayer) { if (player instanceof ForgePlayer) {
return player; return player;
} else { } else {
EntityPlayerMP entity = server.getConfigurationManager().func_152612_a(player.getName()); EntityPlayerMP entity = server.getConfigurationManager().getPlayerByUsername(player.getName());
return entity != null ? new ForgePlayer(this, entity) : null; return entity != null ? new ForgePlayer(this, entity) : null;
} }
} }
@ -202,7 +204,7 @@ class ForgePlatform extends AbstractPlatform implements MultiUserPlatform {
List<Actor> users = new ArrayList<Actor>(); List<Actor> users = new ArrayList<Actor>();
ServerConfigurationManager scm = server.getConfigurationManager(); ServerConfigurationManager scm = server.getConfigurationManager();
for (String name : scm.getAllUsernames()) { for (String name : scm.getAllUsernames()) {
EntityPlayerMP entity = scm.func_152612_a(name); EntityPlayerMP entity = scm.getPlayerByUsername(name);
if (entity != null) { if (entity != null) {
users.add(new ForgePlayer(this, entity)); users.add(new ForgePlayer(this, entity));
} }

View File

@ -1,216 +1,222 @@
/* /*
* WorldEdit, a Minecraft world manipulation toolkit * WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com> * Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors * Copyright (C) WorldEdit team and contributors
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the * under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or * Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.sk89q.util.StringUtil; import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector; import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extension.platform.AbstractPlayerActor; import com.sk89q.worldedit.extension.platform.AbstractPlayerActor;
import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.LocalWorldAdapter; import com.sk89q.worldedit.internal.LocalWorldAdapter;
import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.Location;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.play.server.S3FPacketCustomPayload; import net.minecraft.network.PacketBuffer;
import net.minecraft.util.ChatComponentText; import net.minecraft.network.play.server.S3FPacketCustomPayload;
import net.minecraft.util.ChatComponentText;
import javax.annotation.Nullable; import io.netty.buffer.Unpooled;
import net.minecraft.util.EnumChatFormatting;
import java.util.UUID;
import javax.annotation.Nullable;
public class ForgePlayer extends AbstractPlayerActor {
import java.util.UUID;
private final ForgePlatform platform;
private final EntityPlayerMP player; public class ForgePlayer extends AbstractPlayerActor {
protected ForgePlayer(ForgePlatform platform, EntityPlayerMP player) { private final ForgePlatform platform;
this.platform = platform; private final EntityPlayerMP player;
this.player = player;
ThreadSafeCache.getInstance().getOnlineIds().add(getUniqueId()); protected ForgePlayer(ForgePlatform platform, EntityPlayerMP player) {
} this.platform = platform;
this.player = player;
@Override ThreadSafeCache.getInstance().getOnlineIds().add(getUniqueId());
public UUID getUniqueId() { }
return player.getUniqueID();
} @Override
public UUID getUniqueId() {
@Override return player.getUniqueID();
public int getItemInHand() { }
ItemStack is = this.player.getCurrentEquippedItem();
return is == null ? 0 : Item.getIdFromItem(is.getItem()); @Override
} public int getItemInHand() {
ItemStack is = this.player.getCurrentEquippedItem();
@Override return is == null ? 0 : Item.getIdFromItem(is.getItem());
public String getName() { }
return this.player.getCommandSenderName();
} @Override
public String getName() {
@Override return this.player.getName();
public BaseEntity getState() { }
throw new UnsupportedOperationException("Cannot create a state from this object");
} @Override
public BaseEntity getState() {
@Override throw new UnsupportedOperationException("Cannot create a state from this object");
public Location getLocation() { }
Vector position = new Vector(this.player.posX, this.player.posY, this.player.posZ);
return new Location( @Override
ForgeWorldEdit.inst.getWorld(this.player.worldObj), public Location getLocation() {
position, Vector position = new Vector(this.player.posX, this.player.posY, this.player.posZ);
this.player.cameraYaw, return new Location(
this.player.cameraPitch); ForgeWorldEdit.inst.getWorld(this.player.worldObj),
} position,
this.player.rotationYaw,
@Override this.player.rotationPitch);
public WorldVector getPosition() { }
return new WorldVector(LocalWorldAdapter.adapt(ForgeWorldEdit.inst.getWorld(this.player.worldObj)), this.player.posX, this.player.posY, this.player.posZ);
} @Override
public WorldVector getPosition() {
@Override return new WorldVector(LocalWorldAdapter.adapt(ForgeWorldEdit.inst.getWorld(this.player.worldObj)), this.player.posX, this.player.posY, this.player.posZ);
public com.sk89q.worldedit.world.World getWorld() { }
return ForgeWorldEdit.inst.getWorld(this.player.worldObj);
} @Override
public com.sk89q.worldedit.world.World getWorld() {
@Override return ForgeWorldEdit.inst.getWorld(this.player.worldObj);
public double getPitch() { }
return this.player.rotationPitch;
} @Override
public double getPitch() {
@Override return this.player.rotationPitch;
public double getYaw() { }
return this.player.rotationYaw;
} @Override
public double getYaw() {
@Override return this.player.rotationYaw;
public void giveItem(int type, int amt) { }
this.player.inventory.addItemStackToInventory(new ItemStack(Item.getItemById(type), amt, 0));
} @Override
public void giveItem(int type, int amt) {
@Override this.player.inventory.addItemStackToInventory(new ItemStack(Item.getItemById(type), amt, 0));
public void dispatchCUIEvent(CUIEvent event) { }
String[] params = event.getParameters();
String send = event.getTypeId(); @Override
if (params.length > 0) { public void dispatchCUIEvent(CUIEvent event) {
send = send + "|" + StringUtil.joinString(params, "|"); String[] params = event.getParameters();
} String send = event.getTypeId();
S3FPacketCustomPayload packet = new S3FPacketCustomPayload(ForgeWorldEdit.CUI_PLUGIN_CHANNEL, send.getBytes(WECUIPacketHandler.UTF_8_CHARSET)); if (params.length > 0) {
this.player.playerNetServerHandler.sendPacket(packet); send = send + "|" + StringUtil.joinString(params, "|");
} }
PacketBuffer buffer = new PacketBuffer(Unpooled.copiedBuffer(send.getBytes(WECUIPacketHandler.UTF_8_CHARSET)));
@Override S3FPacketCustomPayload packet = new S3FPacketCustomPayload(ForgeWorldEdit.CUI_PLUGIN_CHANNEL, buffer);
public void printRaw(String msg) { this.player.playerNetServerHandler.sendPacket(packet);
for (String part : msg.split("\n")) { }
this.player.addChatMessage(new ChatComponentText(part));
} @Override
} public void printRaw(String msg) {
for (String part : msg.split("\n")) {
@Override this.player.addChatMessage(new ChatComponentText(part));
public void printDebug(String msg) { }
for (String part : msg.split("\n")) { }
this.player.addChatMessage(new ChatComponentText("\u00a77" + part));
} @Override
} public void printDebug(String msg) {
sendColorized(msg, EnumChatFormatting.GRAY);
@Override }
public void print(String msg) {
for (String part : msg.split("\n")) { @Override
this.player.addChatMessage(new ChatComponentText("\u00a7d" + part)); public void print(String msg) {
} sendColorized(msg, EnumChatFormatting.LIGHT_PURPLE);
} }
@Override @Override
public void printError(String msg) { public void printError(String msg) {
for (String part : msg.split("\n")) { sendColorized(msg, EnumChatFormatting.RED);
this.player.addChatMessage(new ChatComponentText("\u00a7c" + part)); }
}
} private void sendColorized(String msg, EnumChatFormatting formatting) {
for (String part : msg.split("\n")) {
@Override ChatComponentText component = new ChatComponentText(part);
public void setPosition(Vector pos, float pitch, float yaw) { component.getChatStyle().setColor(formatting);
this.player.playerNetServerHandler.setPlayerLocation(pos.getX(), pos.getY(), pos.getZ(), pitch, yaw); this.player.addChatMessage(component);
} }
}
@Override
public String[] getGroups() { @Override
return new String[]{}; // WorldEditMod.inst.getPermissionsResolver().getGroups(this.player.username); public void setPosition(Vector pos, float pitch, float yaw) {
} this.player.playerNetServerHandler.setPlayerLocation(pos.getX(), pos.getY(), pos.getZ(), yaw, pitch);
}
@Override
public BlockBag getInventoryBlockBag() { @Override
return null; public String[] getGroups() {
} return new String[]{}; // WorldEditMod.inst.getPermissionsResolver().getGroups(this.player.username);
}
@Override
public boolean hasPermission(String perm) { @Override
return ForgeWorldEdit.inst.getPermissionsProvider().hasPermission(player, perm); public BlockBag getInventoryBlockBag() {
} return null;
}
@Nullable
@Override @Override
public <T> T getFacet(Class<? extends T> cls) { public boolean hasPermission(String perm) {
return null; return ForgeWorldEdit.inst.getPermissionsProvider().hasPermission(player, perm);
} }
@Override @Nullable
public SessionKey getSessionKey() { @Override
return new SessionKeyImpl(player.getUniqueID(), player.getCommandSenderName()); public <T> T getFacet(Class<? extends T> cls) {
} return null;
}
private static class SessionKeyImpl implements SessionKey {
// If not static, this will leak a reference @Override
public SessionKey getSessionKey() {
private final UUID uuid; return new SessionKeyImpl(player.getUniqueID(), player.getName());
private final String name; }
private SessionKeyImpl(UUID uuid, String name) { private static class SessionKeyImpl implements SessionKey {
this.uuid = uuid; // If not static, this will leak a reference
this.name = name;
} private final UUID uuid;
private final String name;
@Override
public UUID getUniqueId() { private SessionKeyImpl(UUID uuid, String name) {
return uuid; this.uuid = uuid;
} this.name = name;
}
@Nullable
@Override @Override
public String getName() { public UUID getUniqueId() {
return name; return uuid;
} }
@Override @Nullable
public boolean isActive() { @Override
// We can't directly check if the player is online because public String getName() {
// the list of players is not thread safe return name;
return ThreadSafeCache.getInstance().getOnlineIds().contains(uuid); }
}
@Override
@Override public boolean isActive() {
public boolean isPersistent() { // We can't directly check if the player is online because
return true; // the list of players is not thread safe
} return ThreadSafeCache.getInstance().getOnlineIds().contains(uuid);
}
}
@Override
} public boolean isPersistent() {
return true;
}
}
}

View File

@ -1,483 +1,445 @@
/* /*
* WorldEdit, a Minecraft world manipulation toolkit * WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com> * Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors * Copyright (C) WorldEdit team and contributors
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the * under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or * Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.LazyBlock;
import com.sk89q.worldedit.blocks.LazyBlock; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.internal.Constants; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.util.TreeGenerator.TreeType; import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.AbstractWorld; import com.sk89q.worldedit.world.registry.WorldData;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.registry.WorldData; import java.lang.ref.WeakReference;
import net.minecraft.block.Block; import java.util.ArrayList;
import net.minecraft.entity.EntityList; import java.util.List;
import net.minecraft.entity.item.EntityItem; import java.util.Random;
import net.minecraft.inventory.IInventory; import java.util.Set;
import net.minecraft.item.Item; import java.util.logging.Level;
import net.minecraft.item.ItemStack; import java.util.logging.Logger;
import net.minecraft.nbt.NBTTagCompound; import javax.annotation.Nullable;
import net.minecraft.tileentity.TileEntity; import net.minecraft.block.Block;
import net.minecraft.util.LongHashMap; import net.minecraft.block.BlockLeaves;
import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.block.BlockOldLeaf;
import net.minecraft.world.World; import net.minecraft.block.BlockOldLog;
import net.minecraft.world.WorldServer; import net.minecraft.block.BlockPlanks;
import net.minecraft.world.chunk.Chunk; import net.minecraft.block.state.IBlockState;
import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.entity.EntityList;
import net.minecraft.world.gen.ChunkProviderServer; import net.minecraft.entity.item.EntityItem;
import net.minecraft.world.gen.feature.WorldGenBigMushroom; import net.minecraft.init.Blocks;
import net.minecraft.world.gen.feature.WorldGenBigTree; import net.minecraft.inventory.IInventory;
import net.minecraft.world.gen.feature.WorldGenCanopyTree; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.gen.feature.WorldGenForest; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.gen.feature.WorldGenMegaJungle; import net.minecraft.util.BlockPos;
import net.minecraft.world.gen.feature.WorldGenMegaPineTree; import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.gen.feature.WorldGenSavannaTree; import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenShrub; import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.feature.WorldGenSwamp; import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenTaiga1; import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraft.world.gen.feature.WorldGenTaiga2; import net.minecraft.world.gen.feature.WorldGenBigMushroom;
import net.minecraft.world.gen.feature.WorldGenTrees; import net.minecraft.world.gen.feature.WorldGenBigTree;
import net.minecraft.world.gen.feature.WorldGenerator; import net.minecraft.world.gen.feature.WorldGenCanopyTree;
import net.minecraft.world.gen.feature.WorldGenForest;
import javax.annotation.Nullable; import net.minecraft.world.gen.feature.WorldGenMegaJungle;
import java.lang.ref.WeakReference; import net.minecraft.world.gen.feature.WorldGenMegaPineTree;
import java.lang.reflect.Field; import net.minecraft.world.gen.feature.WorldGenSavannaTree;
import java.util.ArrayList; import net.minecraft.world.gen.feature.WorldGenShrub;
import java.util.List; import net.minecraft.world.gen.feature.WorldGenSwamp;
import java.util.Random; import net.minecraft.world.gen.feature.WorldGenTaiga1;
import java.util.Set; import net.minecraft.world.gen.feature.WorldGenTaiga2;
import java.util.logging.Level; import net.minecraft.world.gen.feature.WorldGenTrees;
import java.util.logging.Logger; import net.minecraft.world.gen.feature.WorldGenerator;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* An adapter to Minecraft worlds for WorldEdit. * An adapter to Minecraft worlds for WorldEdit.
*/ */
public class ForgeWorld extends AbstractWorld { public class ForgeWorld extends AbstractWorld {
private static final Logger logger = Logger.getLogger(ForgeWorld.class.getCanonicalName()); private static final Random random = new Random();
private static final Random random = new Random(); private static final int UPDATE = 1, NOTIFY = 2, NOTIFY_CLIENT = 4;
private final WeakReference<World> worldRef; private static final Logger logger = Logger.getLogger(ForgeWorld.class.getCanonicalName());
/** private static final IBlockState JUNGLE_LOG = Blocks.log.getDefaultState().withProperty(BlockOldLog.VARIANT, BlockPlanks.EnumType.JUNGLE);
* Construct a new world. 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_SHRUB = Blocks.leaves.getDefaultState().withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.OAK).withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(false));
* @param world the world
*/ private final WeakReference<World> worldRef;
ForgeWorld(World world) {
checkNotNull(world); /**
this.worldRef = new WeakReference<World>(world); * Construct a new world.
} *
* @param world the world
/** */
* Get the underlying handle to the world. ForgeWorld(World world) {
* checkNotNull(world);
* @return the world this.worldRef = new WeakReference<World>(world);
* @throws WorldEditException thrown if a reference to the world was lost (i.e. world was unloaded) }
*/
public World getWorldChecked() throws WorldEditException { /**
World world = worldRef.get(); * Get the underlying handle to the world.
if (world != null) { *
return world; * @return the world
} else { * @throws WorldEditException thrown if a reference to the world was lost (i.e. world was unloaded)
throw new WorldReferenceLostException("The reference to the world was lost (i.e. the world may have been unloaded)"); */
} public World getWorldChecked() throws WorldEditException {
} World world = worldRef.get();
if (world != null) {
/** return world;
* Get the underlying handle to the world. } else {
* throw new WorldReferenceLostException("The reference to the world was lost (i.e. the world may have been unloaded)");
* @return the world }
* @throws RuntimeException thrown if a reference to the world was lost (i.e. world was unloaded) }
*/
public World getWorld() { /**
World world = worldRef.get(); * Get the underlying handle to the world.
if (world != null) { *
return world; * @return the world
} else { * @throws RuntimeException thrown if a reference to the world was lost (i.e. world was unloaded)
throw new RuntimeException("The reference to the world was lost (i.e. the world may have been unloaded)"); */
} public World getWorld() {
} World world = worldRef.get();
if (world != null) {
@Override return world;
public String getName() { } else {
return getWorld().getWorldInfo().getWorldName(); throw new RuntimeException("The reference to the world was lost (i.e. the world may have been unloaded)");
} }
}
@Override
public boolean useItem(Vector position, BaseItem item, Direction face) { @Override
Item nativeItem = Item.getItemById(item.getType()); public String getName() {
ItemStack stack = new ItemStack(nativeItem, 1, item.getData()); return getWorld().getWorldInfo().getWorldName();
World world = getWorld(); }
return stack.tryPlaceItemIntoWorld(new WorldEditFakePlayer((WorldServer) world), world, position.getBlockX(), position.getBlockY(), position.getBlockZ(), ForgeAdapter.adapt(face), 0, 0, 0);
} @Override
public boolean setBlock(Vector position, BaseBlock block, boolean notifyAndLight) throws WorldEditException {
@Override checkNotNull(position);
public boolean setBlock(Vector position, BaseBlock block, boolean notifyAndLight) throws WorldEditException { checkNotNull(block);
checkNotNull(position);
checkNotNull(block); World world = getWorldChecked();
int x = position.getBlockX();
World world = getWorldChecked(); int y = position.getBlockY();
int x = position.getBlockX(); int z = position.getBlockZ();
int y = position.getBlockY();
int z = position.getBlockZ(); // First set the block
Chunk chunk = world.getChunkFromChunkCoords(x >> 4, z >> 4);
// First set the block BlockPos pos = new BlockPos(x, y, z);
Chunk chunk = world.getChunkFromChunkCoords(x >> 4, z >> 4); IBlockState old = chunk.getBlockState(pos);
int previousId = 0; IBlockState newState = Block.getBlockById(block.getId()).getStateFromMeta(block.getData());
IBlockState successState = chunk.setBlockState(pos, newState);
if (notifyAndLight) { boolean successful = successState != null;
previousId = Block.getIdFromBlock(chunk.getBlock(x & 15, y, z & 15));
} // Create the TileEntity
if (successful) {
boolean successful = chunk.func_150807_a(x & 15, y, z & 15, Block.getBlockById(block.getId()), block.getData()); if (block.hasNbtData()) {
// Kill the old TileEntity
// Create the TileEntity world.removeTileEntity(pos);
if (successful) { NBTTagCompound nativeTag = NBTConverter.toNative(block.getNbtData());
CompoundTag tag = block.getNbtData(); nativeTag.setString("id", block.getNbtId());
if (tag != null) { TileEntityUtils.setTileEntity(world, position, nativeTag);
NBTTagCompound nativeTag = NBTConverter.toNative(tag); }
nativeTag.setString("id", block.getNbtId()); }
TileEntityUtils.setTileEntity(getWorld(), position, nativeTag);
} if (notifyAndLight) {
} if (!successful) {
newState = old;
if (notifyAndLight) { }
world.func_147451_t(x, y, z); world.checkLight(pos);
world.markBlockForUpdate(x, y, z); world.markAndNotifyBlock(pos, chunk, old, newState, UPDATE | NOTIFY);
world.notifyBlockChange(x, y, z, Block.getBlockById(previousId)); }
Block mcBlock = Block.getBlockById(previousId); return successful;
if (mcBlock != null && mcBlock.hasComparatorInputOverride()) { }
world.func_147453_f(x, y, z, Block.getBlockById(block.getId()));
} @Override
} public int getBlockLightLevel(Vector position) {
checkNotNull(position);
return successful; return getWorld().getLight(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()));
} }
@Override @Override
public int getBlockLightLevel(Vector position) { public boolean clearContainerBlockContents(Vector position) {
checkNotNull(position); checkNotNull(position);
return getWorld().getBlockLightValue(position.getBlockX(), position.getBlockY(), position.getBlockZ()); TileEntity tile = getWorld().getTileEntity(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()));
} if ((tile instanceof IInventory)) {
IInventory inv = (IInventory) tile;
@Override int size = inv.getSizeInventory();
public boolean clearContainerBlockContents(Vector position) { for (int i = 0; i < size; i++) {
checkNotNull(position); inv.setInventorySlotContents(i, null);
TileEntity tile = getWorld().getTileEntity(position.getBlockX(), position.getBlockY(), position.getBlockZ()); }
if ((tile instanceof IInventory)) { return true;
IInventory inv = (IInventory) tile; }
int size = inv.getSizeInventory(); return false;
for (int i = 0; i < size; i++) { }
inv.setInventorySlotContents(i, null);
} @Override
return true; public BaseBiome getBiome(Vector2D position) {
} checkNotNull(position);
return false; return new BaseBiome(getWorld().getBiomeGenForCoords(new BlockPos(position.getBlockX(), 0, position.getBlockZ())).biomeID);
} }
@Override @Override
public BaseBiome getBiome(Vector2D position) { public boolean setBiome(Vector2D position, BaseBiome biome) {
checkNotNull(position); checkNotNull(position);
return new BaseBiome(getWorld().getBiomeGenForCoords(position.getBlockX(), position.getBlockZ()).biomeID); checkNotNull(biome);
}
Chunk chunk = getWorld().getChunkFromBlockCoords(new BlockPos(position.getBlockX(), 0, position.getBlockZ()));
@Override if ((chunk != null) && (chunk.isLoaded())) {
public boolean setBiome(Vector2D position, BaseBiome biome) { chunk.getBiomeArray()[((position.getBlockZ() & 0xF) << 4 | position.getBlockX() & 0xF)] = (byte) biome.getId();
checkNotNull(position); return true;
checkNotNull(biome); }
Chunk chunk = getWorld().getChunkFromBlockCoords(position.getBlockX(), position.getBlockZ()); return false;
if ((chunk != null) && (chunk.isChunkLoaded)) { }
chunk.getBiomeArray()[((position.getBlockZ() & 0xF) << 4 | position.getBlockX() & 0xF)] = (byte) biome.getId();
return true; @Override
} public void dropItem(Vector position, BaseItemStack item) {
checkNotNull(position);
return false; checkNotNull(item);
}
if (item.getType() == 0) {
@Override return;
public void dropItem(Vector position, BaseItemStack item) { }
checkNotNull(position);
checkNotNull(item); EntityItem entity = new EntityItem(getWorld(), position.getX(), position.getY(), position.getZ(), ForgeWorldEdit.toForgeItemStack(item));
entity.setPickupDelay(10);
if (item.getType() == 0) { getWorld().spawnEntityInWorld(entity);
return; }
}
@Override
EntityItem entity = new EntityItem(getWorld(), position.getX(), position.getY(), position.getZ(), ForgeWorldEdit.toForgeItemStack(item)); public boolean regenerate(Region region, EditSession editSession) {
entity.delayBeforeCanPickup = 10; BaseBlock[] history = new BaseBlock[256 * (getMaxY() + 1)];
getWorld().spawnEntityInWorld(entity);
} for (Vector2D chunk : region.getChunks()) {
Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
@Override
public boolean regenerate(Region region, EditSession editSession) { for (int x = 0; x < 16; x++) {
BaseBlock[] history = new BaseBlock[256 * (getMaxY() + 1)]; for (int y = 0; y < getMaxY() + 1; y++) {
for (int z = 0; z < 16; z++) {
for (Vector2D chunk : region.getChunks()) { Vector pt = min.add(x, y, z);
Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16); int index = y * 16 * 16 + z * 16 + x;
history[index] = editSession.getBlock(pt);
for (int x = 0; x < 16; x++) { }
for (int y = 0; y < getMaxY() + 1; y++) { }
for (int z = 0; z < 16; z++) { }
Vector pt = min.add(x, y, z); try {
int index = y * 16 * 16 + z * 16 + x; Set<Vector2D> chunks = region.getChunks();
history[index] = editSession.getBlock(pt); IChunkProvider provider = getWorld().getChunkProvider();
} if (!(provider instanceof ChunkProviderServer)) {
} return false;
} }
try { ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
Set<Vector2D> chunks = region.getChunks(); IChunkProvider chunkProvider = chunkServer.serverChunkGenerator;
IChunkProvider provider = getWorld().getChunkProvider();
if (!(provider instanceof ChunkProviderServer)) { for (Vector2D coord : chunks) {
return false; long pos = ChunkCoordIntPair.chunkXZ2Int(coord.getBlockX(), coord.getBlockZ());
} Chunk mcChunk;
ChunkProviderServer chunkServer = (ChunkProviderServer) provider; if (chunkServer.chunkExists(coord.getBlockX(), coord.getBlockZ())) {
Field u; mcChunk = chunkServer.loadChunk(coord.getBlockX(), coord.getBlockZ());
try { mcChunk.onChunkUnload();
u = ChunkProviderServer.class.getDeclaredField("field_73248_b"); // chunksToUnload }
} catch(NoSuchFieldException e) { chunkServer.droppedChunksSet.remove(pos);
u = ChunkProviderServer.class.getDeclaredField("chunksToUnload"); chunkServer.id2ChunkMap.remove(pos);
} mcChunk = chunkProvider.provideChunk(coord.getBlockX(), coord.getBlockZ());
u.setAccessible(true); chunkServer.id2ChunkMap.add(pos, mcChunk);
Set<?> unloadQueue = (Set<?>) u.get(chunkServer); chunkServer.loadedChunks.add(mcChunk);
Field m; if (mcChunk != null) {
try { mcChunk.onChunkLoad();
m = ChunkProviderServer.class.getDeclaredField("field_73244_f"); // loadedChunkHashMap mcChunk.populateChunk(chunkProvider, chunkProvider, coord.getBlockX(), coord.getBlockZ());
} catch(NoSuchFieldException e) { }
m = ChunkProviderServer.class.getDeclaredField("loadedChunkHashMap"); }
} } catch (Throwable t) {
m.setAccessible(true); logger.log(Level.WARNING, "Failed to generate chunk", t);
LongHashMap loadedMap = (LongHashMap) m.get(chunkServer); return false;
Field lc; }
try {
lc = ChunkProviderServer.class.getDeclaredField("field_73245_g"); // loadedChunkHashMap for (int x = 0; x < 16; x++) {
} catch(NoSuchFieldException e) { for (int y = 0; y < getMaxY() + 1; y++) {
lc = ChunkProviderServer.class.getDeclaredField("loadedChunks"); for (int z = 0; z < 16; z++) {
} Vector pt = min.add(x, y, z);
lc.setAccessible(true); int index = y * 16 * 16 + z * 16 + x;
@SuppressWarnings("unchecked") List<Chunk> loaded = (List<Chunk>) lc.get(chunkServer);
Field p; if (!region.contains(pt))
try { editSession.smartSetBlock(pt, history[index]);
p = ChunkProviderServer.class.getDeclaredField("field_73246_d"); // currentChunkProvider else {
} catch(NoSuchFieldException e) { editSession.rememberChange(pt, history[index], editSession.rawGetBlock(pt));
p = ChunkProviderServer.class.getDeclaredField("currentChunkProvider"); }
} }
p.setAccessible(true); }
IChunkProvider chunkProvider = (IChunkProvider) p.get(chunkServer); }
}
for (Vector2D coord : chunks) {
long pos = ChunkCoordIntPair.chunkXZ2Int(coord.getBlockX(), coord.getBlockZ()); return false;
Chunk mcChunk; }
if (chunkServer.chunkExists(coord.getBlockX(), coord.getBlockZ())) {
mcChunk = chunkServer.loadChunk(coord.getBlockX(), coord.getBlockZ()); @Nullable
mcChunk.onChunkUnload(); private static WorldGenerator createWorldGenerator(TreeType type) {
} switch (type) {
unloadQueue.remove(pos); case TREE: return new WorldGenTrees(true);
loadedMap.remove(pos); case BIG_TREE: return new WorldGenBigTree(true);
mcChunk = chunkProvider.provideChunk(coord.getBlockX(), coord.getBlockZ()); case REDWOOD: return new WorldGenTaiga2(true);
loadedMap.add(pos, mcChunk); case TALL_REDWOOD: return new WorldGenTaiga1();
loaded.add(mcChunk); case BIRCH: return new WorldGenForest(true, false);
if (mcChunk != null) { case JUNGLE: return new WorldGenMegaJungle(true, 10, 20, JUNGLE_LOG, JUNGLE_LEAF);
mcChunk.onChunkLoad(); case SMALL_JUNGLE: return new WorldGenTrees(true, 4 + random.nextInt(7), JUNGLE_LOG, JUNGLE_LEAF, false);
mcChunk.populateChunk(chunkProvider, chunkProvider, coord.getBlockX(), coord.getBlockZ()); case SHORT_JUNGLE: return new WorldGenTrees(true, 4 + random.nextInt(7), JUNGLE_LOG, JUNGLE_LEAF, true);
} case JUNGLE_BUSH: return new WorldGenShrub(JUNGLE_LOG, JUNGLE_SHRUB);
} case RED_MUSHROOM: return new WorldGenBigMushroom(Blocks.brown_mushroom_block);
} catch (Throwable t) { case BROWN_MUSHROOM: return new WorldGenBigMushroom(Blocks.red_mushroom_block);
logger.log(Level.WARNING, "Failed to generate chunk", t); case SWAMP: return new WorldGenSwamp();
return false; case ACACIA: return new WorldGenSavannaTree(true);
} case DARK_OAK: return new WorldGenCanopyTree(true);
case MEGA_REDWOOD: return new WorldGenMegaPineTree(false, random.nextBoolean());
for (int x = 0; x < 16; x++) { case TALL_BIRCH: return new WorldGenForest(true, true);
for (int y = 0; y < getMaxY() + 1; y++) { case RANDOM:
for (int z = 0; z < 16; z++) { case PINE:
Vector pt = min.add(x, y, z); case RANDOM_REDWOOD:
int index = y * 16 * 16 + z * 16 + x; default:
return null;
if (!region.contains(pt)) }
editSession.smartSetBlock(pt, history[index]); }
else {
editSession.rememberChange(pt, history[index], editSession.rawGetBlock(pt)); @Override
} public boolean generateTree(TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException {
} WorldGenerator generator = createWorldGenerator(type);
} return generator != null ? generator.generate(getWorld(), random, ForgeAdapter.toBlockPos(position)) : false;
} }
}
@Override
return false; public WorldData getWorldData() {
} return ForgeWorldData.getInstance();
}
@Nullable
private static WorldGenerator createWorldGenerator(TreeType type) { @Override
switch (type) { public boolean isValidBlockType(int id) {
case TREE: return new WorldGenTrees(true); return (id == 0) || (net.minecraft.block.Block.getBlockById(id) != null);
case BIG_TREE: return new WorldGenBigTree(true); }
case REDWOOD: return new WorldGenTaiga2(true);
case TALL_REDWOOD: return new WorldGenTaiga1(); @Override
case BIRCH: return new WorldGenForest(true, false); public BaseBlock getBlock(Vector position) {
case JUNGLE: return new WorldGenMegaJungle(true, 10, 20, 3, 3); World world = getWorld();
case SMALL_JUNGLE: return new WorldGenTrees(true, 4 + random.nextInt(7), 3, 3, false); BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ());
case SHORT_JUNGLE: return new WorldGenTrees(true, 4 + random.nextInt(7), 3, 3, true); IBlockState state = world.getBlockState(pos);
case JUNGLE_BUSH: return new WorldGenShrub(3, 0); TileEntity tile = getWorld().getTileEntity(pos);
case RED_MUSHROOM: return new WorldGenBigMushroom(1);
case BROWN_MUSHROOM: return new WorldGenBigMushroom(0); if (tile != null) {
case SWAMP: return new WorldGenSwamp(); return new TileEntityBaseBlock(Block.getIdFromBlock(state.getBlock()), state.getBlock().getMetaFromState(state), tile);
case ACACIA: return new WorldGenSavannaTree(true); } else {
case DARK_OAK: return new WorldGenCanopyTree(true); return new BaseBlock(Block.getIdFromBlock(state.getBlock()), state.getBlock().getMetaFromState(state));
case MEGA_REDWOOD: return new WorldGenMegaPineTree(false, random.nextBoolean()); }
case TALL_BIRCH: return new WorldGenForest(true, true); }
case RANDOM:
case PINE: @Override
case RANDOM_REDWOOD: public BaseBlock getLazyBlock(Vector position) {
default: World world = getWorld();
return null; BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ());
} IBlockState state = world.getBlockState(pos);
} return new LazyBlock(Block.getIdFromBlock(state.getBlock()), state.getBlock().getMetaFromState(state), this, position);
}
@Override
public boolean generateTree(TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException { @Override
WorldGenerator generator = createWorldGenerator(type); public int hashCode() {
return generator != null ? generator.generate(getWorld(), random, position.getBlockX(), position.getBlockY(), position.getBlockZ()) : false; return getWorld().hashCode();
} }
@Override @Override
public WorldData getWorldData() { public boolean equals(Object o) {
return ForgeWorldData.getInstance(); if (o == null) {
} return false;
} else if ((o instanceof ForgeWorld)) {
@Override ForgeWorld other = ((ForgeWorld) o);
public boolean isValidBlockType(int id) { World otherWorld = other.worldRef.get();
return (id == 0) || (net.minecraft.block.Block.getBlockById(id) != null); World thisWorld = worldRef.get();
} return otherWorld != null && thisWorld != null && otherWorld.equals(thisWorld);
} else if (o instanceof com.sk89q.worldedit.world.World) {
@Override return ((com.sk89q.worldedit.world.World) o).getName().equals(getName());
public BaseBlock getBlock(Vector position) { } else {
World world = getWorld(); return false;
int id = Block.getIdFromBlock(world.getBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ())); }
int data = world.getBlockMetadata(position.getBlockX(), position.getBlockY(), position.getBlockZ()); }
TileEntity tile = getWorld().getTileEntity(position.getBlockX(), position.getBlockY(), position.getBlockZ());
@Override
if (tile != null) { public List<? extends Entity> getEntities(Region region) {
return new TileEntityBaseBlock(id, data, tile); List<Entity> entities = new ArrayList<Entity>();
} else { World world = getWorld();
return new BaseBlock(id, data); List<net.minecraft.entity.Entity> ents = world.loadedEntityList;
} for (net.minecraft.entity.Entity entity : ents) {
} if (region.contains(new Vector(entity.posX, entity.posY, entity.posZ))) {
entities.add(new ForgeEntity(entity));
@Override }
public BaseBlock getLazyBlock(Vector position) { }
World world = getWorld(); return entities;
int id = Block.getIdFromBlock(world.getBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ())); }
int data = world.getBlockMetadata(position.getBlockX(), position.getBlockY(), position.getBlockZ());
return new LazyBlock(id, data, this, position); @Override
} public List<? extends Entity> getEntities() {
List<Entity> entities = new ArrayList<Entity>();
@Override for (net.minecraft.entity.Entity entity : getWorld().loadedEntityList) {
public int hashCode() { entities.add(new ForgeEntity(entity));
return getWorld().hashCode(); }
} return entities;
}
@Override
public boolean equals(Object o) { @Nullable
if (o == null) { @Override
return false; public Entity createEntity(Location location, BaseEntity entity) {
} else if ((o instanceof ForgeWorld)) { World world = getWorld();
ForgeWorld other = ((ForgeWorld) o); net.minecraft.entity.Entity createdEntity = EntityList.createEntityByName(entity.getTypeId(), world);
World otherWorld = other.worldRef.get(); if (createdEntity != null) {
World thisWorld = worldRef.get(); CompoundTag nativeTag = entity.getNbtData();
return otherWorld != null && thisWorld != null && otherWorld.equals(thisWorld); if (nativeTag != null) {
} else if (o instanceof com.sk89q.worldedit.world.World) { NBTTagCompound tag = NBTConverter.toNative(entity.getNbtData());
return ((com.sk89q.worldedit.world.World) o).getName().equals(getName()); for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
} else { tag.removeTag(name);
return false; }
} createdEntity.readFromNBT(tag);
} }
@Override createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
@SuppressWarnings("unchecked")
public List<? extends Entity> getEntities(Region region) { world.spawnEntityInWorld(createdEntity);
List<Entity> entities = new ArrayList<Entity>(); return new ForgeEntity(createdEntity);
World world = getWorld(); } else {
List<net.minecraft.entity.Entity> ents = world.loadedEntityList; return null;
for (net.minecraft.entity.Entity entity : ents) { }
if (region.contains(new Vector(entity.posX, entity.posY, entity.posZ))) { }
entities.add(new ForgeEntity(entity));
} /**
} * Thrown when the reference to the world is lost.
return entities; */
} private static class WorldReferenceLostException extends WorldEditException {
private WorldReferenceLostException(String message) {
@Override super(message);
public List<? extends Entity> getEntities() { }
List<Entity> entities = new ArrayList<Entity>(); }
for (Object entity : getWorld().loadedEntityList) {
entities.add(new ForgeEntity((net.minecraft.entity.Entity) entity)); }
}
return entities;
}
@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity) {
World world = getWorld();
net.minecraft.entity.Entity createdEntity = EntityList.createEntityByName(entity.getTypeId(), world);
if (createdEntity != null) {
CompoundTag nativeTag = entity.getNbtData();
if (nativeTag != null) {
NBTTagCompound tag = NBTConverter.toNative(entity.getNbtData());
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.removeTag(name);
}
createdEntity.readFromNBT(tag);
}
createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
world.spawnEntityInWorld(createdEntity);
return new ForgeEntity(createdEntity);
} else {
return null;
}
}
/**
* Thrown when the reference to the world is lost.
*/
private static class WorldReferenceLostException extends WorldEditException {
private WorldReferenceLostException(String message) {
super(message);
}
}
}

View File

@ -20,7 +20,6 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.world.registry.BiomeRegistry; import com.sk89q.worldedit.world.registry.BiomeRegistry;
import com.sk89q.worldedit.world.registry.ItemRegistry;
import com.sk89q.worldedit.world.registry.LegacyWorldData; import com.sk89q.worldedit.world.registry.LegacyWorldData;
/** /**
@ -29,14 +28,8 @@ import com.sk89q.worldedit.world.registry.LegacyWorldData;
class ForgeWorldData extends LegacyWorldData { class ForgeWorldData extends LegacyWorldData {
private static final ForgeWorldData INSTANCE = new ForgeWorldData(); private static final ForgeWorldData INSTANCE = new ForgeWorldData();
private final ItemRegistry itemRegistry = new ForgeItemRegistry();
private final BiomeRegistry biomeRegistry = new ForgeBiomeRegistry(); private final BiomeRegistry biomeRegistry = new ForgeBiomeRegistry();
@Override
public ItemRegistry getItemRegistry() {
return itemRegistry;
}
@Override @Override
public BiomeRegistry getBiomeRegistry() { public BiomeRegistry getBiomeRegistry() {
return biomeRegistry; return biomeRegistry;

View File

@ -19,6 +19,8 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import org.apache.logging.log4j.Logger;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
@ -26,24 +28,10 @@ import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent; import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.forge.compat.ForgeMultipartCompat;
import com.sk89q.worldedit.forge.compat.ForgeMultipartExistsCompat;
import com.sk89q.worldedit.forge.compat.NoForgeMultipartCompat;
import com.sk89q.worldedit.internal.LocalWorldAdapter; import com.sk89q.worldedit.internal.LocalWorldAdapter;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader; import java.io.File;
import cpw.mods.fml.common.Mod; import java.util.Map;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
import cpw.mods.fml.common.event.FMLServerStartedEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -51,13 +39,22 @@ import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.CommandEvent; import net.minecraftforge.event.CommandEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import org.apache.logging.log4j.Logger; import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import net.minecraftforge.fml.common.Loader;
import java.io.File; import net.minecraftforge.fml.common.Mod;
import java.util.Map; import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerAboutToStartEvent;
import net.minecraftforge.fml.common.event.FMLServerStartedEvent;
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
import net.minecraftforge.fml.common.eventhandler.Event.Result;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
/** /**
* The Forge implementation of WorldEdit. * The Forge implementation of WorldEdit.
@ -80,7 +77,6 @@ public class ForgeWorldEdit {
private ForgePlatform platform; private ForgePlatform platform;
private ForgeConfiguration config; private ForgeConfiguration config;
private File workingDir; private File workingDir;
private ForgeMultipartCompat compat = new NoForgeMultipartCompat();
@EventHandler @EventHandler
public void preInit(FMLPreInitializationEvent event) { public void preInit(FMLPreInitializationEvent event) {
@ -92,16 +88,13 @@ public class ForgeWorldEdit {
config = new ForgeConfiguration(this); config = new ForgeConfiguration(this);
config.load(); config.load();
if (Loader.isModLoaded("ForgeMultipart")) { MinecraftForge.EVENT_BUS.register(ThreadSafeCache.getInstance());
compat = new ForgeMultipartExistsCompat();
}
FMLCommonHandler.instance().bus().register(ThreadSafeCache.getInstance());
} }
@EventHandler @EventHandler
public void init(FMLInitializationEvent event) { public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
WECUIPacketHandler.init();
proxy.registerHandlers(); proxy.registerHandlers();
} }
@ -122,7 +115,12 @@ public class ForgeWorldEdit {
this.platform = new ForgePlatform(this); this.platform = new ForgePlatform(this);
WorldEdit.getInstance().getPlatformManager().register(platform); WorldEdit.getInstance().getPlatformManager().register(platform);
this.provider = new ForgePermissionsProvider.VanillaPermissionsProvider(platform);
if (Loader.isModLoaded("sponge")) {
this.provider = new ForgePermissionsProvider.SpongePermissionsProvider();
} else {
this.provider = new ForgePermissionsProvider.VanillaPermissionsProvider(platform);
}
} }
@EventHandler @EventHandler
@ -165,7 +163,7 @@ public class ForgeWorldEdit {
Action action = event.action; Action action = event.action;
switch (action) { switch (action) {
case LEFT_CLICK_BLOCK: { case LEFT_CLICK_BLOCK: {
WorldVector pos = new WorldVector(LocalWorldAdapter.adapt(world), event.x, event.y, event.z); WorldVector pos = new WorldVector(LocalWorldAdapter.adapt(world), event.pos.getX(), event.pos.getY(), event.pos.getZ());
if (we.handleBlockLeftClick(player, pos)) { if (we.handleBlockLeftClick(player, pos)) {
event.setCanceled(true); event.setCanceled(true);
@ -178,7 +176,7 @@ public class ForgeWorldEdit {
break; break;
} }
case RIGHT_CLICK_BLOCK: { case RIGHT_CLICK_BLOCK: {
WorldVector pos = new WorldVector(LocalWorldAdapter.adapt(world), event.x, event.y, event.z); WorldVector pos = new WorldVector(LocalWorldAdapter.adapt(world), event.pos.getX(), event.pos.getY(), event.pos.getZ());
if (we.handleBlockRightClick(player, pos)) { if (we.handleBlockRightClick(player, pos)) {
event.setCanceled(true); event.setCanceled(true);
@ -203,7 +201,7 @@ public class ForgeWorldEdit {
public static ItemStack toForgeItemStack(BaseItemStack item) { public static ItemStack toForgeItemStack(BaseItemStack item) {
ItemStack ret = new ItemStack(Item.getItemById(item.getType()), item.getAmount(), item.getData()); ItemStack ret = new ItemStack(Item.getItemById(item.getType()), item.getAmount(), item.getData());
for (Map.Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) { for (Map.Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) {
ret.addEnchantment(net.minecraft.enchantment.Enchantment.enchantmentsList[((Integer) entry.getKey())], (Integer) entry.getValue()); ret.addEnchantment(net.minecraft.enchantment.Enchantment.getEnchantmentById(entry.getKey()), entry.getValue());
} }
return ret; return ret;
@ -269,10 +267,6 @@ public class ForgeWorldEdit {
return this.workingDir; return this.workingDir;
} }
public ForgeMultipartCompat getFMPCompat() {
return compat;
}
/** /**
* Get the version of the WorldEdit-for-Forge implementation. * Get the version of the WorldEdit-for-Forge implementation.
* *

View File

@ -20,11 +20,13 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.forge.gui.GuiHandler; import com.sk89q.worldedit.forge.gui.GuiHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
public class KeyHandler { public class KeyHandler {

View File

@ -170,7 +170,7 @@ final class NBTConverter {
} }
public static IntArrayTag fromNative(NBTTagIntArray other) { public static IntArrayTag fromNative(NBTTagIntArray other) {
int[] value = other.func_150302_c(); int[] value = other.getIntArray();
return new IntArrayTag(Arrays.copyOf(value, value.length)); return new IntArrayTag(Arrays.copyOf(value, value.length));
} }
@ -192,28 +192,28 @@ final class NBTConverter {
} }
public static LongTag fromNative(NBTTagLong other) { public static LongTag fromNative(NBTTagLong other) {
return new LongTag(other.func_150291_c()); return new LongTag(other.getLong());
} }
public static StringTag fromNative(NBTTagString other) { public static StringTag fromNative(NBTTagString other) {
return new StringTag(other.func_150285_a_()); return new StringTag(other.getString());
} }
public static IntTag fromNative(NBTTagInt other) { public static IntTag fromNative(NBTTagInt other) {
return new IntTag(other.func_150287_d()); return new IntTag(other.getInt());
} }
public static ByteTag fromNative(NBTTagByte other) { public static ByteTag fromNative(NBTTagByte other) {
return new ByteTag(other.func_150290_f()); return new ByteTag(other.getByte());
} }
public static ByteArrayTag fromNative(NBTTagByteArray other) { public static ByteArrayTag fromNative(NBTTagByteArray other) {
byte[] value = other.func_150292_c(); byte[] value = other.getByteArray();
return new ByteArrayTag(Arrays.copyOf(value, value.length)); return new ByteArrayTag(Arrays.copyOf(value, value.length));
} }
public static CompoundTag fromNative(NBTTagCompound other) { public static CompoundTag fromNative(NBTTagCompound other) {
@SuppressWarnings("unchecked") Collection<String> tags = other.func_150296_c(); @SuppressWarnings("unchecked") Set<String> tags = other.getKeySet();
Map<String, Tag> map = new HashMap<String, Tag>(); Map<String, Tag> map = new HashMap<String, Tag>();
for (String tagName : tags) { for (String tagName : tags) {
map.put(tagName, fromNative(other.getTag(tagName))); map.put(tagName, fromNative(other.getTag(tagName)));
@ -222,15 +222,15 @@ final class NBTConverter {
} }
public static FloatTag fromNative(NBTTagFloat other) { public static FloatTag fromNative(NBTTagFloat other) {
return new FloatTag(other.func_150288_h()); return new FloatTag(other.getFloat());
} }
public static ShortTag fromNative(NBTTagShort other) { public static ShortTag fromNative(NBTTagShort other) {
return new ShortTag(other.func_150289_e()); return new ShortTag(other.getShort());
} }
public static DoubleTag fromNative(NBTTagDouble other) { public static DoubleTag fromNative(NBTTagDouble other) {
return new DoubleTag(other.func_150286_g()); return new DoubleTag(other.getDouble());
} }
} }

View File

@ -19,10 +19,11 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@ -55,8 +56,9 @@ public class ThreadSafeCache {
if (now - lastRefresh > REFRESH_DELAY) { if (now - lastRefresh > REFRESH_DELAY) {
Set<UUID> onlineIds = new HashSet<UUID>(); Set<UUID> onlineIds = new HashSet<UUID>();
if (FMLCommonHandler.instance().getMinecraftServerInstance() == null) { MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
if (server == null || server.getConfigurationManager() == null) {
return; return;
} }
for (Object object : FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList) { for (Object object : FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList) {

View File

@ -1,40 +1,40 @@
/* /*
* WorldEdit, a Minecraft world manipulation toolkit * WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com> * Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors * Copyright (C) WorldEdit team and contributors
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the * under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or * Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.TileEntityBlock; import com.sk89q.worldedit.blocks.TileEntityBlock;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
public class TileEntityBaseBlock extends BaseBlock implements TileEntityBlock { public class TileEntityBaseBlock extends BaseBlock implements TileEntityBlock {
public TileEntityBaseBlock(int type, int data, TileEntity tile) { public TileEntityBaseBlock(int type, int data, TileEntity tile) {
super(type, data); super(type, data);
setNbtData(NBTConverter.fromNative(copyNbtData(tile))); setNbtData(NBTConverter.fromNative(copyNbtData(tile)));
} }
private static NBTTagCompound copyNbtData(TileEntity tile) { private static NBTTagCompound copyNbtData(TileEntity tile) {
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
tile.writeToNBT(tag); tile.writeToNBT(tag);
return tag; return tag;
} }
} }

View File

@ -20,12 +20,15 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import net.minecraft.nbt.NBTTagCompound; 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.world.World; import net.minecraft.world.World;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -81,10 +84,9 @@ final class TileEntityUtils {
tileEntity.readFromNBT(tag); tileEntity.readFromNBT(tag);
} }
tileEntity = ForgeWorldEdit.inst.getFMPCompat().overrideTileEntity(world, tag, tileEntity); world.setTileEntity(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()), tileEntity);
setTileEntity(world, position, tileEntity);
} }
/** /**
* Set a tile entity at the given location using the tile entity ID from * Set a tile entity at the given location using the tile entity ID from
* the tag. * the tag.
@ -96,26 +98,12 @@ final class TileEntityUtils {
static void setTileEntity(World world, Vector position, @Nullable NBTTagCompound tag) { static void setTileEntity(World world, Vector position, @Nullable NBTTagCompound tag) {
if (tag != null) { if (tag != null) {
updateForSet(tag, position); updateForSet(tag, position);
TileEntity tileEntity = makeTileEntity(world, position, tag); TileEntity tileEntity = TileEntity.createAndLoadEntity(tag);
if (tileEntity != null) { if (tileEntity != null) {
setTileEntity(world, position, tileEntity); world.setTileEntity(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()), tileEntity);
} }
} }
} }
private static TileEntity makeTileEntity(World world, Vector position,
NBTTagCompound tag) {
TileEntity normal = TileEntity.createAndLoadEntity(tag);
return ForgeWorldEdit.inst.getFMPCompat().overrideTileEntity(world, tag,
normal);
}
private static void setTileEntity(World world, Vector position,
TileEntity tileEntity) {
world.setTileEntity(position.getBlockX(), position.getBlockY(),
position.getBlockZ(), tileEntity);
ForgeWorldEdit.inst.getFMPCompat().sendDescPacket(world, tileEntity);
}
/** /**
* Construct a tile entity from the given class. * Construct a tile entity from the given class.

View File

@ -1,63 +1,72 @@
/* /*
* WorldEdit, a Minecraft world manipulation toolkit * WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com> * Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors * Copyright (C) WorldEdit team and contributors
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the * under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or * Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import java.nio.charset.Charset; import com.sk89q.worldedit.LocalSession;
import net.minecraft.entity.player.EntityPlayerMP; import java.nio.charset.Charset;
import net.minecraft.network.NetHandlerPlayServer; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.play.client.C17PacketCustomPayload; import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.PacketBuffer;
import com.sk89q.worldedit.LocalSession; import net.minecraft.network.ThreadQuickExitException;
import net.minecraft.network.play.server.S3FPacketCustomPayload;
import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.FMLEventChannel; import net.minecraftforge.fml.common.network.FMLEventChannel;
import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent; import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientCustomPacketEvent;
import cpw.mods.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
public class WECUIPacketHandler {
public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8"); public class WECUIPacketHandler {
private static FMLEventChannel WECUI_CHANNEL; public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
public static FMLEventChannel WECUI_CHANNEL;
public static void init() {
WECUI_CHANNEL = NetworkRegistry.INSTANCE.newEventDrivenChannel(ForgeWorldEdit.CUI_PLUGIN_CHANNEL); public static void init() {
WECUI_CHANNEL.register(new WECUIPacketHandler()); WECUI_CHANNEL = NetworkRegistry.INSTANCE.newEventDrivenChannel(ForgeWorldEdit.CUI_PLUGIN_CHANNEL);
} WECUI_CHANNEL.register(new WECUIPacketHandler());
}
@SubscribeEvent
public void onPacketData(ServerCustomPacketEvent event) { @SubscribeEvent
C17PacketCustomPayload rawPacket = (C17PacketCustomPayload) event.packet.toC17Packet(); public void onPacketData(ServerCustomPacketEvent event) {
if (event.packet.channel().equals(ForgeWorldEdit.CUI_PLUGIN_CHANNEL)) { if (event.packet.channel().equals(ForgeWorldEdit.CUI_PLUGIN_CHANNEL)) {
EntityPlayerMP player = getPlayerFromEvent(event); EntityPlayerMP player = getPlayerFromEvent(event);
LocalSession session = ForgeWorldEdit.inst.getSession((EntityPlayerMP) player); LocalSession session = ForgeWorldEdit.inst.getSession((EntityPlayerMP) player);
if (session.hasCUISupport()) { if (session.hasCUISupport()) {
return; return;
} }
String text = new String(rawPacket.func_149558_e(), UTF_8_CHARSET); String text = event.packet.payload().toString(UTF_8_CHARSET);
session.handleCUIInitializationMessage(text); session.handleCUIInitializationMessage(text);
} session.describeCUI(ForgeWorldEdit.inst.wrap(player));
} }
}
private static EntityPlayerMP getPlayerFromEvent(ServerCustomPacketEvent event) {
return ((NetHandlerPlayServer) event.handler).playerEntity; @SubscribeEvent
} public void callProcessPacket(ClientCustomPacketEvent event) {
try {
new S3FPacketCustomPayload(event.packet.channel(), new PacketBuffer(event.packet.payload())).processPacket(event.handler);
} catch (ThreadQuickExitException suppress) {
}
}
private static EntityPlayerMP getPlayerFromEvent(ServerCustomPacketEvent event) {
return ((NetHandlerPlayServer) event.handler).playerEntity;
}
} }

View File

@ -1,34 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.forge.compat;
import javax.annotation.Nullable;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public interface ForgeMultipartCompat {
TileEntity overrideTileEntity(World world, @Nullable NBTTagCompound tag,
TileEntity normal);
void sendDescPacket(World world, TileEntity entity);
}

View File

@ -1,51 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.forge.compat;
import codechicken.multipart.MultipartHelper;
import codechicken.multipart.TileMultipart;
import javax.annotation.Nullable;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class ForgeMultipartExistsCompat implements ForgeMultipartCompat {
@Override
public TileEntity overrideTileEntity(World world,
@Nullable NBTTagCompound tag, TileEntity normal) {
if (tag == null) {
return normal;
}
TileEntity tile = MultipartHelper.createTileFromNBT(world, tag);
if (tile == null) {
return normal;
}
return tile;
}
@Override
public void sendDescPacket(World world, TileEntity entity) {
if (entity instanceof TileMultipart) {
TileMultipart multi = (TileMultipart) entity;
MultipartHelper.sendDescPacket(world, multi);
}
}
}

View File

@ -1,38 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.forge.compat;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class NoForgeMultipartCompat implements ForgeMultipartCompat {
@Override
public TileEntity overrideTileEntity(World world, NBTTagCompound tag,
TileEntity normal) {
return normal;
}
@Override
public void sendDescPacket(World world, TileEntity entity) {
}
}

View File

@ -19,9 +19,9 @@
package com.sk89q.worldedit.forge.gui; package com.sk89q.worldedit.forge.gui;
import cpw.mods.fml.common.network.IGuiHandler;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;
public class GuiHandler implements IGuiHandler { public class GuiHandler implements IGuiHandler {

View File

@ -0,0 +1,4 @@
public net.minecraft.world.gen.ChunkProviderServer field_73248_b # droppedChunksSet
public net.minecraft.world.gen.ChunkProviderServer field_73244_f # id2ChunkMap
public net.minecraft.world.gen.ChunkProviderServer field_73245_g # loadedChunks
public net.minecraft.world.gen.ChunkProviderServer field_73246_d # serverChunkGenerator

View File

@ -1,12 +1,12 @@
[{ [{
"modid": "WorldEdit", "modid": "worldedit",
"name": "WorldEdit", "name": "WorldEdit",
"description": "WorldEdit is an easy-to-use in-game world editor for Minecraft, supporting both single player and multiplayer.", "description": "WorldEdit is an easy-to-use in-game world editor for Minecraft, supporting both single player and multiplayer.",
"version": "${internalVersion}", "version": "${internalVersion}",
"mcversion": "${mcVersion}", "mcversion": "${mcVersion}",
"url": "http://wiki.sk89q.com/wiki/WorldEdit", "url": "http://wiki.sk89q.com/wiki/WorldEdit",
"updateUrl": "", "updateUrl": "",
"authors": [ "sk89q", "wizjany", "TomyLobo" ], "authors": [ "sk89q", "wizjany", "TomyLobo", "kenzierocks" ],
"credits": "", "credits": "",
"logoFile": "", "logoFile": "",
"screenshots": [], "screenshots": [],
@ -15,7 +15,7 @@
], ],
"dependencies": [ "dependencies": [
"Forge@[${forgeVersion},)", "Forge@[${forgeVersion},)",
"ForgeMultipart" "sponge"
], ],
"dependants": [] "dependants": []
}] }]