2014-04-06 08:41:28 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2020-03-23 21:13:11 +00:00
|
|
|
package com.sk89q.worldedit.forge.internal;
|
2014-04-06 08:41:28 +00:00
|
|
|
|
2018-07-30 13:26:06 +00:00
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
2015-01-16 03:39:15 +00:00
|
|
|
|
2018-10-14 10:40:53 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
|
|
|
|
2019-06-09 05:02:24 +00:00
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
2014-04-06 08:41:28 +00:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-03-19 16:53:52 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2014-04-06 08:41:28 +00:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility methods for setting tile entities in the world.
|
|
|
|
*/
|
2020-03-23 21:13:11 +00:00
|
|
|
public final class TileEntityUtils {
|
2014-04-06 08:41:28 +00:00
|
|
|
|
|
|
|
private TileEntityUtils() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a tile entity at the given location using the tile entity ID from
|
|
|
|
* the tag.
|
|
|
|
*
|
|
|
|
* @param world the world
|
|
|
|
* @param position the position
|
2020-03-23 04:02:04 +00:00
|
|
|
* @param tag the tag for the tile entity
|
2014-04-06 08:41:28 +00:00
|
|
|
*/
|
2020-03-23 04:02:04 +00:00
|
|
|
static boolean setTileEntity(World world, BlockPos position, CompoundNBT tag) {
|
|
|
|
TileEntity tileEntity = TileEntity.create(tag);
|
|
|
|
if (tileEntity == null) {
|
|
|
|
return false;
|
2014-04-06 08:41:28 +00:00
|
|
|
}
|
2020-03-23 04:02:04 +00:00
|
|
|
world.setTileEntity(new BlockPos(position.getX(), position.getY(), position.getZ()), tileEntity);
|
|
|
|
return true;
|
2014-04-06 08:41:28 +00:00
|
|
|
}
|
|
|
|
|
2019-06-09 05:02:24 +00:00
|
|
|
public static CompoundNBT copyNbtData(TileEntity tile) {
|
|
|
|
CompoundNBT tag = new CompoundNBT();
|
2018-12-15 12:13:13 +00:00
|
|
|
tile.write(tag);
|
2018-08-13 12:18:12 +00:00
|
|
|
return tag;
|
|
|
|
}
|
2014-04-06 08:41:28 +00:00
|
|
|
}
|