Correct line endings from previous commits

Dieser Commit ist enthalten in:
Kenzie Togami 2016-01-12 02:15:33 -08:00
Ursprung 5f08034ec1
Commit 337ecb2864
5 geänderte Dateien mit 836 neuen und 836 gelöschten Zeilen

Datei anzeigen

@ -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();
} }
} }

Datei anzeigen

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

Datei anzeigen

@ -1,460 +1,460 @@
/* /*
* 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.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.Direction; import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.TreeGenerator.TreeType; import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.world.AbstractWorld; import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.registry.WorldData; import com.sk89q.worldedit.world.registry.WorldData;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves; import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockOldLeaf; import net.minecraft.block.BlockOldLeaf;
import net.minecraft.block.BlockOldLog; import net.minecraft.block.BlockOldLog;
import net.minecraft.block.BlockPlanks; import net.minecraft.block.BlockPlanks;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityList;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos; import net.minecraft.util.BlockPos;
import net.minecraft.util.ClassInheritanceMultiMap; import net.minecraft.util.ClassInheritanceMultiMap;
import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldServer; import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.ChunkProviderServer; import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraft.world.gen.feature.WorldGenBigMushroom; import net.minecraft.world.gen.feature.WorldGenBigMushroom;
import net.minecraft.world.gen.feature.WorldGenBigTree; import net.minecraft.world.gen.feature.WorldGenBigTree;
import net.minecraft.world.gen.feature.WorldGenCanopyTree; import net.minecraft.world.gen.feature.WorldGenCanopyTree;
import net.minecraft.world.gen.feature.WorldGenForest; import net.minecraft.world.gen.feature.WorldGenForest;
import net.minecraft.world.gen.feature.WorldGenMegaJungle; import net.minecraft.world.gen.feature.WorldGenMegaJungle;
import net.minecraft.world.gen.feature.WorldGenMegaPineTree; import net.minecraft.world.gen.feature.WorldGenMegaPineTree;
import net.minecraft.world.gen.feature.WorldGenSavannaTree; import net.minecraft.world.gen.feature.WorldGenSavannaTree;
import net.minecraft.world.gen.feature.WorldGenShrub; import net.minecraft.world.gen.feature.WorldGenShrub;
import net.minecraft.world.gen.feature.WorldGenSwamp; import net.minecraft.world.gen.feature.WorldGenSwamp;
import net.minecraft.world.gen.feature.WorldGenTaiga1; import net.minecraft.world.gen.feature.WorldGenTaiga1;
import net.minecraft.world.gen.feature.WorldGenTaiga2; import net.minecraft.world.gen.feature.WorldGenTaiga2;
import net.minecraft.world.gen.feature.WorldGenTrees; import net.minecraft.world.gen.feature.WorldGenTrees;
import net.minecraft.world.gen.feature.WorldGenerator; 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 Random random = new Random(); private static final Random random = new Random();
private static final int UPDATE = 1, NOTIFY = 2, NOTIFY_CLIENT = 4; private static final int UPDATE = 1, NOTIFY = 2, NOTIFY_CLIENT = 4;
private static final Logger logger = Logger.getLogger(ForgeWorld.class.getCanonicalName()); 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); private static final IBlockState JUNGLE_LOG = Blocks.log.getDefaultState().withProperty(BlockOldLog.VARIANT, BlockPlanks.EnumType.JUNGLE);
private static final IBlockState JUNGLE_LEAF = Blocks.leaves.getDefaultState().withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.JUNGLE).withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(false)); private static final IBlockState JUNGLE_LEAF = Blocks.leaves.getDefaultState().withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.JUNGLE).withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(false));
private static final IBlockState JUNGLE_SHRUB = Blocks.leaves.getDefaultState().withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.OAK).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));
private final WeakReference<World> worldRef; private final WeakReference<World> worldRef;
/** /**
* Construct a new world. * Construct a new world.
* *
* @param world the world * @param world the world
*/ */
ForgeWorld(World world) { ForgeWorld(World world) {
checkNotNull(world); checkNotNull(world);
this.worldRef = new WeakReference<World>(world); this.worldRef = new WeakReference<World>(world);
} }
/** /**
* Get the underlying handle to the world. * Get the underlying handle to the world.
* *
* @return the world * @return the world
* @throws WorldEditException thrown if a reference to the world was lost (i.e. world was unloaded) * @throws WorldEditException thrown if a reference to the world was lost (i.e. world was unloaded)
*/ */
public World getWorldChecked() throws WorldEditException { public World getWorldChecked() throws WorldEditException {
World world = worldRef.get(); World world = worldRef.get();
if (world != null) { if (world != null) {
return world; return world;
} else { } else {
throw new WorldReferenceLostException("The reference to the world was lost (i.e. the world may have been unloaded)"); 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. * Get the underlying handle to the world.
* *
* @return the world * @return the world
* @throws RuntimeException thrown if a reference to the world was lost (i.e. world was unloaded) * @throws RuntimeException thrown if a reference to the world was lost (i.e. world was unloaded)
*/ */
public World getWorld() { public World getWorld() {
World world = worldRef.get(); World world = worldRef.get();
if (world != null) { if (world != null) {
return world; return world;
} else { } else {
throw new RuntimeException("The reference to the world was lost (i.e. the world may have been unloaded)"); throw new RuntimeException("The reference to the world was lost (i.e. the world may have been unloaded)");
} }
} }
@Override @Override
public String getName() { public String getName() {
return getWorld().getWorldInfo().getWorldName(); return getWorld().getWorldInfo().getWorldName();
} }
@Override @Override
public boolean useItem(Vector position, BaseItem item, Direction face) { public boolean useItem(Vector position, BaseItem item, Direction face) {
Item nativeItem = Item.getItemById(item.getType()); Item nativeItem = Item.getItemById(item.getType());
ItemStack stack = new ItemStack(nativeItem, 1, item.getData()); ItemStack stack = new ItemStack(nativeItem, 1, item.getData());
World world = getWorld(); World world = getWorld();
return stack.tryPlaceItemIntoWorld(new WorldEditFakePlayer((WorldServer) world), world, position.getBlockX(), position.getBlockY(), position.getBlockZ(), ForgeAdapter.adapt(face), 0, 0, 0); return stack.tryPlaceItemIntoWorld(new WorldEditFakePlayer((WorldServer) world), world, position.getBlockX(), position.getBlockY(), position.getBlockZ(), ForgeAdapter.adapt(face), 0, 0, 0);
} }
@Override @Override
public boolean setBlock(Vector position, BaseBlock block, boolean notifyAndLight) throws WorldEditException { public boolean setBlock(Vector position, BaseBlock block, boolean notifyAndLight) throws WorldEditException {
checkNotNull(position); checkNotNull(position);
checkNotNull(block); checkNotNull(block);
World world = getWorldChecked(); World world = getWorldChecked();
int x = position.getBlockX(); int x = position.getBlockX();
int y = position.getBlockY(); int y = position.getBlockY();
int z = position.getBlockZ(); int z = position.getBlockZ();
// First set the block // First set the block
Chunk chunk = world.getChunkFromChunkCoords(x >> 4, z >> 4); Chunk chunk = world.getChunkFromChunkCoords(x >> 4, z >> 4);
BlockPos pos = new BlockPos(x, y, z); BlockPos pos = new BlockPos(x, y, z);
IBlockState old = chunk.getBlockState(pos); IBlockState old = chunk.getBlockState(pos);
IBlockState newState = Block.getBlockById(block.getId()).getStateFromMeta(block.getData()); IBlockState newState = Block.getBlockById(block.getId()).getStateFromMeta(block.getData());
IBlockState successState = chunk.setBlockState(pos, newState); IBlockState successState = chunk.setBlockState(pos, newState);
boolean successful = successState != null; boolean successful = successState != null;
// Create the TileEntity // Create the TileEntity
if (successful) { if (successful) {
if (block.hasNbtData()) { if (block.hasNbtData()) {
// Kill the old TileEntity // Kill the old TileEntity
world.removeTileEntity(pos); world.removeTileEntity(pos);
NBTTagCompound nativeTag = NBTConverter.toNative(block.getNbtData()); NBTTagCompound nativeTag = NBTConverter.toNative(block.getNbtData());
nativeTag.setString("id", block.getNbtId()); nativeTag.setString("id", block.getNbtId());
TileEntityUtils.setTileEntity(world, position, nativeTag); TileEntityUtils.setTileEntity(world, position, nativeTag);
} }
} }
if (notifyAndLight) { if (notifyAndLight) {
if (!successful) { if (!successful) {
newState = old; newState = old;
} }
world.checkLight(pos); world.checkLight(pos);
world.markAndNotifyBlock(pos, chunk, old, newState, UPDATE | NOTIFY); world.markAndNotifyBlock(pos, chunk, old, newState, UPDATE | NOTIFY);
} }
return successful; return successful;
} }
@Override @Override
public int getBlockLightLevel(Vector position) { public int getBlockLightLevel(Vector position) {
checkNotNull(position); checkNotNull(position);
return getWorld().getLight(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ())); return getWorld().getLight(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()));
} }
@Override @Override
public boolean clearContainerBlockContents(Vector position) { public boolean clearContainerBlockContents(Vector position) {
checkNotNull(position); checkNotNull(position);
TileEntity tile = getWorld().getTileEntity(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ())); TileEntity tile = getWorld().getTileEntity(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()));
if ((tile instanceof IInventory)) { if ((tile instanceof IInventory)) {
IInventory inv = (IInventory) tile; IInventory inv = (IInventory) tile;
int size = inv.getSizeInventory(); int size = inv.getSizeInventory();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
inv.setInventorySlotContents(i, null); inv.setInventorySlotContents(i, null);
} }
return true; return true;
} }
return false; return false;
} }
@Override @Override
public BaseBiome getBiome(Vector2D position) { public BaseBiome getBiome(Vector2D position) {
checkNotNull(position); checkNotNull(position);
return new BaseBiome(getWorld().getBiomeGenForCoords(new BlockPos(position.getBlockX(), 0, position.getBlockZ())).biomeID); return new BaseBiome(getWorld().getBiomeGenForCoords(new BlockPos(position.getBlockX(), 0, position.getBlockZ())).biomeID);
} }
@Override @Override
public boolean setBiome(Vector2D position, BaseBiome biome) { public boolean setBiome(Vector2D position, BaseBiome biome) {
checkNotNull(position); checkNotNull(position);
checkNotNull(biome); checkNotNull(biome);
Chunk chunk = getWorld().getChunkFromBlockCoords(new BlockPos(position.getBlockX(), 0, position.getBlockZ())); Chunk chunk = getWorld().getChunkFromBlockCoords(new BlockPos(position.getBlockX(), 0, position.getBlockZ()));
if ((chunk != null) && (chunk.isLoaded())) { if ((chunk != null) && (chunk.isLoaded())) {
chunk.getBiomeArray()[((position.getBlockZ() & 0xF) << 4 | position.getBlockX() & 0xF)] = (byte) biome.getId(); chunk.getBiomeArray()[((position.getBlockZ() & 0xF) << 4 | position.getBlockX() & 0xF)] = (byte) biome.getId();
return true; return true;
} }
return false; return false;
} }
@Override @Override
public void dropItem(Vector position, BaseItemStack item) { public void dropItem(Vector position, BaseItemStack item) {
checkNotNull(position); checkNotNull(position);
checkNotNull(item); checkNotNull(item);
if (item.getType() == 0) { if (item.getType() == 0) {
return; return;
} }
EntityItem entity = new EntityItem(getWorld(), position.getX(), position.getY(), position.getZ(), ForgeWorldEdit.toForgeItemStack(item)); EntityItem entity = new EntityItem(getWorld(), position.getX(), position.getY(), position.getZ(), ForgeWorldEdit.toForgeItemStack(item));
entity.setPickupDelay(10); entity.setPickupDelay(10);
getWorld().spawnEntityInWorld(entity); getWorld().spawnEntityInWorld(entity);
} }
@Override @Override
public boolean regenerate(Region region, EditSession editSession) { public boolean regenerate(Region region, EditSession editSession) {
BaseBlock[] history = new BaseBlock[256 * (getMaxY() + 1)]; BaseBlock[] history = new BaseBlock[256 * (getMaxY() + 1)];
for (Vector2D chunk : region.getChunks()) { for (Vector2D chunk : region.getChunks()) {
Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16); Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
for (int y = 0; y < getMaxY() + 1; y++) { for (int y = 0; y < getMaxY() + 1; y++) {
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {
Vector pt = min.add(x, y, z); Vector pt = min.add(x, y, z);
int index = y * 16 * 16 + z * 16 + x; int index = y * 16 * 16 + z * 16 + x;
history[index] = editSession.getBlock(pt); history[index] = editSession.getBlock(pt);
} }
} }
} }
try { try {
Set<Vector2D> chunks = region.getChunks(); Set<Vector2D> chunks = region.getChunks();
IChunkProvider provider = getWorld().getChunkProvider(); IChunkProvider provider = getWorld().getChunkProvider();
if (!(provider instanceof ChunkProviderServer)) { if (!(provider instanceof ChunkProviderServer)) {
return false; return false;
} }
ChunkProviderServer chunkServer = (ChunkProviderServer) provider; ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
IChunkProvider chunkProvider = chunkServer.serverChunkGenerator; IChunkProvider chunkProvider = chunkServer.serverChunkGenerator;
for (Vector2D coord : chunks) { for (Vector2D coord : chunks) {
long pos = ChunkCoordIntPair.chunkXZ2Int(coord.getBlockX(), coord.getBlockZ()); long pos = ChunkCoordIntPair.chunkXZ2Int(coord.getBlockX(), coord.getBlockZ());
Chunk mcChunk; Chunk mcChunk;
if (chunkServer.chunkExists(coord.getBlockX(), coord.getBlockZ())) { if (chunkServer.chunkExists(coord.getBlockX(), coord.getBlockZ())) {
mcChunk = chunkServer.loadChunk(coord.getBlockX(), coord.getBlockZ()); mcChunk = chunkServer.loadChunk(coord.getBlockX(), coord.getBlockZ());
mcChunk.onChunkUnload(); mcChunk.onChunkUnload();
} }
chunkServer.droppedChunksSet.remove(pos); chunkServer.droppedChunksSet.remove(pos);
chunkServer.id2ChunkMap.remove(pos); chunkServer.id2ChunkMap.remove(pos);
mcChunk = chunkProvider.provideChunk(coord.getBlockX(), coord.getBlockZ()); mcChunk = chunkProvider.provideChunk(coord.getBlockX(), coord.getBlockZ());
chunkServer.id2ChunkMap.add(pos, mcChunk); chunkServer.id2ChunkMap.add(pos, mcChunk);
chunkServer.loadedChunks.add(mcChunk); chunkServer.loadedChunks.add(mcChunk);
if (mcChunk != null) { if (mcChunk != null) {
mcChunk.onChunkLoad(); mcChunk.onChunkLoad();
mcChunk.populateChunk(chunkProvider, chunkProvider, coord.getBlockX(), coord.getBlockZ()); mcChunk.populateChunk(chunkProvider, chunkProvider, coord.getBlockX(), coord.getBlockZ());
} }
} }
} catch (Throwable t) { } catch (Throwable t) {
logger.log(Level.WARNING, "Failed to generate chunk", t); logger.log(Level.WARNING, "Failed to generate chunk", t);
return false; return false;
} }
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
for (int y = 0; y < getMaxY() + 1; y++) { for (int y = 0; y < getMaxY() + 1; y++) {
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {
Vector pt = min.add(x, y, z); Vector pt = min.add(x, y, z);
int index = y * 16 * 16 + z * 16 + x; int index = y * 16 * 16 + z * 16 + x;
if (!region.contains(pt)) if (!region.contains(pt))
editSession.smartSetBlock(pt, history[index]); editSession.smartSetBlock(pt, history[index]);
else { else {
editSession.rememberChange(pt, history[index], editSession.rawGetBlock(pt)); editSession.rememberChange(pt, history[index], editSession.rawGetBlock(pt));
} }
} }
} }
} }
} }
return false; return false;
} }
@Nullable @Nullable
private static WorldGenerator createWorldGenerator(TreeType type) { private static WorldGenerator createWorldGenerator(TreeType type) {
switch (type) { switch (type) {
case TREE: return new WorldGenTrees(true); case TREE: return new WorldGenTrees(true);
case BIG_TREE: return new WorldGenBigTree(true); case BIG_TREE: return new WorldGenBigTree(true);
case REDWOOD: return new WorldGenTaiga2(true); case REDWOOD: return new WorldGenTaiga2(true);
case TALL_REDWOOD: return new WorldGenTaiga1(); case TALL_REDWOOD: return new WorldGenTaiga1();
case BIRCH: return new WorldGenForest(true, false); case BIRCH: return new WorldGenForest(true, false);
case JUNGLE: return new WorldGenMegaJungle(true, 10, 20, JUNGLE_LOG, JUNGLE_LEAF); case JUNGLE: return new WorldGenMegaJungle(true, 10, 20, JUNGLE_LOG, JUNGLE_LEAF);
case SMALL_JUNGLE: return new WorldGenTrees(true, 4 + random.nextInt(7), JUNGLE_LOG, JUNGLE_LEAF, false); case SMALL_JUNGLE: return new WorldGenTrees(true, 4 + random.nextInt(7), JUNGLE_LOG, JUNGLE_LEAF, false);
case SHORT_JUNGLE: return new WorldGenTrees(true, 4 + random.nextInt(7), JUNGLE_LOG, JUNGLE_LEAF, true); 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 JUNGLE_BUSH: return new WorldGenShrub(JUNGLE_LOG, JUNGLE_SHRUB);
case RED_MUSHROOM: return new WorldGenBigMushroom(Blocks.brown_mushroom_block); case RED_MUSHROOM: return new WorldGenBigMushroom(Blocks.brown_mushroom_block);
case BROWN_MUSHROOM: return new WorldGenBigMushroom(Blocks.red_mushroom_block); case BROWN_MUSHROOM: return new WorldGenBigMushroom(Blocks.red_mushroom_block);
case SWAMP: return new WorldGenSwamp(); case SWAMP: return new WorldGenSwamp();
case ACACIA: return new WorldGenSavannaTree(true); case ACACIA: return new WorldGenSavannaTree(true);
case DARK_OAK: return new WorldGenCanopyTree(true); case DARK_OAK: return new WorldGenCanopyTree(true);
case MEGA_REDWOOD: return new WorldGenMegaPineTree(false, random.nextBoolean()); case MEGA_REDWOOD: return new WorldGenMegaPineTree(false, random.nextBoolean());
case TALL_BIRCH: return new WorldGenForest(true, true); case TALL_BIRCH: return new WorldGenForest(true, true);
case RANDOM: case RANDOM:
case PINE: case PINE:
case RANDOM_REDWOOD: case RANDOM_REDWOOD:
default: default:
return null; return null;
} }
} }
@Override @Override
public boolean generateTree(TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException { public boolean generateTree(TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException {
WorldGenerator generator = createWorldGenerator(type); WorldGenerator generator = createWorldGenerator(type);
return generator != null ? generator.generate(getWorld(), random, position.getBlockX(), position.getBlockY(), position.getBlockZ()) : false; return generator != null ? generator.generate(getWorld(), random, position.getBlockX(), position.getBlockY(), position.getBlockZ()) : false;
} }
@Override @Override
public WorldData getWorldData() { public WorldData getWorldData() {
return ForgeWorldData.getInstance(); return ForgeWorldData.getInstance();
} }
@Override @Override
public boolean isValidBlockType(int id) { public boolean isValidBlockType(int id) {
return (id == 0) || (net.minecraft.block.Block.getBlockById(id) != null); return (id == 0) || (net.minecraft.block.Block.getBlockById(id) != null);
} }
@Override @Override
public BaseBlock getBlock(Vector position) { public BaseBlock getBlock(Vector position) {
World world = getWorld(); World world = getWorld();
BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()); BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ());
IBlockState state = world.getBlockState(pos); IBlockState state = world.getBlockState(pos);
TileEntity tile = getWorld().getTileEntity(pos); TileEntity tile = getWorld().getTileEntity(pos);
if (tile != null) { if (tile != null) {
return new TileEntityBaseBlock(Block.getIdFromBlock(state.getBlock()), state.getBlock().getMetaFromState(state), tile); return new TileEntityBaseBlock(Block.getIdFromBlock(state.getBlock()), state.getBlock().getMetaFromState(state), tile);
} else { } else {
return new BaseBlock(Block.getIdFromBlock(state.getBlock()), state.getBlock().getMetaFromState(state)); return new BaseBlock(Block.getIdFromBlock(state.getBlock()), state.getBlock().getMetaFromState(state));
} }
} }
@Override @Override
public BaseBlock getLazyBlock(Vector position) { public BaseBlock getLazyBlock(Vector position) {
World world = getWorld(); World world = getWorld();
BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()); BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ());
IBlockState state = world.getBlockState(pos); IBlockState state = world.getBlockState(pos);
return new LazyBlock(Block.getIdFromBlock(state.getBlock()), state.getBlock().getMetaFromState(state), this, position); return new LazyBlock(Block.getIdFromBlock(state.getBlock()), state.getBlock().getMetaFromState(state), this, position);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return getWorld().hashCode(); return getWorld().hashCode();
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (o == null) { if (o == null) {
return false; return false;
} else if ((o instanceof ForgeWorld)) { } else if ((o instanceof ForgeWorld)) {
ForgeWorld other = ((ForgeWorld) o); ForgeWorld other = ((ForgeWorld) o);
World otherWorld = other.worldRef.get(); World otherWorld = other.worldRef.get();
World thisWorld = worldRef.get(); World thisWorld = worldRef.get();
return otherWorld != null && thisWorld != null && otherWorld.equals(thisWorld); return otherWorld != null && thisWorld != null && otherWorld.equals(thisWorld);
} else if (o instanceof com.sk89q.worldedit.world.World) { } else if (o instanceof com.sk89q.worldedit.world.World) {
return ((com.sk89q.worldedit.world.World) o).getName().equals(getName()); return ((com.sk89q.worldedit.world.World) o).getName().equals(getName());
} else { } else {
return false; return false;
} }
} }
@Override @Override
public List<? extends Entity> getEntities(Region region) { public List<? extends Entity> getEntities(Region region) {
List<Entity> entities = new ArrayList<Entity>(); List<Entity> entities = new ArrayList<Entity>();
World world = getWorld(); World world = getWorld();
List<net.minecraft.entity.Entity> ents = world.loadedEntityList; List<net.minecraft.entity.Entity> ents = world.loadedEntityList;
for (net.minecraft.entity.Entity entity : ents) { for (net.minecraft.entity.Entity entity : ents) {
if (region.contains(new Vector(entity.posX, entity.posY, entity.posZ))) { if (region.contains(new Vector(entity.posX, entity.posY, entity.posZ))) {
entities.add(new ForgeEntity(entity)); entities.add(new ForgeEntity(entity));
} }
} }
return entities; return entities;
} }
@Override @Override
public List<? extends Entity> getEntities() { public List<? extends Entity> getEntities() {
List<Entity> entities = new ArrayList<Entity>(); List<Entity> entities = new ArrayList<Entity>();
for (net.minecraft.entity.Entity entity : getWorld().loadedEntityList) { for (net.minecraft.entity.Entity entity : getWorld().loadedEntityList) {
entities.add(new ForgeEntity(entity)); entities.add(new ForgeEntity(entity));
} }
return entities; return entities;
} }
@Nullable @Nullable
@Override @Override
public Entity createEntity(Location location, BaseEntity entity) { public Entity createEntity(Location location, BaseEntity entity) {
World world = getWorld(); World world = getWorld();
net.minecraft.entity.Entity createdEntity = EntityList.createEntityByName(entity.getTypeId(), world); net.minecraft.entity.Entity createdEntity = EntityList.createEntityByName(entity.getTypeId(), world);
if (createdEntity != null) { if (createdEntity != null) {
CompoundTag nativeTag = entity.getNbtData(); CompoundTag nativeTag = entity.getNbtData();
if (nativeTag != null) { if (nativeTag != null) {
NBTTagCompound tag = NBTConverter.toNative(entity.getNbtData()); NBTTagCompound tag = NBTConverter.toNative(entity.getNbtData());
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.removeTag(name); tag.removeTag(name);
} }
createdEntity.readFromNBT(tag); createdEntity.readFromNBT(tag);
} }
createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
world.spawnEntityInWorld(createdEntity); world.spawnEntityInWorld(createdEntity);
return new ForgeEntity(createdEntity); return new ForgeEntity(createdEntity);
} else { } else {
return null; return null;
} }
} }
/** /**
* Thrown when the reference to the world is lost. * Thrown when the reference to the world is lost.
*/ */
private static class WorldReferenceLostException extends WorldEditException { private static class WorldReferenceLostException extends WorldEditException {
private WorldReferenceLostException(String message) { private WorldReferenceLostException(String message) {
super(message); super(message);
} }
} }
} }

