Switch to Gradle. Use git log --follow for history.

This converts the project into a multi-module Gradle build.

By default, Git does not show history past a rename, so use git log
--follow to see further history.
This commit is contained in:
sk89q
2014-11-14 11:27:39 -08:00
parent 44559cde68
commit 7192780251
714 changed files with 333 additions and 834 deletions

View File

@ -0,0 +1,71 @@
buildscript {
repositories {
mavenCentral()
maven { url = "http://files.minecraftforge.net/maven" }
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
}
}
apply plugin: 'forge'
dependencies {
compile project(':worldedit-core')
testCompile group: 'org.mockito', name: 'mockito-core', version:'1.9.0-rc1'
}
minecraft {
ext.forgeVersion = "10.13.1.1225"
version = "1.7.10-$forgeVersion"
replaceIn "com/sk89q/worldedit/forge/ForgeWorldEdit.java"
replace "%VERSION%", project.version
}
project.archivesBaseName = "${project.archivesBaseName}-mc${minecraft.version}"
processResources {
from (sourceSets.main.resources.srcDirs) {
expand 'version': project.version,
'mcVersion': project.minecraft.version,
'forgeVersion': project.minecraft.forgeVersion,
'internalVersion': project.internalVersion
include 'mcmod.info'
}
from (sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
jar {
manifest {
attributes("Class-Path": "truezip.jar WorldEdit/truezip.jar js.jar WorldEdit/js.jar",
"WorldEdit-Version": version)
}
}
shadowJar {
dependencies {
include(dependency(':worldedit-core'))
}
}
reobf.reobf(shadowJar) { spec ->
spec.classpath = sourceSets.main.compileClasspath;
}
task deobfJar(type: Jar) {
from sourceSets.main.output
classifier = 'dev'
}
artifacts {
archives deobfJar
}
build.dependsOn(shadowJar)

View File

@ -0,0 +1,150 @@
<project name="WorldEdit-Forge" default="main">
<property environment="env"/>
<!-- Properties -->
<property name="build.dir" value="${maven.build.directory}/forge"/>
<property name="resource.dir" value="src/forge/resources"/>
<property name="src.forge.dir" value="src/forge/java"/>
<property name="src.we.dir" value="src/main/java"/>
<property name="bukkit.src.1" value="com/sk89q/bukkit"/>
<property name="bukkit.src.2" value="com/sk89q/worldedit/bukkit"/>
<property name="wepif.src" value="com/sk89q/wepif"/>
<property name="util.yaml.src" value="com/sk89q/util/yaml"/>
<property name="we.yaml.src" value="com/sk89q/worldedit/util/YAMLConfiguration.java"/>
<property name="download.dir" value="forge-download"/>
<property name="forge.dir" value="${build.dir}/forge"/>
<property name="mcp.dir" value="${forge.dir}/mcp"/>
<property name="minecraftsrc.dir" value="${mcp.dir}/src/minecraft"/>
<property file="${minecraftsrc.dir}/fmlversion.properties" />
<property name="mc.version" value="1.6.2"/>
<property name="forge.version" value="9.10.1.850"/>
<!-- Targets -->
<target name="init-msg">
<echo message="Starting build for ${we.version} for MC ${mc.version}"/>
</target>
<target name="download">
<mkdir dir="${download.dir}"/>
<get src="http://files.minecraftforge.net/minecraftforge/minecraftforge-src-${mc.version}-${forge.version}.zip" dest="${download.dir}" usetimestamp="True"/>
<echo message="Download finished"/>
</target>
<target name="check-setup-forge" depends="download">
<available file="${download.dir}/minecraftforge-setup-${mc.version}-${forge.version}.zip" property="setup.forge.present"/>
</target>
<target name="setup-forge" depends="check-setup-forge" unless="setup.forge.present">
<unzip dest="${build.dir}" failOnEmptyArchive="true">
<fileset dir="${download.dir}">
<include name="minecraftforge-src-${mc.version}-${forge.version}.zip"/>
</fileset>
</unzip>
<!-- Set executable permission on forge's *.sh -->
<chmod dir="${forge.dir}" perm="a+rx" includes="**.sh"/>
<!-- Install forge -->
<echo message="Starting forge install process"/>
<exec dir="${forge.dir}" executable="cmd" osfamily="windows" failonerror="true">
<arg value="/c"/>
<arg value="install.cmd"/>
</exec>
<exec dir="${forge.dir}" executable="sh" osfamily="unix" failonerror="true">
<arg value="install.sh"/>
</exec>
<echo message="Forge installation finished"/>
<zip destfile="${download.dir}/minecraftforge-setup-${mc.version}-${forge.version}.zip" basedir="${build.dir}"/>
</target>
<target name="unzip-forge" depends="check-setup-forge" if="setup.forge.present">
<unzip dest="${build.dir}" failOnEmptyArchive="true">
<fileset dir="${download.dir}">
<include name="minecraftforge-setup-${mc.version}-${forge.version}.zip"/>
</fileset>
</unzip>
</target>
<target name="copySRC" >
<!-- Copy WE dependencies source -->
<copy todir="${mcp.dir}/lib" file="${jchronic.path}"/>
<copy todir="${mcp.dir}/lib" file="${truezip.path}"/>
<copy todir="${mcp.dir}/lib" file="${rhino.path}"/>
<!--<copy todir="${mcp.dir}/lib" file="${snakeyaml.path}"/>-->
<!-- Copy WE forge source -->
<copy todir="${minecraftsrc.dir}">
<fileset dir="${src.forge.dir}"/>
</copy>
<!-- Copy WE source -->
<copy todir="${minecraftsrc.dir}">
<fileset dir="${src.we.dir}"/>
</copy>
<!-- Delete bukkit related sources -->
<delete dir="${minecraftsrc.dir}/${bukkit.src.1}"/>
<delete dir="${minecraftsrc.dir}/${bukkit.src.2}"/>
<delete dir="${minecraftsrc.dir}/${wepif.src}"/>
<delete dir="${minecraftsrc.dir}/${util.yaml.src}"/>
<delete file="${minecraftsrc.dir}/${we.yaml.src}"/>
<!-- Set Version -->
<replace file="${minecraftsrc.dir}/com/sk89q/worldedit/forge/WorldEditMod.java" token="%VERSION%" value="${we.version}"/>
</target>
<target name="compile" depends="copySRC">
<echo message="Compiling version ${we.version}"/>
<!-- Recompile -->
<exec dir="${mcp.dir}" executable="cmd" osfamily="windows" failonerror="true">
<arg line="/c recompile.bat --client"/>
</exec>
<exec dir="${mcp.dir}" executable="sh" osfamily="unix" failonerror="true">
<arg line="recompile.sh --client"/>
</exec>
<!-- Reobf -->
<exec dir="${mcp.dir}" executable="cmd" osfamily="windows" failonerror="true">
<arg line="/c reobfuscate_srg.bat --client"/>
</exec>
<exec dir="${mcp.dir}" executable="sh" osfamily="unix" failonerror="true">
<arg line="reobfuscate_srg.sh --client"/>
</exec>
<echo message="Compiling finished"/>
</target>
<target name="copyclasses" depends="compile">
<echo message="Adding version ${we.version} to maven result"/>
<!-- Copy WE classes -->
<copy todir="${maven.build.directory}/classes/com/sk89q/worldedit/forge">
<fileset dir="${mcp.dir}/reobf/minecraft/com/sk89q/worldedit/forge"/>
</copy>
<!-- Copy resources -->
<copy todir="${maven.build.directory}/classes">
<fileset dir="${resource.dir}"></fileset>
</copy>
<replace file="${maven.build.directory}/classes/mcmod.info" token="%VERSION%" value="${we.version}"/>
<replace file="${maven.build.directory}/classes/mcmod.info" token="%MCVERSION%" value="${mc.version}"/>
<echo message="Adding finished"/>
</target>
<target name="main" depends="init-msg, unzip-forge, setup-forge, copyclasses"/>
</project>

View File

@ -0,0 +1,39 @@
/*
* 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.Vector;
import com.sk89q.worldedit.world.World;
import net.minecraft.util.Vec3;
final class ForgeAdapter {
private ForgeAdapter() {
}
public static World adapt(net.minecraft.world.World world) {
return new ForgeWorld(world);
}
public static Vector adapt(Vec3 vector) {
return new Vector(vector.xCoord, vector.yCoord, vector.zCoord);
}
}

View File

@ -0,0 +1,115 @@
/*
* 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.google.common.base.Throwables;
import com.google.common.collect.HashBiMap;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.biome.BiomeData;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import net.minecraft.world.biome.BiomeGenBase;
import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Provides access to biome data in Forge.
*/
class ForgeBiomeRegistry implements BiomeRegistry {
private static Map<Integer, BiomeGenBase> biomes = Collections.emptyMap();
private static Map<Integer, BiomeData> biomeData = Collections.emptyMap();
@Nullable
@Override
public BaseBiome createFromId(int id) {
return new BaseBiome(id);
}
@Override
public List<BaseBiome> getBiomes() {
List<BaseBiome> list = new ArrayList<BaseBiome>();
for (int biome : biomes.keySet()) {
list.add(new BaseBiome(biome));
}
return list;
}
@Nullable
@Override
public BiomeData getData(BaseBiome biome) {
return biomeData.get(biome.getId());
}
/**
* Populate the internal static list of biomes.
*
* <p>If called repeatedly, the last call will overwrite all previous
* calls.</p>
*/
static void populate() {
Map<Integer, BiomeGenBase> biomes = HashBiMap.create();
Map<Integer, BiomeData> biomeData = new HashMap<Integer, BiomeData>();
for (BiomeGenBase biome : BiomeGenBase.getBiomeGenArray()) {
if ((biome == null) || (biomes.containsValue(biome))) {
continue;
}
biomes.put(biome.biomeID, biome);
biomeData.put(biome.biomeID, new ForgeBiomeData(biome));
}
ForgeBiomeRegistry.biomes = biomes;
ForgeBiomeRegistry.biomeData = biomeData;
}
/**
* Cached biome data information.
*/
private static class ForgeBiomeData implements BiomeData {
private final BiomeGenBase biome;
/**
* Create a new instance.
*
* @param biome the base biome
*/
private ForgeBiomeData(BiomeGenBase biome) {
this.biome = biome;
}
@Override
public String getName() {
return biome.biomeName;
}
}
}

View File

@ -0,0 +1,36 @@
/*
* 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.util.PropertiesConfiguration;
import java.io.File;
public class ForgeConfiguration extends PropertiesConfiguration {
public ForgeConfiguration(ForgeWorldEdit mod) {
super(new File(mod.getWorkingDir() + File.separator + "worldedit.properties"));
}
@Override
public File getWorkingDirectory() {
return ForgeWorldEdit.inst.getWorkingDir();
}
}

View File

@ -0,0 +1,111 @@
/*
* 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.Vector;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.metadata.EntityType;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.NullWorld;
import net.minecraft.entity.EntityList;
import net.minecraft.nbt.NBTTagCompound;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import static com.google.common.base.Preconditions.checkNotNull;
class ForgeEntity implements Entity {
private final WeakReference<net.minecraft.entity.Entity> entityRef;
ForgeEntity(net.minecraft.entity.Entity entity) {
checkNotNull(entity);
this.entityRef = new WeakReference<net.minecraft.entity.Entity>(entity);
}
@Override
public BaseEntity getState() {
net.minecraft.entity.Entity entity = entityRef.get();
if (entity != null) {
String id = EntityList.getEntityString(entity);
if (id != null) {
NBTTagCompound tag = new NBTTagCompound();
entity.writeToNBT(tag);
return new BaseEntity(id, NBTConverter.fromNative(tag));
} else {
return null;
}
} else {
return null;
}
}
@Override
public Location getLocation() {
net.minecraft.entity.Entity entity = entityRef.get();
if (entity != null) {
Vector position = new Vector(entity.posX, entity.posY, entity.posZ);
float yaw = entity.rotationYaw;
float pitch = entity.rotationPitch;
return new Location(ForgeAdapter.adapt(entity.worldObj), position, yaw, pitch);
} else {
return new Location(NullWorld.getInstance());
}
}
@Override
public Extent getExtent() {
net.minecraft.entity.Entity entity = entityRef.get();
if (entity != null) {
return ForgeAdapter.adapt(entity.worldObj);
} else {
return NullWorld.getInstance();
}
}
@Override
public boolean remove() {
net.minecraft.entity.Entity entity = entityRef.get();
if (entity != null) {
entity.setDead();
}
return true;
}
@SuppressWarnings("unchecked")
@Nullable
@Override
public <T> T getFacet(Class<? extends T> cls) {
net.minecraft.entity.Entity entity = entityRef.get();
if (entity != null) {
if (EntityType.class.isAssignableFrom(cls)) {
return (T) new ForgeEntityType(entity);
} else {
return null;
}
} else {
return null;
}
}
}

View File

@ -0,0 +1,138 @@
/*
* 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.entity.metadata.EntityType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.IMerchant;
import net.minecraft.entity.INpc;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.item.EntityBoat;
import net.minecraft.entity.item.EntityEnderEye;
import net.minecraft.entity.item.EntityFallingBlock;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.entity.item.EntityPainting;
import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.monster.EntityGolem;
import net.minecraft.entity.passive.EntityAmbientCreature;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.passive.IAnimals;
import net.minecraft.entity.player.EntityPlayer;
import static com.google.common.base.Preconditions.checkNotNull;
public class ForgeEntityType implements EntityType {
private final Entity entity;
public ForgeEntityType(Entity entity) {
checkNotNull(entity);
this.entity = entity;
}
@Override
public boolean isPlayerDerived() {
return entity instanceof EntityPlayer;
}
@Override
public boolean isProjectile() {
return entity instanceof EntityEnderEye || entity instanceof IProjectile;
}
@Override
public boolean isItem() {
return entity instanceof EntityItem;
}
@Override
public boolean isFallingBlock() {
return entity instanceof EntityFallingBlock;
}
@Override
public boolean isPainting() {
return entity instanceof EntityPainting;
}
@Override
public boolean isItemFrame() {
return entity instanceof EntityItemFrame;
}
@Override
public boolean isBoat() {
return entity instanceof EntityBoat;
}
@Override
public boolean isMinecart() {
return entity instanceof EntityMinecart;
}
@Override
public boolean isTNT() {
return entity instanceof EntityTNTPrimed;
}
@Override
public boolean isExperienceOrb() {
return entity instanceof EntityXPOrb;
}
@Override
public boolean isLiving() {
return entity instanceof EntityLiving;
}
@Override
public boolean isAnimal() {
return entity instanceof IAnimals;
}
@Override
public boolean isAmbient() {
return entity instanceof EntityAmbientCreature;
}
@Override
public boolean isNPC() {
return entity instanceof INpc || entity instanceof IMerchant;
}
@Override
public boolean isGolem() {
return entity instanceof EntityGolem;
}
@Override
public boolean isTamed() {
return entity instanceof EntityTameable && ((EntityTameable) entity).isTamed();
}
@Override
public boolean isTagged() {
return entity instanceof EntityLiving && ((EntityLiving) entity).hasCustomNameTag();
}
}

View File

@ -0,0 +1,228 @@
/*
* 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.LocalConfiguration;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.AbstractPlatform;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.MultiUserPlatform;
import com.sk89q.worldedit.extension.platform.Preference;
import com.sk89q.worldedit.util.command.CommandMapping;
import com.sk89q.worldedit.util.command.Description;
import com.sk89q.worldedit.util.command.Dispatcher;
import com.sk89q.worldedit.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.ServerCommandManager;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.ServerConfigurationManager;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
class ForgePlatform extends AbstractPlatform implements MultiUserPlatform {
private final ForgeWorldEdit mod;
private final MinecraftServer server;
private boolean hookingEvents = false;
ForgePlatform(ForgeWorldEdit mod) {
this.mod = mod;
this.server = FMLCommonHandler.instance().getMinecraftServerInstance();
}
boolean isHookingEvents() {
return hookingEvents;
}
@Override
public int resolveItem(String name) {
if (name == null) return 0;
for (Object itemObj : Item.itemRegistry) {
Item item = (Item) itemObj;
if (item == null) continue;
if (item.getUnlocalizedName() == null) continue;
if (item.getUnlocalizedName().startsWith("item.")) {
if (item.getUnlocalizedName().equalsIgnoreCase("item." + name)) return Item.getIdFromItem(item);
}
if (item.getUnlocalizedName().startsWith("tile.")) {
if (item.getUnlocalizedName().equalsIgnoreCase("tile." + name)) return Item.getIdFromItem(item);
}
if (item.getUnlocalizedName().equalsIgnoreCase(name)) return Item.getIdFromItem(item);
}
return 0;
}
@Override
public boolean isValidMobType(String type) {
return EntityList.stringToClassMapping.containsKey(type);
}
@Override
public void reload() {
}
@Override
public int schedule(long delay, long period, Runnable task) {
return -1;
}
@Override
public List<? extends com.sk89q.worldedit.world.World> getWorlds() {
List<WorldServer> worlds = Arrays.asList(DimensionManager.getWorlds());
List<com.sk89q.worldedit.world.World> ret = new ArrayList<com.sk89q.worldedit.world.World>(worlds.size());
for (WorldServer world : worlds) {
ret.add(new ForgeWorld(world));
}
return ret;
}
@Nullable
@Override
public Player matchPlayer(Player player) {
if (player instanceof ForgePlayer) {
return player;
} else {
EntityPlayerMP entity = server.getConfigurationManager().func_152612_a(player.getName());
return entity != null ? new ForgePlayer(entity) : null;
}
}
@Nullable
@Override
public World matchWorld(World world) {
if (world instanceof ForgeWorld) {
return world;
} else {
for (WorldServer ws : DimensionManager.getWorlds()) {
if (ws.getWorldInfo().getWorldName().equals(world.getName())) {
return new ForgeWorld(ws);
}
}
return null;
}
}
@Override
public void registerCommands(Dispatcher dispatcher) {
if (server == null) return;
ServerCommandManager mcMan = (ServerCommandManager) server.getCommandManager();
for (final CommandMapping command : dispatcher.getCommands()) {
final Description description = command.getDescription();
mcMan.registerCommand(new CommandBase() {
@Override
public String getCommandName() {
return command.getPrimaryAlias();
}
@Override
public List<String> getCommandAliases() {
return Arrays.asList(command.getAllAliases());
}
@Override
public void processCommand(ICommandSender var1, String[] var2) {}
@Override
public String getCommandUsage(ICommandSender icommandsender) {
return "/" + command.getPrimaryAlias() + " " + description.getUsage();
}
@Override
public int compareTo(@Nullable Object o) {
if (o == null) {
return 0;
} else if (o instanceof ICommand) {
return super.compareTo((ICommand) o);
} else {
return 0;
}
}
});
}
}
@Override
public void registerGameHooks() {
// We registered the events already anyway, so we just 'turn them on'
hookingEvents = true;
}
@Override
public LocalConfiguration getConfiguration() {
return mod.getConfig();
}
@Override
public String getVersion() {
return mod.getInternalVersion();
}
@Override
public String getPlatformName() {
return "Forge-Official";
}
@Override
public String getPlatformVersion() {
return mod.getInternalVersion();
}
@Override
public Map<Capability, Preference> getCapabilities() {
Map<Capability, Preference> capabilities = new EnumMap<Capability, Preference>(Capability.class);
capabilities.put(Capability.CONFIGURATION, Preference.PREFER_OTHERS);
capabilities.put(Capability.WORLDEDIT_CUI, Preference.NORMAL);
capabilities.put(Capability.GAME_HOOKS, Preference.NORMAL);
capabilities.put(Capability.PERMISSIONS, Preference.PREFER_OTHERS);
capabilities.put(Capability.USER_COMMANDS, Preference.NORMAL);
capabilities.put(Capability.WORLD_EDITING, Preference.PREFERRED);
return capabilities;
}
@Override
public Collection<Actor> getConnectedUsers() {
List<Actor> users = new ArrayList<Actor>();
ServerConfigurationManager scm = server.getConfigurationManager();
for (String name : scm.getAllUsernames()) {
EntityPlayerMP entity = scm.func_152612_a(name);
if (entity != null) {
users.add(new ForgePlayer(entity));
}
}
return users;
}
}

View File

@ -0,0 +1,214 @@
/*
* 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.util.StringUtil;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extension.platform.AbstractPlayerActor;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.LocalWorldAdapter;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.Location;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.server.S3FPacketCustomPayload;
import net.minecraft.util.ChatComponentText;
import javax.annotation.Nullable;
import java.util.UUID;
public class ForgePlayer extends AbstractPlayerActor {
private EntityPlayerMP player;
protected ForgePlayer(EntityPlayerMP player) {
this.player = player;
ThreadSafeCache.getInstance().getOnlineIds().add(getUniqueId());
}
@Override
public UUID getUniqueId() {
return player.getUniqueID();
}
@Override
public int getItemInHand() {
ItemStack is = this.player.getCurrentEquippedItem();
return is == null ? 0 : Item.getIdFromItem(is.getItem());
}
@Override
public String getName() {
return this.player.getCommandSenderName();
}
@Override
public BaseEntity getState() {
throw new UnsupportedOperationException("Cannot create a state from this object");
}
@Override
public Location getLocation() {
Vector position = new Vector(this.player.posX, this.player.posY, this.player.posZ);
return new Location(
ForgeWorldEdit.inst.getWorld(this.player.worldObj),
position,
this.player.cameraYaw,
this.player.cameraPitch);
}
@Override
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 com.sk89q.worldedit.world.World getWorld() {
return ForgeWorldEdit.inst.getWorld(this.player.worldObj);
}
@Override
public double getPitch() {
return this.player.rotationPitch;
}
@Override
public double getYaw() {
return this.player.rotationYaw;
}
@Override
public void giveItem(int type, int amt) {
this.player.inventory.addItemStackToInventory(new ItemStack(Item.getItemById(type), amt, 0));
}
@Override
public void dispatchCUIEvent(CUIEvent event) {
String[] params = event.getParameters();
String send = event.getTypeId();
if (params.length > 0) {
send = send + "|" + StringUtil.joinString(params, "|");
}
S3FPacketCustomPayload packet = new S3FPacketCustomPayload(ForgeWorldEdit.CUI_PLUGIN_CHANNEL, send.getBytes(WECUIPacketHandler.UTF_8_CHARSET));
this.player.playerNetServerHandler.sendPacket(packet);
}
@Override
public void printRaw(String msg) {
for (String part : msg.split("\n")) {
this.player.addChatMessage(new ChatComponentText(part));
}
}
@Override
public void printDebug(String msg) {
for (String part : msg.split("\n")) {
this.player.addChatMessage(new ChatComponentText("\u00a77" + part));
}
}
@Override
public void print(String msg) {
for (String part : msg.split("\n")) {
this.player.addChatMessage(new ChatComponentText("\u00a7d" + part));
}
}
@Override
public void printError(String msg) {
for (String part : msg.split("\n")) {
this.player.addChatMessage(new ChatComponentText("\u00a7c" + part));
}
}
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
this.player.playerNetServerHandler.setPlayerLocation(pos.getX(), pos.getY(), pos.getZ(), pitch, yaw);
}
@Override
public String[] getGroups() {
return new String[]{}; // WorldEditMod.inst.getPermissionsResolver().getGroups(this.player.username);
}
@Override
public BlockBag getInventoryBlockBag() {
return null;
}
@Override
public boolean hasPermission(String perm) {
return ForgeUtil.hasPermission(this.player, perm);
}
@Nullable
@Override
public <T> T getFacet(Class<? extends T> cls) {
return null;
}
@Override
public SessionKey getSessionKey() {
return new SessionKeyImpl(player.getUniqueID(), player.getCommandSenderName());
}
private static class SessionKeyImpl implements SessionKey {
// If not static, this will leak a reference
private final UUID uuid;
private final String name;
private SessionKeyImpl(UUID uuid, String name) {
this.uuid = uuid;
this.name = name;
}
@Override
public UUID getUniqueId() {
return uuid;
}
@Nullable
@Override
public String getName() {
return name;
}
@Override
public boolean isActive() {
// We can't directly check if the player is online because
// the list of players is not thread safe
return ThreadSafeCache.getInstance().getOnlineIds().contains(uuid);
}
@Override
public boolean isPersistent() {
return true;
}
}
}

View File

@ -0,0 +1,48 @@
/*
* 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.BaseItemStack;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import java.util.Map;
public final class ForgeUtil {
private ForgeUtil() {
}
public static boolean hasPermission(EntityPlayerMP player, String perm) {
// TODO fix WEPIF
return FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().func_152596_g(player.getGameProfile());
}
public static ItemStack toForgeItemStack(BaseItemStack item) {
ItemStack ret = new ItemStack(Item.getItemById(item.getType()), item.getAmount(), item.getData());
for (Map.Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) {
ret.addEnchantment(net.minecraft.enchantment.Enchantment.enchantmentsList[((Integer) entry.getKey())], (Integer) entry.getValue());
}
return ret;
}
}

View File

@ -0,0 +1,435 @@
/*
* 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.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.LazyBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.registry.WorldData;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.LongHashMap;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.ChunkProviderServer;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* An adapter to Minecraft worlds for WorldEdit.
*/
public class ForgeWorld extends AbstractWorld {
private static final Logger logger = Logger.getLogger(ForgeWorld.class.getCanonicalName());
private final WeakReference<World> worldRef;
/**
* Construct a new world.
*
* @param world the world
*/
ForgeWorld(World world) {
checkNotNull(world);
this.worldRef = new WeakReference<World>(world);
}
/**
* Get the underlying handle to the world.
*
* @return the 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();
if (world != null) {
return world;
} else {
throw new WorldReferenceLostException("The reference to the world was lost (i.e. the world may have been unloaded)");
}
}
/**
* Get the underlying handle to the world.
*
* @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();
if (world != null) {
return world;
} else {
throw new RuntimeException("The reference to the world was lost (i.e. the world may have been unloaded)");
}
}
@Override
public String getName() {
return getWorld().getWorldInfo().getWorldName();
}
@Override
public boolean setBlock(Vector position, BaseBlock block, boolean notifyAndLight) throws WorldEditException {
checkNotNull(position);
checkNotNull(block);
World world = getWorldChecked();
int x = position.getBlockX();
int y = position.getBlockY();
int z = position.getBlockZ();
// First set the block
Chunk chunk = world.getChunkFromChunkCoords(x >> 4, z >> 4);
int previousId = 0;
if (notifyAndLight) {
previousId = Block.getIdFromBlock(chunk.getBlock(x & 15, y, z & 15));
}
boolean successful = chunk.func_150807_a(x & 15, y, z & 15, Block.getBlockById(block.getId()), block.getData());
// Create the TileEntity
if (successful) {
CompoundTag tag = block.getNbtData();
if (tag != null) {
NBTTagCompound nativeTag = NBTConverter.toNative(tag);
nativeTag.setString("id", block.getNbtId());
TileEntityUtils.setTileEntity(getWorld(), position, nativeTag);
}
}
if (notifyAndLight) {
world.func_147451_t(x, y, z);
world.markBlockForUpdate(x, y, z);
world.notifyBlockChange(x, y, z, Block.getBlockById(previousId));
Block mcBlock = Block.getBlockById(previousId);
if (mcBlock != null && mcBlock.hasComparatorInputOverride()) {
world.func_147453_f(x, y, z, Block.getBlockById(block.getId()));
}
}
return successful;
}
@Override
public int getBlockLightLevel(Vector position) {
checkNotNull(position);
return getWorld().getBlockLightValue(position.getBlockX(), position.getBlockY(), position.getBlockZ());
}
@Override
public boolean clearContainerBlockContents(Vector position) {
checkNotNull(position);
TileEntity tile = getWorld().getTileEntity(position.getBlockX(), position.getBlockY(), position.getBlockZ());
if ((tile instanceof IInventory)) {
IInventory inv = (IInventory) tile;
int size = inv.getSizeInventory();
for (int i = 0; i < size; i++) {
inv.setInventorySlotContents(i, null);
}
return true;
}
return false;
}
@Override
public BaseBiome getBiome(Vector2D position) {
checkNotNull(position);
return new BaseBiome(getWorld().getBiomeGenForCoords(position.getBlockX(), position.getBlockZ()).biomeID);
}
@Override
public boolean setBiome(Vector2D position, BaseBiome biome) {
checkNotNull(position);
checkNotNull(biome);
Chunk chunk = getWorld().getChunkFromBlockCoords(position.getBlockX(), position.getBlockZ());
if ((chunk != null) && (chunk.isChunkLoaded)) {
chunk.getBiomeArray()[((position.getBlockZ() & 0xF) << 4 | position.getBlockX() & 0xF)] = (byte) biome.getId();
return true;
}
return false;
}
@Override
public void dropItem(Vector position, BaseItemStack item) {
checkNotNull(position);
checkNotNull(item);
if (item.getType() == 0) {
return;
}
EntityItem entity = new EntityItem(getWorld(), position.getX(), position.getY(), position.getZ(), ForgeUtil.toForgeItemStack(item));
entity.delayBeforeCanPickup = 10;
getWorld().spawnEntityInWorld(entity);
}
@Override
public boolean regenerate(Region region, EditSession editSession) {
BaseBlock[] history = new BaseBlock[256 * (getMaxY() + 1)];
for (Vector2D chunk : region.getChunks()) {
Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
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);
int index = y * 16 * 16 + z * 16 + x;
history[index] = editSession.getBlock(pt);
}
}
}
try {
Set<Vector2D> chunks = region.getChunks();
IChunkProvider provider = getWorld().getChunkProvider();
if (!(provider instanceof ChunkProviderServer)) {
return false;
}
ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
Field u;
try {
u = ChunkProviderServer.class.getDeclaredField("field_73248_b"); // chunksToUnload
} catch(NoSuchFieldException e) {
u = ChunkProviderServer.class.getDeclaredField("chunksToUnload");
}
u.setAccessible(true);
Set<?> unloadQueue = (Set<?>) u.get(chunkServer);
Field m;
try {
m = ChunkProviderServer.class.getDeclaredField("field_73244_f"); // loadedChunkHashMap
} catch(NoSuchFieldException e) {
m = ChunkProviderServer.class.getDeclaredField("loadedChunkHashMap");
}
m.setAccessible(true);
LongHashMap loadedMap = (LongHashMap) m.get(chunkServer);
Field lc;
try {
lc = ChunkProviderServer.class.getDeclaredField("field_73245_g"); // loadedChunkHashMap
} catch(NoSuchFieldException e) {
lc = ChunkProviderServer.class.getDeclaredField("loadedChunks");
}
lc.setAccessible(true);
@SuppressWarnings("unchecked") List<Chunk> loaded = (List<Chunk>) lc.get(chunkServer);
Field p;
try {
p = ChunkProviderServer.class.getDeclaredField("field_73246_d"); // currentChunkProvider
} catch(NoSuchFieldException e) {
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());
Chunk mcChunk;
if (chunkServer.chunkExists(coord.getBlockX(), coord.getBlockZ())) {
mcChunk = chunkServer.loadChunk(coord.getBlockX(), coord.getBlockZ());
mcChunk.onChunkUnload();
}
unloadQueue.remove(pos);
loadedMap.remove(pos);
mcChunk = chunkProvider.provideChunk(coord.getBlockX(), coord.getBlockZ());
loadedMap.add(pos, mcChunk);
loaded.add(mcChunk);
if (mcChunk != null) {
mcChunk.onChunkLoad();
mcChunk.populateChunk(chunkProvider, chunkProvider, coord.getBlockX(), coord.getBlockZ());
}
}
} catch (Throwable t) {
logger.log(Level.WARNING, "Failed to generate chunk", t);
return false;
}
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);
int index = y * 16 * 16 + z * 16 + x;
if (!region.contains(pt))
editSession.smartSetBlock(pt, history[index]);
else {
editSession.rememberChange(pt, history[index], editSession.rawGetBlock(pt));
}
}
}
}
}
return false;
}
@Override
public boolean generateTree(TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException {
return false;
}
@Override
public WorldData getWorldData() {
return ForgeWorldData.getInstance();
}
@Override
public boolean isValidBlockType(int id) {
return (id == 0) || (net.minecraft.block.Block.getBlockById(id) != null);
}
@Override
public BaseBlock getBlock(Vector position) {
World world = getWorld();
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());
if (tile != null) {
return new TileEntityBaseBlock(id, data, tile);
} else {
return new BaseBlock(id, data);
}
}
@Override
public BaseBlock getLazyBlock(Vector position) {
World world = getWorld();
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 int hashCode() {
return getWorld().hashCode();
}
@Override
public boolean equals(Object o) {
if (o == null) {
return false;
} else if ((o instanceof ForgeWorld)) {
ForgeWorld other = ((ForgeWorld) o);
World otherWorld = other.worldRef.get();
World thisWorld = worldRef.get();
return otherWorld != null && thisWorld != null && otherWorld.equals(thisWorld);
} else if (o instanceof com.sk89q.worldedit.world.World) {
return ((com.sk89q.worldedit.world.World) o).getName().equals(getName());
} else {
return false;
}
}
@Override
@SuppressWarnings("unchecked")
public List<? extends Entity> getEntities(Region region) {
List<Entity> entities = new ArrayList<Entity>();
World world = getWorld();
for (Vector2D pt : region.getChunks()) {
if (!world.getChunkProvider().chunkExists(pt.getBlockX(), pt.getBlockZ())) {
continue;
}
Chunk chunk = world.getChunkProvider().provideChunk(pt.getBlockX(), pt.getBlockZ());
for (List<net.minecraft.entity.Entity> entitySubList : chunk.entityLists) {
for (net.minecraft.entity.Entity entity : entitySubList) {
if (region.contains(new Vector(entity.posX, entity.posY, entity.posZ))) {
entities.add(new ForgeEntity(entity));
}
}
}
}
return entities;
}
@Override
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

@ -0,0 +1,53 @@
/*
* 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.world.registry.BiomeRegistry;
import com.sk89q.worldedit.world.registry.LegacyWorldData;
/**
* World data for the Forge platform.
*/
class ForgeWorldData extends LegacyWorldData {
private static final ForgeWorldData INSTANCE = new ForgeWorldData();
private final BiomeRegistry biomeRegistry = new ForgeBiomeRegistry();
/**
* Create a new instance.
*/
ForgeWorldData() {
}
@Override
public BiomeRegistry getBiomeRegistry() {
return biomeRegistry;
}
/**
* Get a static instance.
*
* @return an instance
*/
public static ForgeWorldData getInstance() {
return INSTANCE;
}
}

View File

@ -0,0 +1,294 @@
/*
* 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.google.common.base.Joiner;
import com.google.common.io.ByteStreams;
import com.google.common.io.Closer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.internal.LocalWorldAdapter;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
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.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.CommandEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import javax.annotation.Nullable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
import static net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
/**
* The Forge implementation of WorldEdit.
*/
@Mod(modid = "WorldEdit", name = "WorldEdit", version = "%VERSION%", acceptableRemoteVersions = "*")
public class ForgeWorldEdit {
public static Logger logger;
public static final String CUI_PLUGIN_CHANNEL = "WECUI";
@Instance("WorldEdit")
public static ForgeWorldEdit inst;
private ForgePlatform platform;
private ForgeConfiguration config;
private File workingDir;
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
logger = event.getModLog();
// Setup working directory
workingDir = new File(event.getModConfigurationDirectory() + File.separator + "worldedit");
workingDir.mkdir();
// Create default configuration
createDefaultConfiguration(event.getSourceFile(), "worldedit.properties");
config = new ForgeConfiguration(this);
config.load();
FMLCommonHandler.instance().bus().register(ThreadSafeCache.getInstance());
}
@EventHandler
public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(this);
}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
logger.info("WorldEdit for Forge (version " + getInternalVersion() + ") is loaded");
}
@EventHandler
public void serverAboutToStart(FMLServerAboutToStartEvent event) {
if (this.platform != null) {
logger.warn("FMLServerStartingEvent occurred when FMLServerStoppingEvent hasn't");
WorldEdit.getInstance().getPlatformManager().unregister(platform);
}
ForgeBiomeRegistry.populate();
this.platform = new ForgePlatform(this);
WorldEdit.getInstance().getPlatformManager().register(platform);
}
@EventHandler
public void serverStopping(FMLServerStoppingEvent event) {
WorldEdit.getInstance().getPlatformManager().unregister(platform);
}
@EventHandler
public void serverStarted(FMLServerStartedEvent event) {
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent());
}
@SubscribeEvent
public void onCommandEvent(CommandEvent event) {
if ((event.sender instanceof EntityPlayerMP)) {
if (((EntityPlayerMP) event.sender).worldObj.isRemote) return;
String[] split = new String[event.parameters.length + 1];
System.arraycopy(event.parameters, 0, split, 1, event.parameters.length);
split[0] = event.command.getCommandName();
com.sk89q.worldedit.event.platform.CommandEvent weEvent =
new com.sk89q.worldedit.event.platform.CommandEvent(wrap((EntityPlayerMP) event.sender), Joiner.on(" ").join(split));
WorldEdit.getInstance().getEventBus().post(weEvent);
}
}
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event) {
if (platform == null) {
return;
}
if (!platform.isHookingEvents()) return; // We have to be told to catch these events
if (event.useItem == Result.DENY || event.entity.worldObj.isRemote) return;
WorldEdit we = WorldEdit.getInstance();
ForgePlayer player = wrap((EntityPlayerMP) event.entityPlayer);
ForgeWorld world = getWorld(event.entityPlayer.worldObj);
Action action = event.action;
switch (action) {
case LEFT_CLICK_BLOCK: {
WorldVector pos = new WorldVector(LocalWorldAdapter.adapt(world), event.x, event.y, event.z);
if (we.handleBlockLeftClick(player, pos)) {
event.setCanceled(true);
}
if (we.handleArmSwing(player)) {
event.setCanceled(true);
}
break;
}
case RIGHT_CLICK_BLOCK: {
WorldVector pos = new WorldVector(LocalWorldAdapter.adapt(world), event.x, event.y, event.z);
if (we.handleBlockRightClick(player, pos)) {
event.setCanceled(true);
}
if (we.handleRightClick(player)) {
event.setCanceled(true);
}
break;
}
case RIGHT_CLICK_AIR: {
if (we.handleRightClick(player)) {
event.setCanceled(true);
}
break;
}
}
}
/**
* Get the configuration.
*
* @return the Forge configuration
*/
ForgeConfiguration getConfig() {
return this.config;
}
/**
* Get the WorldEdit proxy for the given player.
*
* @param player the player
* @return the WorldEdit player
*/
public ForgePlayer wrap(EntityPlayerMP player) {
checkNotNull(player);
return new ForgePlayer(player);
}
/**
* Get the session for a player.
*
* @param player the player
* @return the session
*/
public LocalSession getSession(EntityPlayerMP player) {
checkNotNull(player);
return WorldEdit.getInstance().getSessionManager().get(wrap(player));
}
/**
* Get the WorldEdit proxy for the given world.
*
* @param world the world
* @return the WorldEdit world
*/
public ForgeWorld getWorld(World world) {
checkNotNull(world);
return new ForgeWorld(world);
}
/**
* Get the WorldEdit proxy for the platform.
*
* @return the WorldEdit platform
*/
public Platform getPlatform() {
return this.platform;
}
/**
* Get the working directory where WorldEdit's files are stored.
*
* @return the working directory
*/
public File getWorkingDir() {
return this.workingDir;
}
/**
* Create the default configuration.
*
* @param jar the jar
* @param name the name
*/
private void createDefaultConfiguration(File jar, String name) {
checkNotNull(jar);
checkNotNull(name);
String path = "/defaults/" + name;
File targetFile = new File(getWorkingDir(), name);
Closer closer = Closer.create();
try {
@Nullable InputStream inputStream = getClass().getResourceAsStream(path);
if (inputStream == null) {
throw new IOException("Failed to get resource '" + path + "' from .class");
}
closer.register(inputStream);
FileOutputStream outputStream = new FileOutputStream(targetFile);
ByteStreams.copy(inputStream, outputStream);
logger.info("Default configuration file written: " + name);
} catch (IOException e) {
logger.log(Level.WARN, "Failed to extract defaults", e);
} finally {
try {
closer.close();
} catch (IOException ignored) {
}
}
}
/**
* Get the version of the WorldEdit-for-Forge implementation.
*
* @return a version string
*/
String getInternalVersion() {
return ForgeWorldEdit.class.getAnnotation(Mod.class).version();
}
}

