Search in sources :

Example 16 with TileEntity

use of net.minecraft.server.v1_16_R3.TileEntity in project Movecraft by APDevTeam.

the class IWorldHandler method moveTileEntity.

private void moveTileEntity(@NotNull World nativeWorld, @NotNull BlockPosition newPosition, @NotNull TileEntity tile) {
    Chunk chunk = nativeWorld.getChunkAtWorldCoords(newPosition);
    tile.invalidateBlockCache();
    tile.setLocation(nativeWorld, newPosition);
    if (nativeWorld.captureBlockStates) {
        tile.setLocation(nativeWorld, newPosition);
        nativeWorld.capturedTileEntities.put(newPosition, tile);
        return;
    }
    chunk.tileEntities.put(newPosition, tile);
}
Also used : Chunk(net.minecraft.server.v1_16_R3.Chunk)

Example 17 with TileEntity

use of net.minecraft.server.v1_16_R3.TileEntity in project Movecraft by APDevTeam.

the class IWorldHandler method rotateCraft.

@Override
public void rotateCraft(@NotNull Craft craft, @NotNull MovecraftLocation originPoint, @NotNull MovecraftRotation rotation) {
    // *******************************************
    // *      Step one: Convert to Positions     *
    // *******************************************
    HashMap<BlockPosition, BlockPosition> rotatedPositions = new HashMap<>();
    MovecraftRotation counterRotation = rotation == MovecraftRotation.CLOCKWISE ? MovecraftRotation.ANTICLOCKWISE : MovecraftRotation.CLOCKWISE;
    for (MovecraftLocation newLocation : craft.getHitBox()) {
        rotatedPositions.put(locationToPosition(MathUtils.rotateVec(counterRotation, newLocation.subtract(originPoint)).add(originPoint)), locationToPosition(newLocation));
    }
    // *******************************************
    // *         Step two: Get the tiles         *
    // *******************************************
    WorldServer nativeWorld = ((CraftWorld) craft.getWorld()).getHandle();
    List<TileHolder> tiles = new ArrayList<>();
    // get the tiles
    for (BlockPosition position : rotatedPositions.keySet()) {
        // TileEntity tile = nativeWorld.removeTileEntity(position);
        TileEntity tile = removeTileEntity(nativeWorld, position);
        if (tile == null)
            continue;
        tile.a(ROTATION[rotation.ordinal()]);
        // get the nextTick to move with the tile
        tiles.add(new TileHolder(tile, tickProvider.getNextTick(nativeWorld, position), position));
    }
    // *******************************************
    // *   Step three: Translate all the blocks  *
    // *******************************************
    // blockedByWater=false means an ocean-going vessel
    // TODO: Simplify
    // TODO: go by chunks
    // TODO: Don't move unnecessary blocks
    // get the blocks and rotate them
    HashMap<BlockPosition, IBlockData> blockData = new HashMap<>();
    for (BlockPosition position : rotatedPositions.keySet()) {
        blockData.put(position, nativeWorld.getType(position).a(ROTATION[rotation.ordinal()]));
    }
    // create the new block
    for (Map.Entry<BlockPosition, IBlockData> entry : blockData.entrySet()) {
        setBlockFast(nativeWorld, rotatedPositions.get(entry.getKey()), entry.getValue());
    }
    // TODO: go by chunks
    for (TileHolder tileHolder : tiles) {
        moveTileEntity(nativeWorld, rotatedPositions.get(tileHolder.getTilePosition()), tileHolder.getTile());
        if (tileHolder.getNextTick() == null)
            continue;
        final long currentTime = nativeWorld.worldData.getTime();
        nativeWorld.getBlockTickList().a(rotatedPositions.get(tileHolder.getNextTick().a), (Block) tileHolder.getNextTick().b(), (int) (tileHolder.getNextTick().b - currentTime), tileHolder.getNextTick().c);
    }
    // *******************************************
    // *   Step five: Destroy the leftovers      *
    // *******************************************
    // TODO: add support for pass-through
    Collection<BlockPosition> deletePositions = CollectionUtils.filter(rotatedPositions.keySet(), rotatedPositions.values());
    for (BlockPosition position : deletePositions) {
        setBlockFast(nativeWorld, position, Blocks.AIR.getBlockData());
    }
}
Also used : HashMap(java.util.HashMap) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) ArrayList(java.util.ArrayList) WorldServer(net.minecraft.server.v1_16_R3.WorldServer) MovecraftRotation(net.countercraft.movecraft.MovecraftRotation) TileEntity(net.minecraft.server.v1_16_R3.TileEntity) IBlockData(net.minecraft.server.v1_16_R3.IBlockData) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with TileEntity