Datei anzeigen

@ -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;
} }
} }

Datei anzeigen

@ -1,72 +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 com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.NetHandlerPlayServer; import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.network.ThreadQuickExitException; import net.minecraft.network.ThreadQuickExitException;
import net.minecraft.network.play.server.S3FPacketCustomPayload; import net.minecraft.network.play.server.S3FPacketCustomPayload;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.FMLEventChannel; import net.minecraftforge.fml.common.network.FMLEventChannel;
import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientCustomPacketEvent; import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientCustomPacketEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent; import net.minecraftforge.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.NetworkRegistry;
public class WECUIPacketHandler { public class WECUIPacketHandler {
public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8"); public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
public static FMLEventChannel WECUI_CHANNEL; public static FMLEventChannel WECUI_CHANNEL;
public static void init() { public static void init() {
WECUI_CHANNEL = NetworkRegistry.INSTANCE.newEventDrivenChannel(ForgeWorldEdit.CUI_PLUGIN_CHANNEL); WECUI_CHANNEL = NetworkRegistry.INSTANCE.newEventDrivenChannel(ForgeWorldEdit.CUI_PLUGIN_CHANNEL);
WECUI_CHANNEL.register(new WECUIPacketHandler()); WECUI_CHANNEL.register(new WECUIPacketHandler());
} }
@SubscribeEvent @SubscribeEvent
public void onPacketData(ServerCustomPacketEvent event) { 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 = event.packet.payload().toString(UTF_8_CHARSET); String text = event.packet.payload().toString(UTF_8_CHARSET);
session.handleCUIInitializationMessage(text); session.handleCUIInitializationMessage(text);
session.describeCUI(ForgeWorldEdit.inst.wrap(player)); session.describeCUI(ForgeWorldEdit.inst.wrap(player));
} }
} }
@SubscribeEvent @SubscribeEvent
public void callProcessPacket(ClientCustomPacketEvent event) { public void callProcessPacket(ClientCustomPacketEvent event) {
try { try {
new S3FPacketCustomPayload(event.packet.channel(), new PacketBuffer(event.packet.payload())).processPacket(event.handler); new S3FPacketCustomPayload(event.packet.channel(), new PacketBuffer(event.packet.payload())).processPacket(event.handler);
} catch (ThreadQuickExitException suppress) { } catch (ThreadQuickExitException suppress) {
} }
} }
private static EntityPlayerMP getPlayerFromEvent(ServerCustomPacketEvent event) { private static EntityPlayerMP getPlayerFromEvent(ServerCustomPacketEvent event) {
return ((NetHandlerPlayServer) event.handler).playerEntity; return ((NetHandlerPlayServer) event.handler).playerEntity;
} }
} }