View File

@ -0,0 +1,236 @@
/*
* 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.jnbt.*;
import net.minecraft.nbt.*;
import java.util.*;
import java.util.Map.Entry;
/**
* Converts between JNBT and Minecraft NBT classes.
*/
final class NBTConverter {
private NBTConverter() {
}
public static NBTBase toNative(Tag tag) {
if (tag instanceof IntArrayTag) {
return toNative((IntArrayTag) tag);
} else if (tag instanceof ListTag) {
return toNative((ListTag) tag);
} else if (tag instanceof LongTag) {
return toNative((LongTag) tag);
} else if (tag instanceof StringTag) {
return toNative((StringTag) tag);
} else if (tag instanceof IntTag) {
return toNative((IntTag) tag);
} else if (tag instanceof ByteTag) {
return toNative((ByteTag) tag);
} else if (tag instanceof ByteArrayTag) {
return toNative((ByteArrayTag) tag);
} else if (tag instanceof CompoundTag) {
return toNative((CompoundTag) tag);
} else if (tag instanceof FloatTag) {
return toNative((FloatTag) tag);
} else if (tag instanceof ShortTag) {
return toNative((ShortTag) tag);
} else if (tag instanceof DoubleTag) {
return toNative((DoubleTag) tag);
} else {
throw new IllegalArgumentException("Can't convert tag of type " + tag.getClass().getCanonicalName());
}
}
public static NBTTagIntArray toNative(IntArrayTag tag) {
int[] value = tag.getValue();
return new NBTTagIntArray(Arrays.copyOf(value, value.length));
}
public static NBTTagList toNative(ListTag tag) {
NBTTagList list = new NBTTagList();
for (Tag child : tag.getValue()) {
if (child instanceof EndTag) {
continue;
}
list.appendTag(toNative(child));
}
return list;
}
public static NBTTagLong toNative(LongTag tag) {
return new NBTTagLong(tag.getValue());
}
public static NBTTagString toNative(StringTag tag) {
return new NBTTagString(tag.getValue());
}
public static NBTTagInt toNative(IntTag tag) {
return new NBTTagInt(tag.getValue());
}
public static NBTTagByte toNative(ByteTag tag) {
return new NBTTagByte(tag.getValue());
}
public static NBTTagByteArray toNative(ByteArrayTag tag) {
byte[] value = tag.getValue();
return new NBTTagByteArray(Arrays.copyOf(value, value.length));
}
public static NBTTagCompound toNative(CompoundTag tag) {
NBTTagCompound compound = new NBTTagCompound();
for (Entry<String, Tag> child : tag.getValue().entrySet()) {
compound.setTag(child.getKey(), toNative(child.getValue()));
}
return compound;
}
public static NBTTagFloat toNative(FloatTag tag) {
return new NBTTagFloat(tag.getValue());
}
public static NBTTagShort toNative(ShortTag tag) {
return new NBTTagShort(tag.getValue());
}
public static NBTTagDouble toNative(DoubleTag tag) {
return new NBTTagDouble(tag.getValue());
}
public static Tag fromNative(NBTBase other) {
if (other instanceof NBTTagIntArray) {
return fromNative((NBTTagIntArray) other);
} else if (other instanceof NBTTagList) {
return fromNative((NBTTagList) other);
} else if (other instanceof NBTTagEnd) {
return fromNative((NBTTagEnd) other);
} else if (other instanceof NBTTagLong) {
return fromNative((NBTTagLong) other);
} else if (other instanceof NBTTagString) {
return fromNative((NBTTagString) other);
} else if (other instanceof NBTTagInt) {
return fromNative((NBTTagInt) other);
} else if (other instanceof NBTTagByte) {
return fromNative((NBTTagByte) other);
} else if (other instanceof NBTTagByteArray) {
return fromNative((NBTTagByteArray) other);
} else if (other instanceof NBTTagCompound) {
return fromNative((NBTTagCompound) other);
} else if (other instanceof NBTTagFloat) {
return fromNative((NBTTagFloat) other);
} else if (other instanceof NBTTagShort) {
return fromNative((NBTTagShort) other);
} else if (other instanceof NBTTagDouble) {
return fromNative((NBTTagDouble) other);
} else {
throw new IllegalArgumentException("Can't convert other of type " + other.getClass().getCanonicalName());
}
}
public static IntArrayTag fromNative(NBTTagIntArray other) {
int[] value = other.func_150302_c();
return new IntArrayTag(Arrays.copyOf(value, value.length));
}
public static ListTag fromNative(NBTTagList other) {
other = (NBTTagList) other.copy();
List<Tag> list = new ArrayList<Tag>();
Class<? extends Tag> listClass = StringTag.class;
int tags = other.tagCount();
for (int i = 0; i < tags; i++) {
Tag child = fromNative(other.removeTag(0));
list.add(child);
listClass = child.getClass();
}
return new ListTag(listClass, list);
}
public static EndTag fromNative(NBTTagEnd other) {
return new EndTag();
}
public static LongTag fromNative(NBTTagLong other) {
return new LongTag(other.func_150291_c());
}
public static StringTag fromNative(NBTTagString other) {
return new StringTag(other.func_150285_a_());
}
public static IntTag fromNative(NBTTagInt other) {
return new IntTag(other.func_150287_d());
}
public static ByteTag fromNative(NBTTagByte other) {
return new ByteTag(other.func_150290_f());
}
public static ByteArrayTag fromNative(NBTTagByteArray other) {
byte[] value = other.func_150292_c();
return new ByteArrayTag(Arrays.copyOf(value, value.length));
}
public static CompoundTag fromNative(NBTTagCompound other) {
@SuppressWarnings("unchecked") Collection<String> tags = other.func_150296_c();
Map<String, Tag> map = new HashMap<String, Tag>();
for (String tagName : tags) {
map.put(tagName, fromNative(other.getTag(tagName)));
}
return new CompoundTag(map);
}
public static FloatTag fromNative(NBTTagFloat other) {
return new FloatTag(other.func_150288_h());
}
public static ShortTag fromNative(NBTTagShort other) {
return new ShortTag(other.func_150289_e());
}
public static DoubleTag fromNative(NBTTagDouble other) {
return new DoubleTag(other.func_150286_g());
}
}

