Search in sources :

Example 1 with TeleposeEvent

use of WayofTime.alchemicalWizardry.api.event.TeleposeEvent in project BloodMagic by WayofTime.

the class BlockTeleposer method swapBlocks.

public static boolean swapBlocks(Object caller, World worldI, World worldF, int xi, int yi, int zi, int xf, int yf, int zf, boolean doSound, int flag) {
    TileEntity tileEntityI = worldI.getTileEntity(xi, yi, zi);
    TileEntity tileEntityF = worldF.getTileEntity(xf, yf, zf);
    NBTTagCompound nbttag1 = new NBTTagCompound();
    NBTTagCompound nbttag2 = new NBTTagCompound();
    if (tileEntityI != null) {
        tileEntityI.writeToNBT(nbttag1);
    }
    if (tileEntityF != null) {
        tileEntityF.writeToNBT(nbttag2);
    }
    Block blockI = worldI.getBlock(xi, yi, zi);
    Block blockF = worldF.getBlock(xf, yf, zf);
    if (blockI.equals(Blocks.air) && blockF.equals(Blocks.air)) {
        return false;
    }
    if (blockI instanceof BlockMobSpawner || blockF instanceof BlockMobSpawner || caller instanceof TEDemonPortal ? false : blockI instanceof BlockPortal || blockF instanceof BlockPortal) {
        return false;
    }
    int metaI = worldI.getBlockMetadata(xi, yi, zi);
    int metaF = worldF.getBlockMetadata(xf, yf, zf);
    TeleposeEvent evt = new TeleposeEvent(worldI, xi, yi, zi, blockI, metaI, worldF, xf, yf, zf, blockF, metaF);
    if (MinecraftForge.EVENT_BUS.post(evt))
        return false;
    if (doSound) {
        worldI.playSoundEffect(xi, yi, zi, "mob.endermen.portal", 1.0F, 1.0F);
        worldF.playSoundEffect(xf, yf, zf, "mob.endermen.portal", 1.0F, 1.0F);
    }
    // CLEAR TILES
    Block finalBlock = blockF;
    if (finalBlock != null) {
        TileEntity tileToSet = finalBlock.createTileEntity(worldF, metaF);
        worldF.setTileEntity(xf, yf, zf, tileToSet);
    }
    if (blockI != null) {
        TileEntity tileToSet = blockI.createTileEntity(worldI, metaI);
        worldI.setTileEntity(xi, yi, zi, tileToSet);
    }
    // TILES CLEARED
    worldF.setBlock(xf, yf, zf, blockI, metaI, flag);
    if (tileEntityI != null) {
        TileEntity newTileEntityI = TileEntity.createAndLoadEntity(nbttag1);
        if (AlchemicalWizardry.isFMPLoaded && isMultipart(tileEntityI)) {
            newTileEntityI = createMultipartFromNBT(worldF, nbttag1);
        }
        worldF.setTileEntity(xf, yf, zf, newTileEntityI);
        newTileEntityI.xCoord = xf;
        newTileEntityI.yCoord = yf;
        newTileEntityI.zCoord = zf;
        if (AlchemicalWizardry.isFMPLoaded && isMultipart(tileEntityI)) {
            sendDescriptorOfTile(worldF, newTileEntityI);
        }
    }
    worldI.setBlock(xi, yi, zi, finalBlock, metaF, flag);
    if (tileEntityF != null) {
        TileEntity newTileEntityF = TileEntity.createAndLoadEntity(nbttag2);
        if (AlchemicalWizardry.isFMPLoaded && isMultipart(tileEntityF)) {
            newTileEntityF = createMultipartFromNBT(worldI, nbttag2);
        }
        worldI.setTileEntity(xi, yi, zi, newTileEntityF);
        newTileEntityF.xCoord = xi;
        newTileEntityF.yCoord = yi;
        newTileEntityF.zCoord = zi;
        if (AlchemicalWizardry.isFMPLoaded && isMultipart(tileEntityF)) {
            sendDescriptorOfTile(worldI, newTileEntityF);
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockMobSpawner(net.minecraft.block.BlockMobSpawner) TEDemonPortal(WayofTime.alchemicalWizardry.common.demonVillage.tileEntity.TEDemonPortal) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Block(net.minecraft.block.Block) TeleposeEvent(WayofTime.alchemicalWizardry.api.event.TeleposeEvent) BlockPortal(net.minecraft.block.BlockPortal)

Aggregations

TeleposeEvent (WayofTime.alchemicalWizardry.api.event.TeleposeEvent)1 TEDemonPortal (WayofTime.alchemicalWizardry.common.demonVillage.tileEntity.TEDemonPortal)1 Block (net.minecraft.block.Block)1 BlockMobSpawner (net.minecraft.block.BlockMobSpawner)1 BlockPortal (net.minecraft.block.BlockPortal)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1