use of net.minecraft.server.v1_16_R3.TileEntity in project Denizen-For-Bukkit by DenizenScript.

the class BlockHelper_v1_8_R3 method getNbtData.

@Override
public CompoundTag getNbtData(Block block) {
    TileEntity tileEntity = ((CraftBlockState) block.getState()).getTileEntity();
    if (tileEntity == null) {
        return null;
    }
    NBTTagCompound nbtTagCompound = new NBTTagCompound();
    tileEntity.b(new NBTTagCompound());
    return CompoundTag_v1_8_R3.fromNMSTag(nbtTagCompound);
}
Also used : TileEntity(net.minecraft.server.v1_8_R3.TileEntity) CraftBlockState(org.bukkit.craftbukkit.v1_8_R3.block.CraftBlockState) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound)

Example 19 with TileEntity

use of net.minecraft.server.v1_16_R3.TileEntity in project Denizen-For-Bukkit by DenizenScript.

the class BlockData_v1_10_R1 method setBlock.

public void setBlock(Block block) {
    block.setTypeIdAndData(material.getId(), (byte) data, false);
    if (ctag != null) {
        CompoundTagBuilder builder = ctag.createBuilder();
        builder.putInt("x", block.getX());
        builder.putInt("y", block.getY());
        builder.putInt("z", block.getZ());
        ctag = (CompoundTag_v1_10_R1) builder.build();
        // TODO: make this work!
        BlockPosition blockPos = new BlockPosition(block.getX(), block.getY(), block.getZ());
        TileEntity te = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(blockPos);
        te.a(ctag.toNMSTag());
    }
}
Also used : TileEntity(net.minecraft.server.v1_10_R1.TileEntity) BlockPosition(net.minecraft.server.v1_10_R1.BlockPosition) CompoundTagBuilder(net.aufdemrand.denizen.nms.util.jnbt.CompoundTagBuilder)

Example 20 with TileEntity

use of net.minecraft.server.v1_16_R3.TileEntity in project Denizen-For-Bukkit by DenizenScript.

the class BlockHelper_v1_11_R1 method setNbtData.

@Override
public void setNbtData(Block block, CompoundTag compoundTag) {
    TileEntity tileEntity = ((CraftBlockState) block.getState()).getTileEntity();
    if (tileEntity == null) {
        return;
    }
    tileEntity.a(((CompoundTag_v1_11_R1) compoundTag).toNMSTag());
    tileEntity.update();
}
Also used : TileEntity(net.minecraft.server.v1_11_R1.TileEntity) CraftBlockState(org.bukkit.craftbukkit.v1_11_R1.block.CraftBlockState)

Aggregations

Location (org.bukkit.Location)14 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 Map (java.util.Map)10 WildLoadersPlugin (com.bgsoftware.wildloaders.WildLoadersPlugin)8 Hologram (com.bgsoftware.wildloaders.api.holograms.Hologram)8 ChunkLoader (com.bgsoftware.wildloaders.api.loaders.ChunkLoader)8 ChunkLoaderNPC (com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC)8 ITileEntityChunkLoader (com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader)8 WChunkLoader (com.bgsoftware.wildloaders.loaders.WChunkLoader)8 Collection (java.util.Collection)8 Collections (java.util.Collections)8 UUID (java.util.UUID)8 BlockPosition (net.minecraft.server.v1_16_R3.BlockPosition)7 TileEntity (net.minecraft.server.v1_16_R3.TileEntity)7 TileEntity (net.minecraft.server.v1_8_R3.TileEntity)7 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)7 List (java.util.List)6 World (net.minecraft.server.v1_16_R3.World)5 WorldServer (net.minecraft.server.v1_16_R3.WorldServer)5