View File

@ -0,0 +1,79 @@
/*
* 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 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 java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArraySet;
/**
* Caches data that cannot be accessed from another thread safely.
*/
public class ThreadSafeCache {
private static final long REFRESH_DELAY = 1000 * 30;
private static final ThreadSafeCache INSTANCE = new ThreadSafeCache();
private Set<UUID> onlineIds = Collections.emptySet();
private long lastRefresh = 0;
/**
* Get an concurrent-safe set of UUIDs of online players.
*
* @return a set of UUIDs
*/
public Set<UUID> getOnlineIds() {
return onlineIds;
}
@SubscribeEvent
public void tickStart(TickEvent event) {
long now = System.currentTimeMillis();
if (now - lastRefresh > REFRESH_DELAY) {
Set<UUID> onlineIds = new HashSet<UUID>();
if (FMLCommonHandler.instance().getMinecraftServerInstance() == null) {
return;
}
for (Object object : FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList) {
if (object != null) {
EntityPlayerMP player = (EntityPlayerMP) object;
onlineIds.add(player.getUniqueID());
}
}
this.onlineIds = new CopyOnWriteArraySet<UUID>(onlineIds);
lastRefresh = now;
}
}
public static ThreadSafeCache getInstance() {
return INSTANCE;
}
}

View File

@ -0,0 +1,40 @@
/*
* 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.BaseBlock;
import com.sk89q.worldedit.blocks.TileEntityBlock;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
public class TileEntityBaseBlock extends BaseBlock implements TileEntityBlock {
public TileEntityBaseBlock(int type, int data, TileEntity tile) {
super(type, data);
setNbtData(NBTConverter.fromNative(copyNbtData(tile)));
}
private static NBTTagCompound copyNbtData(TileEntity tile) {
NBTTagCompound tag = new NBTTagCompound();
tile.writeToNBT(tag);
return tag;
}
}

View File

@ -0,0 +1,143 @@
/*
* 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.Vector;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import javax.annotation.Nullable;
import java.lang.reflect.Constructor;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Utility methods for setting tile entities in the world.
*/
final class TileEntityUtils {
private TileEntityUtils() {
}
/**
* Update the given tag compound with position information.
*
* @param tag the tag
* @param position the position
* @return a tag compound
*/
private static NBTTagCompound updateForSet(NBTTagCompound tag, Vector position) {
checkNotNull(tag);
checkNotNull(position);
tag.setTag("x", new NBTTagInt(position.getBlockX()));
tag.setTag("y", new NBTTagInt(position.getBlockY()));
tag.setTag("z", new NBTTagInt(position.getBlockZ()));
return tag;
}
/**
* Set a tile entity at the given location.
*
* @param world the world
* @param position the position
* @param clazz the tile entity class
* @param tag the tag for the tile entity (may be null to not set NBT data)
*/
static void setTileEntity(World world, Vector position, Class<? extends TileEntity> clazz, @Nullable NBTTagCompound tag) {
checkNotNull(world);
checkNotNull(position);
checkNotNull(clazz);
TileEntity tileEntity = constructTileEntity(world, position, clazz);
if (tileEntity == null) {
return;
}
if (tag != null) {
// Set X, Y, Z
updateForSet(tag, position);
tileEntity.readFromNBT(tag);
}
world.setTileEntity(position.getBlockX(), position.getBlockY(), position.getBlockZ(), tileEntity);
}
/**
* Set a tile entity at the given location using the tile entity ID from
* the tag.
*
* @param world the world
* @param position the position
* @param tag the tag for the tile entity (may be null to do nothing)
*/
static void setTileEntity(World world, Vector position, @Nullable NBTTagCompound tag) {
if (tag != null) {
updateForSet(tag, position);
TileEntity tileEntity = TileEntity.createAndLoadEntity(tag);
if (tileEntity != null) {
world.setTileEntity(position.getBlockX(), position.getBlockY(), position.getBlockZ(), tileEntity);
}
}
}
/**
* Construct a tile entity from the given class.
*
* @param world the world
* @param position the position
* @param clazz the class
* @return a tile entity (may be null if it failed)
*/
@Nullable
static TileEntity constructTileEntity(World world, Vector position, Class<? extends TileEntity> clazz) {
Constructor<? extends TileEntity> baseConstructor;
try {
baseConstructor = clazz.getConstructor(); // creates "blank" TE
} catch (Throwable e) {
return null; // every TE *should* have this constructor, so this isn't necessary
}
TileEntity genericTE;
try {
// Downcast here for return while retaining the type
genericTE = (TileEntity) baseConstructor.newInstance();
} catch (Throwable e) {
return null;
}
/*
genericTE.blockType = Block.blocksList[block.getId()];
genericTE.blockMetadata = block.getData();
genericTE.xCoord = pt.getBlockX();
genericTE.yCoord = pt.getBlockY();
genericTE.zCoord = pt.getBlockZ();
genericTE.worldObj = world;
*/ // handled by internal code
return genericTE;
}
}

View File

@ -0,0 +1,63 @@
/*
* 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 java.nio.charset.Charset;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.play.client.C17PacketCustomPayload;
import com.sk89q.worldedit.LocalSession;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.FMLEventChannel;
import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
public class WECUIPacketHandler {
public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
private static FMLEventChannel WECUI_CHANNEL;
public static void init() {
WECUI_CHANNEL = NetworkRegistry.INSTANCE.newEventDrivenChannel(ForgeWorldEdit.CUI_PLUGIN_CHANNEL);
WECUI_CHANNEL.register(new WECUIPacketHandler());
}
@SubscribeEvent
public void onPacketData(ServerCustomPacketEvent event) {
C17PacketCustomPayload rawPacket = (C17PacketCustomPayload) event.packet.toC17Packet();
if (event.packet.channel().equals(ForgeWorldEdit.CUI_PLUGIN_CHANNEL)) {
EntityPlayerMP player = getPlayerFromEvent(event);
LocalSession session = ForgeWorldEdit.inst.getSession((EntityPlayerMP) player);
if (session.hasCUISupport()) {
return;
}
String text = new String(rawPacket.func_149558_e(), UTF_8_CHARSET);
session.handleCUIInitializationMessage(text);
}
}
private static EntityPlayerMP getPlayerFromEvent(ServerCustomPacketEvent event) {
return ((NetHandlerPlayServer) event.handler).playerEntity;
}
}

View File

@ -0,0 +1,32 @@
#Don't put comments; they get removed
default-max-polygon-points=-1
schematic-save-dir=schematics
allow-extra-data-values=false
super-pickaxe-many-drop-items=true
register-help=true
nav-wand-item=345
profile=false
super-pickaxe-drop-items=true
disallowed-blocks=6,26,27,28,31,32,34,36,37,38,39,40,46,50,51,55,59,66,69,75,76,93,94,77,81,83,7,14,15,16,56
max-super-pickaxe-size=5
max-brush-radius=10
craftscript-dir=craftscripts
no-double-slash=false
wand-item=271
shell-save-type=
scripting-timeout=3000
snapshots-dir=
use-inventory-creative-override=false
log-file=worldedit.log
max-changed-blocks=-1
nav-wand-distance=50
butcher-default-radius=-1
default-max-changed-blocks=-1
history-size=15
use-inventory=false
allow-symbolic-links=false
use-inventory-override=false
log-commands=false
butcher-max-radius=-1
max-polygon-points=20
max-radius=-1

View File

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